summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorBrian Chu <brianmchu42@gmail.com>2021-12-05 22:42:46 -0800
committerBrian Chu <brianmchu42@gmail.com>2021-12-05 22:42:46 -0800
commit659d106cc6e92fc8ab89044b3ca260a26a9647ca (patch)
tree46865d322bb4ab5888aee8eb66c08d02e67e05b6
parentb8e6840a1780b4358bbd7c483720a14c87d93788 (diff)
downloadAdventOfCode2021-659d106cc6e92fc8ab89044b3ca260a26a9647ca.tar.gz
solution for day 6
-rw-r--r--day6.py24
1 files changed, 24 insertions, 0 deletions
diff --git a/day6.py b/day6.py
new file mode 100644
index 0000000..c964cd9
--- /dev/null
+++ b/day6.py
@@ -0,0 +1,24 @@
+#!/usr/bin/env python
+
+with open("day6.txt") as data:
+    population = [num for num in map(int, next(data).strip().split(','))]
+
+
+memo = {}
+def count_children(age, time):
+    if (age, time) not in memo:
+        result = 0
+        if time == 0:
+            result = 1
+        elif age == 0:
+            result = count_children(6, time - 1) + count_children(8, time - 1)
+        else:
+            result = count_children(age - 1, time - 1)
+        memo[(age, time)] = result
+    return memo[(age, time)]
+
+# part 1
+print(sum(map(lambda x: count_children(x, 80), population)))
+
+# part 2
+print(sum(map(lambda x: count_children(x, 256), population)))
lt;vc@akkartik.com> 2016-09-17 15:01:51 -0700 committer Kartik K. Agaram <vc@akkartik.com> 2016-09-17 15:01:51 -0700 3395' href='/akkartik/mu/commit/html/038new_text.cc.html?h=main&id=f344b250f6f062a1a1902bf69b23ebf9b565de0e'>f344b250 ^
32b8fac2 ^

3e1349d2 ^
f344b250 ^

32b8fac2 ^




3e1349d2 ^
f344b250 ^


32b8fac2 ^





f344b250 ^
32b8fac2 ^
f344b250 ^
32b8fac2 ^
f344b250 ^
32b8fac2 ^
f344b250 ^
32b8fac2 ^




f344b250 ^
32b8fac2 ^


cd9bb850 ^







32b8fac2 ^

d059fe74 ^
32b8fac2 ^


cd9bb850 ^

32b8fac2 ^
cd9bb850 ^
32b8fac2 ^







3e1349d2 ^
f344b250 ^

32b8fac2 ^


2f02189d ^
f344b250 ^
32b8fac2 ^
f344b250 ^
32b8fac2 ^


3e1349d2 ^
f344b250 ^

32b8fac2 ^



3e1349d2 ^
f344b250 ^

32b8fac2 ^


298f8065 ^
3e1349d2 ^
f344b250 ^

298f8065 ^



f344b250 ^
298f8065 ^

32b8fac2 ^

cd9bb850 ^
3e1349d2 ^

f344b250 ^
32b8fac2 ^
cd9bb850 ^

32b8fac2 ^














f344b250 ^
32b8fac2 ^
cd9bb850 ^
32b8fac2 ^


d059fe74 ^
32b8fac2 ^







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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178