Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.ArrayList;
- import java.util.HashMap;
- public class Lucka1 {
- public static void main(String[] args) {
- 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";
- //String input = "R8, R4, R4, R8";
- String[] inputArray = input.split(", ");
- int direction = 90;
- int x = 0;
- int y = 0;
- HashMap<Integer, ArrayList<Integer>> hm = new HashMap<Integer, ArrayList<Integer>>();
- for (int i = 0; i < inputArray.length; i++) {
- if (inputArray[i].startsWith("L")) {
- direction += 90;
- } else {
- direction -= 90;
- }
- int steps = Integer.parseInt(inputArray[i].substring(1));
- for (int ii = 0; ii < steps; ii++) {
- x += (int) Math.cos(Math.toRadians(direction));
- y += (int) Math.sin(Math.toRadians(direction));
- if (hm.containsKey(x + y)) {
- ArrayList<Integer> al = hm.get(x + y);
- if (al.contains(x)) {
- System.out.println("Rätt: "
- + (Math.abs(x) + Math.abs(y)));
- } else {
- al.add(x);
- hm.put(x + y, al);
- }
- } else {
- ArrayList<Integer> al = new ArrayList<Integer>();
- al.add(x);
- hm.put(x + y, al);
- }
- }
- }
- System.out.println((Math.abs(x) + Math.abs(y)));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement