open System.IO let readLines (filePath: string) = seq { use sr = new StreamReader (filePath) while not sr.EndOfStream do yield sr.ReadLine() } let getMatches (partsOfLines: string array list list) predicate = [ for lineParts in partsOfLines do let part1 = lineParts.[0] let a = part1.[0] |> int let b = part1.[1] |> int let r = lineParts.[1].[0].[0] let rest = lineParts.[2].[0] let matches = [ for i in 0..rest.Length - 1 do let c = rest.[i] if (predicate a b r c i) then yield c ] (a, b, matches.Length) ] [<EntryPoint>] let main argv = let lines = readLines "input.txt" let partsOfLines = [ for line in lines do [ for section in line.Split [| ' ' |] do section.Split [| '-'; ':' |] ] ] let part1Matches = getMatches partsOfLines (fun _ _ r c i -> c = r) let part2Matches = getMatches partsOfLines (fun a b r c i -> (i = a - 1 && c = r) || (i = b - 1 && c = r)) let part1 = part1Matches |> List.filter (fun (a: (int * int * int)) -> match a with | (a, b, count) -> count >= a && count <= b) let part2 = part2Matches |> List.filter (fun (_, _, count) -> count = 1) printf "%d %d\n" part1.Length part2.Length 0