Matt23

Untitled

Jul 17th, 2015
278
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.65 KB | None | 0 0
  1. import java.io.BufferedReader;
  2. import java.io.IOException;
  3. import java.io.InputStreamReader;
  4. import java.net.URL;
  5. import java.net.URLConnection;
  6. import java.util.regex.Matcher;
  7. import java.util.regex.Pattern;
  8.  
  9. public class Main {
  10.  
  11.     public static void main(String[] args) throws IOException {
  12.         int num = 12345;
  13.         String res = "";
  14.         StringBuilder response = new StringBuilder();
  15.        
  16.         while (true){
  17.             try {
  18.                 String a = String.format("http://www.pythonchallenge.com/pc/def/linkedlist.php?nothing=%d", num);
  19.                 URL url = new URL(a);
  20.                 URLConnection conn = url.openConnection();
  21.                 BufferedReader br = new BufferedReader(
  22.                         new InputStreamReader(conn.getInputStream()));
  23.  
  24.                 while ((res = br.readLine()) != null){
  25.                     response.append(res);
  26.                 }
  27.                
  28.                 res = response.toString();
  29.                 response.setLength(0);
  30.  
  31.                 if (res.contains("Divide")){
  32.                     num /= 2;
  33.                 }
  34.                 else {
  35.                     Pattern p = Pattern.compile("\\d+$");
  36.                     Matcher m = p.matcher(res);
  37.                     if (m.find()) num = Integer.parseInt(m.group(0));
  38.                     else {
  39.                         System.out.println(res);
  40.                         break;
  41.                     }
  42.                 }
  43.                 System.out.println(num);
  44.             }
  45.             catch (NumberFormatException e){
  46.                 System.out.println(res);
  47.                 break;
  48.             }
  49.         }
  50.     }
  51. }
Advertisement
Add Comment
Please, Sign In to add comment