Skip to content

Commit 425554f

Browse files
committed
added 2018/day11
1 parent 04f140a commit 425554f

File tree

4 files changed

+42
-1
lines changed

4 files changed

+42
-1
lines changed

2018/day11/answers.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
44,37
2+
235,87,13

2018/day11/input.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
9798

2018/day11/run.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
#! /usr/bin/env python3
2+
3+
def load_data(filename):
4+
with open(filename, 'r') as f:
5+
line = f.readline().rstrip('\n')
6+
return int(line)
7+
8+
num = load_data('input.txt')
9+
10+
# Part One
11+
12+
import numpy as np
13+
14+
x, y = np.meshgrid(np.arange(1, 301), np.arange(1, 301))
15+
rack_id = x + 10
16+
power_level_starts = rack_id * y
17+
increased_power_level = power_level_starts + num
18+
set_power_level = increased_power_level * rack_id
19+
hundreds = (set_power_level % 1000) // 100
20+
level = hundreds - 5
21+
22+
def max_square(sq):
23+
swv = np.lib.stride_tricks.sliding_window_view(level, [sq, sq])
24+
sums = np.sum(swv, axis=(2, 3))
25+
ind = np.unravel_index(np.argmax(sums), sums.shape)
26+
return sums[ind[0],ind[1]], ind[1]+1, ind[0]+1
27+
28+
_, x, y = max_square(3)
29+
30+
print(f"{x},{y}")
31+
32+
# Part Two
33+
34+
all_squares = [ max_square(sq) for sq in range(1, 50) ]
35+
m = max(all_squares)
36+
sq = all_squares.index(m)
37+
38+
print(f"{m[1]},{m[2]},{sq+1}")

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
2015 ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ -- -- -- -- -- -- -- -- -- -- -- -- -- +
44
2016 ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ -- -- -- -- -- -- -- -- -- -- -- -- -- -
55
2017 ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ -- -- -- -- -- -- -- -- -- -- -- -- -- -
6-
2018 ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ -- -- -- -- -- -- -- -- -- -- -- -- -- -- +
6+
2018 ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ -- -- -- -- -- -- -- -- -- -- -- -- -- +
77
2019 ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ -- ++ ++ -- +- ++ +- -
88
2020 ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ +- ++ ++ ++ ++ ++ +
99
2021 ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ +

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy