SHARE
TWEET

Untitled

a guest Jan 20th, 2019 70 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Random numberGen = new Random();
  2.  
  3.         int door = -400869;//(numberGen.nextInt(1000000)) - 500000; //Position door somewhere -500000 to 500000
  4.  
  5.         int you = 0; //Position
  6.         int counter = 0; //Direction reversals
  7.         int steps = 0;
  8.  
  9.         boolean doorFound = false;
  10.  
  11.         while (!doorFound) {
  12.             if (counter % 2 == 1) {
  13.                 System.out.println("You are walking " + java.lang.Math.pow(2, counter) + " steps right.");
  14.                 for (int i = 0; i < java.lang.Math.pow(2, counter); i++) {
  15.                     you++;
  16.                     steps++;
  17.                     if (you == door) {
  18.                         doorFound = true;
  19.                         break;
  20.                     }
  21.                 }
  22.                 counter++;
  23.             } else {
  24.                 System.out.println("You are walking " + java.lang.Math.pow(2, counter) + " steps left.");
  25.                 for (int i = 0; i < java.lang.Math.pow(2, counter); i++) {
  26.                     you--;
  27.                     steps++;
  28.                     if (you == door) {
  29.                         doorFound = true;
  30.                         break;
  31.                     }
  32.                 }
  33.                 counter++;
  34.             }
  35.         }
  36.         System.out.println("YOU FOUND IT. You are at " + you + " and the door is at " + door);
  37.         System.out.println("You changed direction " + counter + " times. - You took " + steps + " steps.");
  38.     }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top