Advertisement
Guest User

Untitled

a guest
Dec 3rd, 2016
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.81 KB | None | 0 0
  1. import java.util.ArrayList;
  2. import java.util.HashMap;
  3.  
  4. public class Lucka1 {
  5.  
  6. public static void main(String[] args) {
  7. String input = "L5, R1, R4, L5, L4, R3, R1, L1, R4, R5, L1, L3, R4, L2, L4, R2, L4, L1, R3, R1, R1, L1, R1, L5, R5, R2, L5, R2, R1, L2, L4, L4, R191, R2, R5, R1, L1, L2, R5, L2, L3, R4, L1, L1, R1, R50, L1, R1, R76, R5, R4, R2, L5, L3, L5, R2, R1, L1, R2, L3, R4, R2, L1, L1, R4, L1, L1, R185, R1, L5, L4, L5, L3, R2, R3, R1, L5, R1, L3, L2, L2, R5, L1, L1, L3, R1, R4, L2, L1, L1, L3, L4, R5, L2, R3, R5, R1, L4, R5, L3, R3, R3, R1, R1, R5, R2, L2, R5, L5, L4, R4, R3, R5, R1, L3, R1, L2, L2, R3, R4, L1, R4, L1, R4, R3, L1, L4, L1, L5, L2, R2, L1, R1, L5, L3, R4, L1, R5, L5, L5, L1, L3, R1, R5, L2, L4, L5, L1, L1, L2, R5, R5, L4, R3, L2, L1, L3, L4, L5, L5, L2, R4, R3, L5, R4, R2, R1, L5";
  8. //String input = "R8, R4, R4, R8";
  9. String[] inputArray = input.split(", ");
  10. int direction = 90;
  11. int x = 0;
  12. int y = 0;
  13. HashMap<Integer, ArrayList<Integer>> hm = new HashMap<Integer, ArrayList<Integer>>();
  14. for (int i = 0; i < inputArray.length; i++) {
  15. if (inputArray[i].startsWith("L")) {
  16. direction += 90;
  17. } else {
  18. direction -= 90;
  19. }
  20. int steps = Integer.parseInt(inputArray[i].substring(1));
  21. for (int ii = 0; ii < steps; ii++) {
  22. x += (int) Math.cos(Math.toRadians(direction));
  23. y += (int) Math.sin(Math.toRadians(direction));
  24. if (hm.containsKey(x + y)) {
  25. ArrayList<Integer> al = hm.get(x + y);
  26. if (al.contains(x)) {
  27. System.out.println("Rätt: "
  28. + (Math.abs(x) + Math.abs(y)));
  29. } else {
  30. al.add(x);
  31. hm.put(x + y, al);
  32. }
  33. } else {
  34. ArrayList<Integer> al = new ArrayList<Integer>();
  35. al.add(x);
  36. hm.put(x + y, al);
  37. }
  38. }
  39.  
  40. }
  41. System.out.println((Math.abs(x) + Math.abs(y)));
  42. }
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement