summary refs log blame commit diff stats
path: root/day3.fsx
blob: ef1a0d9d24eb9568878c650a1ac686fb2feebbd8 (plain) (tree)



















                                                                                                                                  
open System.IO

let lengths = [for line in File.ReadLines "day3.txt" do yield line.Split " " |> Seq.filter ((<>) "") |> Seq.map int |> Seq.toList]
let isTriangle (sides: list<int>): bool =
    let sorted = Seq.sort sides |> Seq.toArray
    sorted[0] + sorted[1] > sorted[2]

// part 1
let triangles = Seq.filter isTriangle lengths
Seq.length triangles |> printfn "%d"

// part 2
let colLengths = seq {
    for row in 0..3..(Seq.length lengths - 1) do
        for col in 0..2 do
            yield [lengths[row][col];lengths[row+1][col]; lengths[row+2][col]]
}

let colTriangles = Seq.filter isTriangle colLengths
Seq.length colTriangles |> printfn "%d"