summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTomasz Kramkowski <tk@the-tk.com>2021-12-06 08:52:21 +0000
committerTomasz Kramkowski <tk@the-tk.com>2021-12-06 08:52:21 +0000
commitf5448cb76e52586d1a0957ee6bd54bba2372b49e (patch)
treeee674cfec8073766b69503623b5ecd053f58482d
parent29e2b30ab066b36762326c3315e0e02702d3c246 (diff)
downloadaoc2021-f5448cb76e52586d1a0957ee6bd54bba2372b49e.tar.gz
aoc2021-f5448cb76e52586d1a0957ee6bd54bba2372b49e.tar.xz
aoc2021-f5448cb76e52586d1a0957ee6bd54bba2372b49e.zip
day 6 numpy: now with linalg.matrix_power
-rw-r--r--6np.py7
1 files changed, 2 insertions, 5 deletions
diff --git a/6np.py b/6np.py
index 6b97f9c..92273b1 100644
--- a/6np.py
+++ b/6np.py
@@ -3,7 +3,6 @@ from utils import open_day
import numpy as np
fish = Counter(map(int, open_day(6).read().split(',')))
-
fish = np.array([fish[i] for i in range(9)])
mat = np.array([
[0, 0, 0, 0, 0, 0, 1, 0, 1],
@@ -17,7 +16,5 @@ mat = np.array([
[0, 0, 0, 0, 0, 0, 0, 1, 0]
])
-for i in range(256):
- if i == 80: print(sum(fish))
- fish = np.matmul(fish, mat)
-print(sum(fish))
+print(sum(np.matmul(fish, np.linalg.matrix_power(mat, 80))))
+print(sum(np.matmul(fish, np.linalg.matrix_power(mat, 256))))