summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTomasz Kramkowski <tk@the-tk.com>2021-12-06 09:07:29 +0000
committerTomasz Kramkowski <tk@the-tk.com>2021-12-06 09:07:29 +0000
commite400c1fab39d87c72f867007952ae3ef65823766 (patch)
tree6f60d9e5011fdcffa0bc73bbcb4f40906346104c
parentf5448cb76e52586d1a0957ee6bd54bba2372b49e (diff)
downloadaoc2021-e400c1fab39d87c72f867007952ae3ef65823766.tar.gz
aoc2021-e400c1fab39d87c72f867007952ae3ef65823766.tar.xz
aoc2021-e400c1fab39d87c72f867007952ae3ef65823766.zip
day 6 numpy: shorter
-rw-r--r--6np.py13
1 files changed, 2 insertions, 11 deletions
diff --git a/6np.py b/6np.py
index 92273b1..8d90f1f 100644
--- a/6np.py
+++ b/6np.py
@@ -4,17 +4,8 @@ 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],
- [1, 0, 0, 0, 0, 0, 0, 0, 0],
- [0, 1, 0, 0, 0, 0, 0, 0, 0],
- [0, 0, 1, 0, 0, 0, 0, 0, 0],
- [0, 0, 0, 1, 0, 0, 0, 0, 0],
- [0, 0, 0, 0, 1, 0, 0, 0, 0],
- [0, 0, 0, 0, 0, 1, 0, 0, 0],
- [0, 0, 0, 0, 0, 0, 1, 0, 0],
- [0, 0, 0, 0, 0, 0, 0, 1, 0]
-])
+mat = np.eye(9, 9, -1, dtype=int)
+mat[0, [6, 8]] = 1
print(sum(np.matmul(fish, np.linalg.matrix_power(mat, 80))))
print(sum(np.matmul(fish, np.linalg.matrix_power(mat, 256))))