horvathm

Untitled

Dec 15th, 2020 (edited)
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.58 KB | None | 0 0
  1. #include <stdio.h>
  2.  
  3. #define TURNS 30000000
  4.  
  5. const int input[] = { 0, 20, 7, 16, 1, 18, 15 };
  6. const int inputLen = sizeof(input) / sizeof(input[0]);
  7.  
  8. int nums[TURNS + sizeof(input) / sizeof(input[0]) + 1] = {};
  9.  
  10. int main() {
  11.     int turn = 1;
  12.  
  13.     int last;
  14.     for (int i = 0; i < inputLen; ++i) {
  15.         last = input[i];
  16.         nums[last] = turn;
  17.  
  18.         turn++;
  19.     }
  20.  
  21.     while (turn <= TURNS) {
  22.         int lastturn = nums[last];
  23.         nums[last] = turn - 1;
  24.  
  25.         if (lastturn == 0) {
  26.             last = 0;
  27.         } else {
  28.             last = turn - lastturn - 1;
  29.         }
  30.  
  31.         turn++;
  32.     }
  33.  
  34.     printf("%d %d\n", turn, last);
  35. }
  36.  
Advertisement
Add Comment
Please, Sign In to add comment