X-Git-Url: https://git.xandkar.net/?a=blobdiff_plain;f=polymorphism%2F001%2Fsrc%2Fpolymorphism.ml;h=0444595e7d2043888875e90a1709f9c25c543c37;hb=47c9d6963d399bc3fac7d39616cf26066311cc29;hp=62730e4457959cf013f49f52427f9952d252f10c;hpb=77d0f9e1ea0f4e1ea131c0bde987ea25ad57d023;p=cellular-automata.git diff --git a/polymorphism/001/src/polymorphism.ml b/polymorphism/001/src/polymorphism.ml index 62730e4..0444595 100644 --- a/polymorphism/001/src/polymorphism.ml +++ b/polymorphism/001/src/polymorphism.ml @@ -263,13 +263,14 @@ struct let create () = Random.int 2 |> State.of_int |> State.to_cell - let live_neighbors neighbors = - neighbors |> List.map ~f:(State.of_cell_state |- State.to_int) - |> List.fold_left ~init:0 ~f:(+) + let count_of_live = + List.map ~f:State.of_cell_state + |- List.map ~f:State.to_int + |- List.fold_left ~f:(+) ~init:0 let transition ~self ~neighbors = self |> State.of_cell_state - |> State.next ~live_neighbors:(live_neighbors neighbors) + |> State.next ~live_neighbors:(count_of_live neighbors) |> State.to_cell end @@ -351,15 +352,15 @@ struct let create () = Random.int 3 |> State.of_int |> State.to_cell - let burning_neighbors neighbors = - neighbors |> List.map ~f:State.of_cell_state - |> List.filter ~f:State.is_burning - |> List.map ~f:State.to_int - |> List.fold_left ~init:0 ~f:(+) + let count_of_burning = + List.map ~f:State.of_cell_state + |- List.filter ~f:State.is_burning + |- List.map ~f:State.to_int + |- List.fold_left ~f:(+) ~init:0 let transition ~self ~neighbors = self |> State.of_cell_state - |> State.next ~burning_neighbors:(burning_neighbors neighbors) + |> State.next ~burning_neighbors:(count_of_burning neighbors) |> State.to_cell end