File tree Expand file tree Collapse file tree 3 files changed +46
-4
lines changed Expand file tree Collapse file tree 3 files changed +46
-4
lines changed Original file line number Diff line number Diff line change
1
+ # iex()> Day1.first
2
+
3
+ defmodule Dive do
4
+ def load_file ( ) do
5
+ File . read! ( "../input.txt" )
6
+ |> String . replace ( " " , "\n " )
7
+ |> String . split ( "\n " , trim: true )
8
+ end
9
+
10
+ def dive ( input ) do
11
+ dive ( input , { 0 , 0 } )
12
+ end
13
+
14
+ def dive ( [ ] , { depth , horizontal } ) , do: depth * horizontal
15
+
16
+ def dive ( [ "forward" , amount_str | tail ] , { depth , horizontal } ) do
17
+ amount = String . to_integer amount_str
18
+ dive ( tail , { depth , horizontal + amount } )
19
+ end
20
+
21
+ def dive ( [ "down" , amount_str | tail ] , { depth , horizontal } ) do
22
+ amount = String . to_integer amount_str
23
+ dive ( tail , { depth + amount , horizontal } )
24
+ end
25
+
26
+ def dive ( [ "up" , amount_str | tail ] , { depth , horizontal } ) do
27
+ amount = String . to_integer amount_str
28
+ dive ( tail , { depth - amount , horizontal } )
29
+ end
30
+
31
+ @ spec first ( ) :: Integer
32
+ def first ( ) do
33
+ Dive . load_file
34
+ |> dive
35
+ end
36
+
37
+ @ spec second ( [ Integer ] ) :: Integer
38
+ def second ( input ) do
39
+ :second
40
+ end
41
+ end
Original file line number Diff line number Diff line change 19
19
print (f"Product: { horizontal * depth } " )
20
20
21
21
# Part 2
22
- with open ("input.txt" ) as f :
22
+ with open ("../ input.txt" ) as f :
23
23
lines = map (lambda l : l .strip (), f .readlines ())
24
24
aim = 0
25
25
depth = 0
Original file line number Diff line number Diff line change 1
1
# Advent of Code
2
2
3
- This code may contain spoilers, if you haven't finished the puzzles over on https://adventofcode.com .
3
+ This code may contain spoilers, if you haven't finished the puzzles over on
4
+ https://adventofcode.com .
4
5
5
6
## Running
6
7
7
- Paste your input in a file named ` input.txt ` in the root of the project of the
8
- desired language. After that, follow the instructions for each language:
8
+ Paste your input in a file named ` input.txt ` in the root of the project. After
9
+ that, follow the instructions for each language:
9
10
10
11
### Rust
11
12
You can’t perform that action at this time.
0 commit comments