diff options
Diffstat (limited to 'solutions/day3.fs')
-rw-r--r-- | solutions/day3.fs | 48 |
1 files changed, 23 insertions, 25 deletions
diff --git a/solutions/day3.fs b/solutions/day3.fs index cebfde5..541a0b4 100644 --- a/solutions/day3.fs +++ b/solutions/day3.fs @@ -1,26 +1,24 @@ -namespace Solutions +module Solutions.Day3 +open System.IO -module Day3 = - open System.IO - - let lines = File.ReadLines("inputs/day3.txt") - let rucksacks = lines - |> Seq.map (fun x -> (Set.ofSeq x[0..x.Length / 2 - 1], Set.ofSeq x[x.Length/2..x.Length])) - let groups = lines - |> Seq.map Set.ofSeq - |> Seq.splitInto (Seq.length lines / 3) - - let prioritize ch = - match ch with - | x when 'a' <= x && x <= 'z' -> int x - int 'a' + 1 - | x when 'A' <= x && x <= 'Z' -> int x - int 'A' + 27 - | _ -> 0 - - // extract the single element from the set with maxElement - let part1 () = rucksacks - |> Seq.map ((fun (x, y) -> Set.intersect x y |> Set.maxElement) >> prioritize) - |> Seq.sum - - let part2 () = groups - |> Seq.map (Set.intersectMany >> Set.maxElement >> prioritize) - |> Seq.sum \ No newline at end of file +let lines = File.ReadLines("inputs/day3.txt") +let rucksacks = lines + |> Seq.map (fun x -> (Set.ofSeq x[0..x.Length / 2 - 1], Set.ofSeq x[x.Length/2..x.Length])) +let groups = lines + |> Seq.map Set.ofSeq + |> Seq.splitInto (Seq.length lines / 3) + +let prioritize ch = + match ch with + | x when 'a' <= x && x <= 'z' -> int x - int 'a' + 1 + | x when 'A' <= x && x <= 'Z' -> int x - int 'A' + 27 + | _ -> 0 + +// extract the single element from the set with maxElement +let part1 () = rucksacks + |> Seq.map ((fun (x, y) -> Set.intersect x y |> Set.maxElement) >> prioritize) + |> Seq.sum + +let part2 () = groups + |> Seq.map (Set.intersectMany >> Set.maxElement >> prioritize) + |> Seq.sum \ No newline at end of file |