Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- module December3
- open System
- open System.IO
- let parseLine (line: string) =
- let numbers =
- line.Split([|' '|], StringSplitOptions.RemoveEmptyEntries)
- |> Seq.map Int32.Parse
- |> Seq.take 3
- |> List.ofSeq
- match numbers with
- | [a; b; c] -> Some(a, b, c)
- | _ -> None
- let getInput () =
- File.ReadAllLines("input3.txt")
- |> Seq.choose parseLine
- let concat (a, b, c) = Seq.concat [a; b; c]
- let collectColumns (_as, _bs, _cs) (a, b, c) =
- (a :: _as, b :: _bs, c :: _cs)
- let getInput2() =
- File.ReadAllLines("input3.txt")
- |> Seq.choose parseLine
- |> Seq.fold collectColumns ([], [], [])
- |> concat
- |> List.ofSeq
- let isTriangle (a, b, c) =
- a + b > c && a + c > b && b + c > a
- let getResult () =
- getInput()
- |> Seq.where isTriangle
- |> Seq.length
- let rec calculateResult2 sideLengths acc =
- match sideLengths with
- | a :: b :: c :: rest ->
- calculateResult2
- rest
- acc + (if isTriangle (a, b, c) then 1 else 0)
- | _ -> acc
- let getResult2() =
- calculateResult2 (getInput2()) 0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement