Advertisement
Guest User

Untitled

a guest
Sep 10th, 2018
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.54 KB | None | 0 0
  1.  
  2. public class Dance {
  3.  
  4.   public static void main(String[] args) {
  5.     System.out.println(getPositionAfterSteps(3));
  6.   }
  7.  
  8.   public static int getPositionAfterSteps(int steps) {
  9.     int pos = 0;
  10.     int current = 0;
  11.     int recent = 0;
  12.     int penultimate = 0;
  13.     for(int step = 0; step < steps; step++){
  14.         if (step == 0) current = 1;
  15.         else if (step == 1) current = -2;
  16.         else current = recent - penultimate;
  17.         pos += current;
  18.      
  19.         penultimate = recent;
  20.         recent = current;
  21.     }
  22.     return pos;
  23.   }
  24.  
  25. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement