summaryrefslogtreecommitdiff
path: root/Advent-of-Code-2021/AOC-6
diff options
context:
space:
mode:
authorkartofen <mladenovnasko0@gmail.com>2022-07-31 11:46:17 +0300
committerkartofen <mladenovnasko0@gmail.com>2022-07-31 11:46:17 +0300
commitaec1c07260257ba7c28eff53f422ddb7daaf316a (patch)
tree88b279cb646bad60c3d55bdd01bb323065fca519 /Advent-of-Code-2021/AOC-6
Big Bang
Diffstat (limited to 'Advent-of-Code-2021/AOC-6')
-rwxr-xr-xAdvent-of-Code-2021/AOC-6/aoc-6bin0 -> 16480 bytes
-rw-r--r--Advent-of-Code-2021/AOC-6/aoc-6.c78
-rw-r--r--Advent-of-Code-2021/AOC-6/aoc-6.c~65
3 files changed, 143 insertions, 0 deletions
diff --git a/Advent-of-Code-2021/AOC-6/aoc-6 b/Advent-of-Code-2021/AOC-6/aoc-6
new file mode 100755
index 0000000..9fe1541
--- /dev/null
+++ b/Advent-of-Code-2021/AOC-6/aoc-6
Binary files differ
diff --git a/Advent-of-Code-2021/AOC-6/aoc-6.c b/Advent-of-Code-2021/AOC-6/aoc-6.c
new file mode 100644
index 0000000..42cd75b
--- /dev/null
+++ b/Advent-of-Code-2021/AOC-6/aoc-6.c
@@ -0,0 +1,78 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+#include <stdint.h>
+
+#define N 9
+#define MAXDAYS 256
+
+u_int64_t table[N];
+u_int64_t temp_table[N];
+
+void PrintTable()
+{
+ for(int i=0; i<N; i++)
+ {
+ printf("%llu: %llu\n", i, table[i]);
+ }
+}
+
+void NextDay()
+{
+ memset(temp_table, 0, sizeof(u_int64_t)*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(u_int64_t)*N);
+}
+
+u_int64_t TableSize()
+{
+ u_int64_t size = 0;
+ for(int i=0; i<N; i++)
+ {
+ size += table[i];
+ }
+
+ return size;
+}
+
+void ParseInput(char *input)
+{
+ for(int i=0; i<strlen(input); i++)
+ {
+ if(input[i] != ',')
+ table[atoi(&(input[i]))] += 1;
+ }
+}
+
+int main(void)
+{
+ memset(table, 0, sizeof(u_int64_t)*N);
+
+ ParseInput("2,1,2,1,5,1,5,1,2,2,1,1,5,1,4,4,4,3,1,2,2,3,4,1,1,5,1,1,4,2,5,5,5,1,1,4,5,4,1,1,4,2,1,4,1,2,2,5,1,1,5,1,1,3,4,4,1,2,3,1,5,5,4,1,4,1,2,1,5,1,1,1,3,4,1,1,5,1,5,1,1,5,1,1,4,3,2,4,1,4,1,5,3,3,1,5,1,3,1,1,4,1,4,5,2,3,1,1,1,1,3,1,2,1,5,1,1,5,1,1,1,1,4,1,4,3,1,5,1,1,5,4,4,2,1,4,5,1,1,3,3,1,1,4,2,5,5,2,4,1,4,5,4,5,3,1,4,1,5,2,4,5,3,1,3,2,4,5,4,4,1,5,1,5,1,2,2,1,4,1,1,4,2,2,2,4,1,1,5,3,1,1,5,4,4,1,5,1,3,1,3,2,2,1,1,4,1,4,1,2,2,1,1,3,5,1,2,1,3,1,4,5,1,3,4,1,1,1,1,4,3,3,4,5,1,1,1,1,1,2,4,5,3,4,2,1,1,1,3,3,1,4,1,1,4,2,1,5,1,1,2,3,4,2,5,1,1,1,5,1,1,4,1,2,4,1,1,2,4,3,4,2,3,1,1,2,1,5,4,2,3,5,1,2,3,1,2,2,1,4");
+ // ParseInput("3,4,3,1,2");
+
+ PrintTable();
+ printf("Size: %llu\n", TableSize());
+ printf("----------------------------\n");
+
+ for(int i=0; i < MAXDAYS; i++)
+ {
+ NextDay();
+ }
+
+ PrintTable();
+ printf("Size: %llu\n", TableSize());
+ printf("Day: %llu\n", MAXDAYS);
+
+ return 0;
+
+}
diff --git a/Advent-of-Code-2021/AOC-6/aoc-6.c~ b/Advent-of-Code-2021/AOC-6/aoc-6.c~
new file mode 100644
index 0000000..5b51725
--- /dev/null
+++ b/Advent-of-Code-2021/AOC-6/aoc-6.c~
@@ -0,0 +1,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;
+}