SHARE
TWEET

Untitled

a guest Jan 20th, 2019 63 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Random numberGen = new Random();
  2.  
  3.         int door = 491920;//(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.             double stepsToTake = java.lang.Math.pow(2, counter);
  13.            
  14.             if (counter % 2 == 1) {
  15.                 System.out.println("You are walking " + stepsToTake + " steps right.");
  16.                 for (int i = 0; i < stepsToTake; i++) {
  17.                     you++;
  18.                     steps++;
  19.                     if (you == door) {
  20.                         doorFound = true;
  21.                         break;
  22.                     }
  23.                 }
  24.                 counter++;
  25.             } else {
  26.                 System.out.println("You are walking " + stepsToTake + " steps left.");
  27.                 for (int i = 0; i < stepsToTake; i++) {
  28.                     you--;
  29.                     steps++;
  30.                     if (you == door) {
  31.                         doorFound = true;
  32.                         break;
  33.                     }
  34.                 }
  35.                 counter++;
  36.             }
  37.         }
  38.         System.out.println("YOU FOUND IT. You are at " + you + " and the door is at " + door);
  39.         System.out.println("You changed direction " + counter + " times. - You took " + steps + " steps.");
  40.     }
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