fork download
  1. public class Main {
  2. public static void main(String[] args) {
  3. System.out.println(java.text.MessageFormat.format(
  4. "x = {1}, y = {0}, direction = {2, choice, 0#north|1#east|2#south|3#west}",
  5. new java.util.Scanner(System.in)
  6. .useDelimiter("\\R")
  7. .tokens()
  8. .mapToInt(s -> Integer.parseInt(s.substring(7).trim()) << s.charAt(0) / 'r' * ' ' / 2)
  9. .mapToObj(data -> new Integer[] {(int)(short) data, (data >> 16) / 90})
  10. .reduce(
  11. new Integer[]{0,0,0},
  12. (turtle, action) -> {
  13. turtle[2] += action[1];
  14. turtle[2] %= 4;
  15. turtle[turtle[2] % 2] += turtle[2] < 2 ? action[0] : -action[0];
  16. return turtle;
  17. })));
  18. }
  19. }
Success #stdin #stdout 0.16s 36068KB
stdin
forward 35
forward 6
forward 5
forward 7
forward 31
forward 5
forward 34
forward 29
forward 16
forward 47
forward 12
rotate 180
forward 47
forward 13
rotate 180
forward 14
forward 10
forward 14
forward 6
forward 34
forward 38
rotate 90
forward 16
rotate 180
rotate 270
rotate 90
forward 17
rotate 180
forward 7
forward 38
rotate 180
forward 24
forward 8
forward 6
forward 11
forward 3
rotate 270
rotate 180
forward 45
forward 23
forward 2
rotate 180
forward 38
rotate 90
rotate 270
forward 18
forward 38
forward 23
rotate 180
forward 3
forward 16
forward 14
forward 37
rotate 270
rotate 180
rotate 90
rotate 270
rotate 180
forward 30
rotate 90
forward 37
forward 45
rotate 180
rotate 270
forward 2
rotate 90
forward 28
forward 27
forward 42
rotate 90
forward 40
rotate 270
forward 5
rotate 270
forward 49
forward 15
rotate 180
rotate 90
forward 32
forward 13
rotate 270
forward 16
rotate 270
forward 9
rotate 90
forward 37
forward 26
forward 23
forward 1
forward 38
forward 37
rotate 180
forward 30
rotate 90
forward 26
forward 46
forward 36
rotate 180
forward 13
forward 46
stdout
x = -160, y = 273, direction = north