Skip to content

Commit 2e9cd97

Browse files
committed
Add 2022/18 py
1 parent a95497a commit 2e9cd97

File tree

13 files changed

+173
-1
lines changed

13 files changed

+173
-1
lines changed

2022/18/README.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# Advent of Code - 2022 Day 18
2+
Here are my solutions to this puzzle.
3+
4+
* Problem instructions: [adventofcode.com/2022/day/18](https://adventofcode.com/2022/day/18)
5+
* Input: [adventofcode.com/2022/day/18/input](https://adventofcode.com/2022/day/18/input)
6+
7+
Fetch input by exporting `$AOC_SESSION` in your shell and then:
8+
```bash
9+
curl -OJLsb session=$AOC_SESSION adventofcode.com/2022/day/18/input
10+
```
11+
12+
or run `fetch_input.sh` in this directory.

2022/18/fetch_input.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#!/usr/bin/env sh
2+
# Make sure $AOC_SESSION is exported before running this script.
3+
4+
curl --remote-name --remote-header-name --silent --fail -A 'https://erikw.me/contact' --cookie "session=$AOC_SESSION" "https://adventofcode.com/2022/day/18/input"
5+
test "$?" -eq 0 && echo "Fetched input" && exit 0 || echo "Failed to fetch input" && exit 1

2022/18/input1.0

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

2022/18/input1.1

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
2,2,2
2+
1,2,2
3+
3,2,2
4+
2,1,2
5+
2,3,2
6+
2,2,1
7+
2,2,3
8+
2,2,4
9+
2,2,6
10+
1,2,5
11+
3,2,5
12+
2,1,5
13+
2,3,5

2022/18/instructions.url

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[InternetShortcut]
2+
URL=https://adventofcode.com/2022/day/18

2022/18/output1.0

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

2022/18/output1.1

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

2022/18/output2.0

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

2022/18/output2.1

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

2022/18/part1.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#!/usr/bin/env python3
2+
import fileinput
3+
4+
5+
def droplet_scan():
6+
return [tuple(int(c) for c in line.split(",")) for line in fileinput.input()]
7+
8+
9+
DELTAS = [
10+
(-1, 0, 0),
11+
(1, 0, 0),
12+
(0, -1, 0),
13+
(0, 1, 0),
14+
(0, 0, -1),
15+
(0, 0, 1),
16+
]
17+
18+
19+
def neighbours(droplet):
20+
for delta in DELTAS:
21+
yield tuple(a + b for a, b in zip(droplet, delta))
22+
23+
24+
def main():
25+
droplets = droplet_scan()
26+
sides = sum(dn not in droplets for d in droplets for dn in neighbours(d))
27+
print(sides)
28+
29+
30+
if __name__ == "__main__":
31+
main()

0 commit comments

Comments
 (0)