Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 3bdaa41

Browse files
committed
added 2016/day13
1 parent abcfac6 commit 3bdaa41

File tree

4 files changed

+50
-1
lines changed

4 files changed

+50
-1
lines changed

‎2016/day13/answers.txt‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
86
2+
127

‎2016/day13/input.txt‎

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

‎2016/day13/run.py‎

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
#! /usr/bin/env python3
2+
3+
def load_data(filename):
4+
with open(filename, 'r') as f:
5+
for line in f:
6+
line = line.rstrip('\n')
7+
yield line
8+
9+
# Part One
10+
11+
office_designer_s_favorite_number = int(next(load_data('input.txt')))
12+
13+
def is_wall(x, y):
14+
global office_designer_s_favorite_number
15+
n = x*x + 3*x + 2*x*y + y + y*y
16+
n += office_designer_s_favorite_number
17+
return n.bit_count() & 1
18+
19+
import networkx as nx
20+
21+
G = nx.Graph()
22+
23+
s = (1, 1)
24+
e = (31, 39)
25+
26+
for y in range(50):
27+
for x in range(50):
28+
if is_wall(x, y):
29+
continue
30+
if not is_wall(x+1, y):
31+
G.add_edge( (x, y), (x+1, y), weight=1 )
32+
if not is_wall(x, y+1):
33+
G.add_edge( (x, y), (x, y+1), weight=1 )
34+
35+
result = len(nx.shortest_path(G, s, e)) - 1
36+
37+
print(result)
38+
39+
# Part Two
40+
41+
lengths = nx.single_source_dijkstra_path_length(G, s, cutoff=50, weight='weight')
42+
43+
result = len(lengths)
44+
45+
print(result)
46+

‎README.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
```
22
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
33
2015 ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ -- -- -- -- -- -- -- -- -- -- -- +-
4-
2016 ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ -- -- -- -- -- -- -- -- -- -- -- -- --
4+
2016 ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ -- -- -- -- -- -- -- -- -- -- -- --
55
2017 ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ -- -- -- -- -- -- -- -- -- -- -- -- --
66
2018 ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ -- -- -- -- -- -- -- -- -- -- -- -- +-
77
2019 ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ -- ++ ++ -- +- ++ +- --

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /