From d8bd75f016a6378282bf6e9cf99c8f4259d084a6 Mon Sep 17 00:00:00 2001 From: Dustin Swan Date: Thu, 3 Dec 2020 15:12:19 -0500 Subject: [PATCH] not passing around count any more --- day3.ml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/day3.ml b/day3.ml index 6496c17..307e4bf 100644 --- a/day3.ml +++ b/day3.ml @@ -29,17 +29,17 @@ let read_cell map x y = (* return Some char at these coordinates, or None if bel then Some (List.nth (List.nth map x) (wrapped_y y map)) else None -let rec go map position slope count = (* move across the map, counting trees *) +let rec go map position slope = (* move across the map, counting trees *) let (x, y) = position in let (dy, dx) = slope in (* suddenly regretting having x be the vertical axis.. *) match read_cell map x y with - | None -> count (* off the map. stop counting *) - | Some '#' -> go map (x+dx, y+dy) slope (count+1) - | Some a -> go map (x+dx, y+dy) slope count + | None -> 0 (* off the map! stop counting *) + | Some '#' -> 1 + go map (x+dx, y+dy) slope + | Some a -> go map (x+dx, y+dy) slope let map = read_file "day3.txt" |> List.map explode let slopes = [(1, 1); (3, 1); (5, 1); (7, 1); (1, 2)] -let tree_counts = slopes |> List.map (fun slope -> go map (0, 0) slope 0);; +let tree_counts = slopes |> List.map (fun slope -> go map (0, 0) slope);; List.iter (fun count -> Printf.printf "Number of trees: %i\n" count) tree_counts;;