summaryrefslogtreecommitdiff
path: root/Advent-of-Code-2021/AOC-6/aoc-6.c~
blob: 5b51725d8555880c87093349a572bf5ed5b24ada (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>

#define N 9
#define MAXDAYS 80

int table[N];

void PrintTable()
{
  for(int i=0; i<N; i++)
  {
    printf("%d: %d\n", i, table[i]);
  }
}

void NextDay()
{
  int temp_table[N];
  memset(temp_table, 0, sizeof(int)*N);

  for(int i=1; i<N; i++)
  {
    temp_table[i-1] = table[i];
  }

  temp_table[6] += table[0];
  temp_table[8] += table[0];

  memcpy(table, temp_table, sizeof(int)*N);
}

int TableSize()
{
  int size = 0;
  for(int i=0; i<N; i++)
  {
    size += table[i];
  }

  return size;
}

int main(void)
{
  memset(table, 0, sizeof(int)*N);

  table[1] = 1;
  table[2] = 1;
  table[3] = 2;
  table[4] = 1;

  for(int i=0; i < MAXDAYS; i++) 
  {
    NextDay();
  }

  PrintTable();
  printf("Size: %d\n", TableSize());
  printf("Day:  %d\n", MAXDAYS);
  
  return 0;
}