Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Dance {
- public static void main(String[] args) {
- System.out.println(getPositionAfterSteps(3));
- }
- public static int getPositionAfterSteps(int steps) {
- int pos = 0;
- int current = 0;
- int recent = 0;
- int penultimate = 0;
- for(int step = 0; step < steps; step++){
- if (step == 0) current = 1;
- else if (step == 1) current = -2;
- else current = recent - penultimate;
- pos += current;
- penultimate = recent;
- recent = current;
- }
- return pos;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement