Skip to content

Commit 02eb202

Browse files
committed
Support multiple days
1 parent 32fbfd9 commit 02eb202

File tree

1 file changed

+21
-5
lines changed

1 file changed

+21
-5
lines changed

src/adventofcode2024.gleam

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,36 @@
11
import gleam/int
22
import gleam/io
3+
import gleam/list
34

5+
import argv
46
import simplifile
57

68
import day1
79

810
pub fn main() {
9-
run(1)
11+
case argv.load().arguments {
12+
[arg] ->
13+
case int.parse(arg) {
14+
Ok(n) -> run(n)
15+
Error(_) -> io.println("Invalid day: " <> arg)
16+
}
17+
_ -> list.range(1, 1) |> list.each(fn(n) { run(n) })
18+
}
1019
}
1120

1221
fn run(n: Int) -> Nil {
1322
let input = read_input(n)
14-
io.print("Day " <> int.to_string(n) <> " Part 1: ")
15-
io.println(int.to_string(day1.part1(input)))
16-
io.print("Day " <> int.to_string(n) <> " Part 2: ")
17-
io.println(int.to_string(day1.part2(input)))
23+
let output = fn(s) { "Day " <> int.to_string(n) <> " " <> s }
24+
io.print(output("Part 1: "))
25+
io.println(case n {
26+
1 -> day1.part1(input) |> int.to_string
27+
_ -> "(not implemented)"
28+
})
29+
io.print(output("Part 2: "))
30+
io.println(case n {
31+
1 -> day1.part2(input) |> int.to_string
32+
_ -> "(not implemented)"
33+
})
1834
}
1935

2036
fn read_input(n: Int) -> String {

0 commit comments

Comments
 (0)