fork download
  1. typedef struct c {
  2. int x,y,b,r
  3. } c; //c will hold the information for each day
  4.  
  5. //determines if a number is a perfect square
  6. s(d) {
  7. int i=sqrt(d);
  8. return i*i==d;
  9. }
  10.  
  11. c m(d) {
  12. if(!d) {
  13. c b={2,2,4,4};
  14. return b; //returns the initial information if the day is 0
  15. }
  16. int i,p,n;
  17. for (i=d,p=1,n=i;--i;p=p*i*i%n); //tests if the number is prime
  18.  
  19. c l=m(d-1); //gets the information for the previous day
  20.  
  21. if (p&&d>1) {
  22. c q=m(d-2);
  23. l.x=q.x,l.y=q.y; //changes the position to what it was at the end of the day 2 days ago if the day is prime
  24. }
  25. if (d%2)
  26. l.x-=l.x>2?1:l.x<2?-1:0,l.y-=l.y>2?1:l.y<2?-1:0; //moves the position towards (2,2) if the day is odd
  27. else
  28. l.y+=d/2,l.y=l.y>l.b?l.y-l.b-1:l.y; //moves down if the day is even
  29. if (s(d))
  30. l.x=l.r; //moves east if the day is a perfect square
  31. if (s(5*d*d+4)||s(5*d*d-4))
  32. l.b++; //expands world down if the day is a fibonacci number
  33. if (s(8*d+1))
  34. l.r++; //expands world right if the day is a triangular number
  35. return l;
  36. }
  37.  
  38. main() {
  39. for (int i = 0; i < 24; i++)
  40. {
  41. c ll=m(i);
  42. printf("Day %d: %d %d\n",i,ll.x,ll.y);
  43. }
  44. }
Success #stdin #stdout 0s 2160KB
stdin
Standard input is empty
stdout
Day 0: 2 2
Day 1: 4 2
Day 2: 2 3
Day 3: 3 2
Day 4: 6 4
Day 5: 2 2
Day 6: 2 5
Day 7: 2 2
Day 8: 2 6
Day 9: 7 5
Day 10: 7 0
Day 11: 6 4
Day 12: 6 0
Day 13: 5 3
Day 14: 5 10
Day 15: 4 9
Day 16: 9 6
Day 17: 3 8
Day 18: 3 6
Day 19: 2 7
Day 20: 2 6
Day 21: 2 5
Day 22: 2 4
Day 23: 2 4