Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

47 lines
1.1KB

  1. //
  2. // Created by red on 07/12/19.
  3. //
  4. #include <stdbool.h>
  5. #include <stdio.h>
  6. #include <stdlib.h>
  7. #include "intcode.h"
  8. bool in (int* arr, size_t len, int key) {
  9. for (size_t i = 0; i < len; i++){
  10. if (arr[i] == key) return true;
  11. }
  12. return false;
  13. }
  14. int main(int argc, char **argv) {
  15. char* filename = argv[1];
  16. intcode* v = read_file(filename, 2048);
  17. long max = 0;
  18. for(size_t i = 0; i < 3125; i++) {
  19. int bits[5];
  20. int num = (int) i;
  21. for(size_t j = 0; j < 5; j++) {
  22. bits[j] = num % 5; // read the jth bit
  23. num = num / 5; // move to the next bit
  24. }
  25. bool isperm = true;
  26. for(size_t j = 0; j < 5; j++) {
  27. if (in(bits+j+1, 5-j-1, bits[j])) {
  28. isperm = false;
  29. }
  30. }
  31. if (isperm == false) continue;
  32. long input[2] = {0, 0};
  33. for(size_t j = 0; j < 5; j++) {
  34. intcode* m = clone(v, 2048);
  35. input[0] = bits[j];
  36. m->input_tape = input;
  37. ival out_val = run(m);
  38. input[1] = out_val.num;
  39. }
  40. if (input[1] > max) max = input[1];
  41. }
  42. printf("max: %ld\n", max);
  43. return EXIT_SUCCESS;
  44. }