summaryrefslogtreecommitdiffstats
path: root/lib/day01.ml
diff options
context:
space:
mode:
Diffstat (limited to 'lib/day01.ml')
-rw-r--r--lib/day01.ml12
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"