Skip to content

Commit

Permalink
Extract rotate
Browse files Browse the repository at this point in the history
  • Loading branch information
drewolson committed Dec 14, 2023
1 parent af24dc0 commit 964e7fc
Showing 1 changed file with 3 additions and 8 deletions.
11 changes: 3 additions & 8 deletions lib/year2023/day14.ml
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,8 @@ module Key = struct
type t = char list list [@@deriving sexp, compare, hash]
end

let parse input =
input
|> String.split_lines
|> List.map ~f:String.to_list
|> List.transpose_exn
|> List.map ~f:List.rev
;;
let rotate grid = grid |> List.transpose_exn |> List.map ~f:List.rev
let parse input = input |> String.split_lines |> List.map ~f:String.to_list |> rotate

let shift_rocks l =
let aux (rocks, l) = function
Expand All @@ -29,7 +24,7 @@ let load grid =

let cycle grid =
List.fold (List.range 0 4) ~init:grid ~f:(fun acc _ ->
acc |> List.map ~f:shift_rocks |> List.transpose_exn |> List.map ~f:List.rev)
acc |> List.map ~f:shift_rocks |> rotate)
;;

let run_cycles n grid =
Expand Down

0 comments on commit 964e7fc

Please sign in to comment.