diff options
| author | Alexandre Jesus <adbjesus@gmail.com> | 2025-12-03 21:05:57 +0000 |
|---|---|---|
| committer | Alexandre Jesus <adbjesus@gmail.com> | 2025-12-03 21:05:57 +0000 |
| commit | 6d80c94eb7ea8ac0421df0832409b63be7c1246a (patch) | |
| tree | 675ceb3feb257c4986860b4a10de5becc677a94a /lib/day01.ml | |
| parent | c260cea076a5dda847e108454aedc10385ea5c10 (diff) | |
| download | aoc2025-6d80c94eb7ea8ac0421df0832409b63be7c1246a.tar.gz aoc2025-6d80c94eb7ea8ac0421df0832409b63be7c1246a.zip | |
Setup ocamlformat
Define a initial setup for ocamlformat. I might still tweak the
settings in the future.
Diffstat (limited to 'lib/day01.ml')
| -rw-r--r-- | lib/day01.ml | 12 |
1 files changed, 5 insertions, 7 deletions
diff --git a/lib/day01.ml b/lib/day01.ml index 9a983a6..097ad28 100644 --- a/lib/day01.ml +++ b/lib/day01.ml @@ -5,10 +5,10 @@ *) let parse_rotation s = - let num = lazy (int_of_string (String.sub s 1 ((String.length s) - 1))) in + let num = lazy (int_of_string (String.sub s 1 (String.length s - 1))) in match s.[0] with | 'R' -> Lazy.force num - | 'L' -> -(Lazy.force num) + | 'L' -> -Lazy.force num | s -> failwith (Printf.sprintf "Unknown rotation %c" s) let parse_rotations ch = @@ -25,8 +25,7 @@ let part1 ch = (fun (a, p) r -> let nxt = (p + r) mod m in let inc = if nxt = 0 then 1 else 0 in - (a + inc, nxt) - ) + (a + inc, nxt)) (0, s) |> fst |> Printf.printf "%d\n" @@ -38,10 +37,9 @@ let part2 ch = |> List.fold_left (fun (a, p) r -> let nxt = p + r in - let inc = (abs nxt) / m + if p > 0 && nxt <= 0 then 1 else 0 in + let inc = (abs nxt / m) + if p > 0 && nxt <= 0 then 1 else 0 in let nxt = ((nxt mod m) + m) mod m in - (a + inc, nxt) - ) + (a + inc, nxt)) (0, s) |> fst |> Printf.printf "%d\n" |
