Advertisement
Guest User

Untitled

a guest
Dec 12th, 2019
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.87 KB | None | 0 0
  1.     @Test
  2.     public void test() {
  3.         int[] memory = {3,8,1001,8,10,8,105,1,0,0,21,34,51,64,73,98,179,260,341,422,99999,3,9,102,4,9,9,1001,9,4,9,4,9,99,3,9,1001,9,4,9,1002,9,3,9,1001,9,5,9,4,9,99,3,9,101,5,9,9,102,5,9,9,4,9,99,3,9,101,5,9,9,4,9,99,3,9,1002,9,5,9,1001,9,3,9,102,2,9,9,101,5,9,9,1002,9,2,9,4,9,99,3,9,1001,9,1,9,4,9,3,9,1002,9,2,9,4,9,3,9,1001,9,2,9,4,9,3,9,1001,9,2,9,4,9,3,9,102,2,9,9,4,9,3,9,102,2,9,9,4,9,3,9,101,1,9,9,4,9,3,9,101,1,9,9,4,9,3,9,102,2,9,9,4,9,3,9,101,2,9,9,4,9,99,3,9,101,1,9,9,4,9,3,9,1001,9,1,9,4,9,3,9,102,2,9,9,4,9,3,9,102,2,9,9,4,9,3,9,101,2,9,9,4,9,3,9,101,1,9,9,4,9,3,9,101,1,9,9,4,9,3,9,1002,9,2,9,4,9,3,9,1002,9,2,9,4,9,3,9,1001,9,2,9,4,9,99,3,9,101,2,9,9,4,9,3,9,102,2,9,9,4,9,3,9,1001,9,2,9,4,9,3,9,1001,9,2,9,4,9,3,9,1001,9,2,9,4,9,3,9,101,2,9,9,4,9,3,9,1001,9,1,9,4,9,3,9,102,2,9,9,4,9,3,9,102,2,9,9,4,9,3,9,101,2,9,9,4,9,99,3,9,1002,9,2,9,4,9,3,9,102,2,9,9,4,9,3,9,1001,9,2,9,4,9,3,9,1002,9,2,9,4,9,3,9,1001,9,2,9,4,9,3,9,1002,9,2,9,4,9,3,9,102,2,9,9,4,9,3,9,102,2,9,9,4,9,3,9,101,2,9,9,4,9,3,9,1001,9,2,9,4,9,99,3,9,1001,9,1,9,4,9,3,9,101,1,9,9,4,9,3,9,1002,9,2,9,4,9,3,9,1001,9,2,9,4,9,3,9,1001,9,1,9,4,9,3,9,101,1,9,9,4,9,3,9,102,2,9,9,4,9,3,9,1001,9,2,9,4,9,3,9,1002,9,2,9,4,9,3,9,1001,9,2,9,4,9,99
  4.         };
  5.  
  6.         List<String> possible_arguments = permutations("", "01234", 5);
  7.         int highest = 0;
  8.         for (String possible : possible_arguments) {
  9.  
  10.             Deque<Integer> input = new ArrayDeque<>(List.of(0));
  11.             Deque<Integer> manual_input = toDeque(possible);
  12.  
  13.             Memory m = new ArrayMemory(memory);
  14.             Processor processor = new Processor(m, new DefaultInstructionSet(input::poll, input::addFirst));
  15.  
  16.             for (int i = 0; i < 5; i++) {
  17.                 input.addFirst(manual_input.poll());
  18.                 processor.process();
  19.  
  20.                 if (input.peek() >= highest) {
  21.                     highest = input.peek();
  22.                 }
  23.             }
  24.  
  25.         }
  26.  
  27.         System.out.println(highest);
  28.     }
  29.     public List<String> permutations(String prefix, String str, int k) {
  30.         if (prefix.length() == k) {
  31.             return Collections.singletonList(prefix);
  32.         }
  33.         List<String> results = new ArrayList<>();
  34.         for (int i = 0; i < str.length(); i++) {
  35.             results.addAll(permutations(prefix + str.charAt(i), str.substring(0, i) + str.substring(i+1, str.length()), k));
  36.         }
  37.         return results;
  38.     }
  39.  
  40.     public Deque<Integer> toDeque(String list) {
  41.         return Stream.of(list).flatMapToInt(string -> {
  42.                     int[] ints = new int[string.length()];
  43.                     for (int i = 0; i < string.length(); i++)
  44.                         ints[i] = Integer.valueOf("" + string.charAt(i));
  45.                     return Arrays.stream(ints);
  46.                 }).boxed().distinct().collect(Collectors.toCollection(ArrayDeque::new));
  47.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement