Skip to content

Commit c0035fd

Browse files
committed
pocket watch everywhere
1 parent 85afdc8 commit c0035fd

File tree

15 files changed

+61
-6
lines changed

15 files changed

+61
-6
lines changed

src/aoc_2024/day_1.gleam

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,13 @@ import gleam/list
55
import gleam/otp/task
66
import gleam/result
77
import gleam/string
8+
import pocket_watch
89

910
pub type Input =
1011
#(List(Int), List(Int))
1112

1213
pub fn parse(input: String) -> Input {
14+
use <- pocket_watch.simple("parse")
1315
input
1416
|> string.split("\n")
1517
|> extra.pmap(string.split(_, " "))
@@ -25,6 +27,7 @@ pub fn parse(input: String) -> Input {
2527
}
2628

2729
pub fn pt_1(input: Input) {
30+
use <- pocket_watch.simple("part 1")
2831
let sorted_xs_handle = task.async(fn() { list.sort(input.0, int.compare) })
2932
let sorted_ys_handle = task.async(fn() { list.sort(input.1, int.compare) })
3033
let sorted_xs = task.await_forever(sorted_xs_handle)
@@ -35,6 +38,7 @@ pub fn pt_1(input: Input) {
3538
}
3639

3740
pub fn pt_2(input: Input) {
41+
use <- pocket_watch.simple("part 2")
3842
let #(xs, ys) = input
3943
let freqs = extra.frequencies(ys)
4044

src/aoc_2024/day_10.gleam

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,24 @@ import gleam/int
33
import gleam/list
44
import gleam/set.{type Set}
55
import grid.{type Grid, type XY}
6+
import pocket_watch
67

78
pub fn parse(input: String) -> Grid(Int) {
9+
use <- pocket_watch.simple("parse")
810
grid.from_string(input)
911
|> grid.map(fn(_, c) { extra.yolo_int(c) })
1012
}
1113

1214
pub fn pt_1(input: Grid(Int)) {
15+
use <- pocket_watch.simple("part 1")
1316
let starting_positions: List(XY) = grid.find_all_exact(input, 0)
1417
starting_positions
1518
|> list.map(trailheads_count(input, _))
1619
|> int.sum
1720
}
1821

1922
pub fn pt_2(input: Grid(Int)) {
23+
use <- pocket_watch.simple("part 2")
2024
let starting_positions: List(XY) = grid.find_all_exact(input, 0)
2125
starting_positions
2226
|> list.map(trailheads_rating(input, _))

src/aoc_2024/day_11.gleam

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,15 @@ pub fn parse(input: String) -> List(Int) {
1414
}
1515

1616
pub fn pt_1(input: List(Int)) {
17-
use <- pocket_watch.simple("pt_1")
17+
use <- pocket_watch.simple("part 1")
1818
use cache <- memo.create()
1919
input
2020
|> list.map(c(_, 25, cache))
2121
|> int.sum
2222
}
2323

2424
pub fn pt_2(input: List(Int)) {
25-
use <- pocket_watch.simple("pt_2")
25+
use <- pocket_watch.simple("part 2")
2626
use cache <- memo.create()
2727
input
2828
|> list.map(c(_, 75, cache))

src/aoc_2024/day_12.gleam

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,22 @@ import gleam/int
33
import gleam/list
44
import gleam/set.{type Set}
55
import grid.{type Grid, type XY}
6+
import pocket_watch
67

78
pub fn parse(input: String) -> Grid(String) {
9+
use <- pocket_watch.simple("parse")
810
grid.from_string(input)
911
}
1012

1113
pub fn pt_1(input: Grid(String)) {
14+
use <- pocket_watch.simple("part 1")
1215
grid.group_consecutive(input, grid.orthogonal_dirs)
1316
|> list.map(fn(kv) { area(kv.1) * perimeter(kv.1) })
1417
|> int.sum
1518
}
1619

1720
pub fn pt_2(input: Grid(String)) {
21+
use <- pocket_watch.simple("part 2")
1822
//io.println_error(grid.to_string(
1923
// input,
2024
// fun: fn(s) { #(s, Error(Nil)) },
@@ -55,7 +59,7 @@ pub fn pt_2(input: Grid(String)) {
5559
// empty: ".",
5660
//))
5761

58-
list.map2(groups, distinguished_groups, fn(old, kv) {
62+
list.map2(groups, distinguished_groups, fn(_, kv) {
5963
let area_ = area(kv.1)
6064
let sides_ = sides(fences, group_id: kv.0)
6165
let result = area_ * sides_

src/aoc_2024/day_13.gleam

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
11
import extra
22
import gleam/bool
33
import gleam/int
4-
import gleam/io
54
import gleam/list
65
import gleam/string
76
import grid.{type XY}
7+
import pocket_watch
88

99
pub type Machine {
1010
Machine(a: XY, b: XY, prize: XY)
1111
}
1212

1313
pub fn parse(input: String) -> List(Machine) {
14+
use <- pocket_watch.simple("parse")
1415
input
1516
|> string.split("\n\n")
1617
|> list.map(parse_machine)
@@ -38,6 +39,7 @@ fn parse_machine(input: String) -> Machine {
3839
}
3940

4041
pub fn pt_1(input: List(Machine)) {
42+
use <- pocket_watch.simple("part 1")
4143
input
4244
|> list.map(solve_machine)
4345
|> int.sum
@@ -68,6 +70,7 @@ fn solve_machine(machine: Machine) -> Int {
6870
}
6971

7072
pub fn pt_2(input: List(Machine)) {
73+
use <- pocket_watch.simple("part 2")
7174
input
7275
|> list.map(fn(machine) {
7376
Machine(

src/aoc_2024/day_14.gleam

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,15 @@ import gleam/int
44
import gleam/io
55
import gleam/list
66
import gleam/string
7-
import grid.{type XY, Dims}
7+
import grid.{type XY}
8+
import pocket_watch
89

910
pub type Robot {
1011
Robot(p: XY, v: XY)
1112
}
1213

1314
pub fn parse(input: String) -> List(Robot) {
15+
use <- pocket_watch.simple("parse")
1416
input
1517
|> string.split("\n")
1618
|> list.map(parse_robot)
@@ -38,6 +40,7 @@ fn parse_robot(line: String) -> Robot {
3840
}
3941

4042
pub fn pt_1(robots: List(Robot)) {
43+
use <- pocket_watch.simple("part 1")
4144
robots
4245
|> step_times(100)
4346
|> io.debug
@@ -103,6 +106,7 @@ fn robots_in_quadrant(robots: List(Robot), q: XY) -> List(Robot) {
103106
}
104107

105108
pub fn pt_2(robots: List(Robot)) {
109+
use <- pocket_watch.simple("part 2")
106110
step_pt2(0, robots)
107111
}
108112

src/aoc_2024/day_15.gleam

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import gleam/io
44
import gleam/list
55
import gleam/string
66
import grid.{type Dir, type Grid, type XY}
7+
import pocket_watch
78

89
pub type Input {
910
Input(grid: Grid(Entity), robot: XY, moves: List(Dir))
@@ -15,6 +16,7 @@ pub type Entity {
1516
}
1617

1718
pub fn parse(input: String) -> Input {
19+
use <- pocket_watch.simple("parse")
1820
case string.split(input, "\n\n") {
1921
[map, moves] -> {
2022
let char_grid = grid.from_string(map)
@@ -50,6 +52,7 @@ pub fn parse(input: String) -> Input {
5052
}
5153

5254
pub fn pt_1(input: Input) {
55+
use <- pocket_watch.simple("part 1")
5356
input.moves
5457
|> list.fold(from: #(input.grid, input.robot), with: step)
5558
|> fn(state) { state.0 }
@@ -60,6 +63,7 @@ pub fn pt_1(input: Input) {
6063
}
6164

6265
pub fn pt_2(input: Input) {
66+
use <- pocket_watch.simple("part 2")
6367
let wider_grid = widen(input.grid)
6468
let wider_robot = grid.xy_mul(input.robot, #(2, 1))
6569
let #(final_grid, _) =
@@ -266,7 +270,7 @@ fn wider_step_find_nonbox(
266270
frontmost_touches,
267271
list.map(frontmost_touches, grid.get(grid, _)),
268272
))
269-
todo
273+
panic as "Unfinished case (not needed though)"
270274
}
271275
}
272276
}

src/aoc_2024/day_2.gleam

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,10 @@ import extra
22
import gleam/int
33
import gleam/list
44
import gleam/string
5+
import pocket_watch
56

67
pub fn parse(input: String) -> List(List(Int)) {
8+
use <- pocket_watch.simple("parse")
79
input
810
|> string.split("\n")
911
|> list.map(fn(line) {
@@ -32,10 +34,12 @@ fn is_ok(line: List(Int)) {
3234
}
3335

3436
pub fn pt_1(input: List(List(Int))) {
37+
use <- pocket_watch.simple("part 1")
3538
list.count(input, is_ok)
3639
}
3740

3841
pub fn pt_2(input: List(List(Int))) {
42+
use <- pocket_watch.simple("part 2")
3943
input
4044
|> list.count(fn(line) {
4145
line

src/aoc_2024/day_3.gleam

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import gleam/int
33
import gleam/list
44
import gleam/regexp
55
import gleam/string
6+
import pocket_watch
67

78
pub type Op {
89
Mul(Int, Int)
@@ -26,6 +27,7 @@ fn from_match(match: regexp.Match) -> Op {
2627
}
2728

2829
pub fn parse(input: String) -> List(Op) {
30+
use <- pocket_watch.simple("parse")
2931
let assert Ok(regex) =
3032
regexp.from_string("mul\\(\\d+,\\d+\\)|do\\(\\)|don't\\(\\)")
3133

@@ -35,6 +37,7 @@ pub fn parse(input: String) -> List(Op) {
3537
}
3638

3739
pub fn pt_1(ops: List(Op)) {
40+
use <- pocket_watch.simple("part 1")
3841
ops
3942
|> list.map(fn(op) {
4043
case op {
@@ -51,6 +54,7 @@ type State {
5154
}
5255

5356
pub fn pt_2(ops: List(Op)) {
57+
use <- pocket_watch.simple("part 2")
5458
let result =
5559
ops
5660
|> list.fold(State(0, True), fn(acc, op) {

src/aoc_2024/day_4.gleam

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,26 @@ import gleam/list
33
import gleam/result
44
import gleam/string
55
import grid.{type Grid, type XY}
6+
import pocket_watch
67

78
pub type XGrid =
89
Grid(String)
910

1011
pub fn parse(input: String) -> XGrid {
12+
use <- pocket_watch.simple("parse")
1113
grid.from_string(input)
1214
}
1315

1416
pub fn pt_1(grid: XGrid) {
17+
use <- pocket_watch.simple("part 1")
1518
grid
1619
|> grid.map(fn(xy, _) { xmas_count(grid, xy) })
1720
|> grid.values
1821
|> int.sum
1922
}
2023

2124
pub fn pt_2(grid: XGrid) {
25+
use <- pocket_watch.simple("part 2")
2226
grid
2327
|> grid.map(fn(xy, _) { x_mas_count(grid, xy) })
2428
|> grid.values

0 commit comments

Comments
 (0)