summary refs log blame commit diff stats
path: root/day6.fsx
blob: 251dba148c24c8827bb69b4065ae17194f397323 (plain) (tree)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18

















                                                                                                       
open System.IO

let lines = File.ReadLines "day6.txt" |> Seq.toArray |> Array.map (fun x -> x.ToCharArray()) |> array2D
let rows, cols = Array2D.length1 lines, Array2D.length2 lines

let chars (reversed:bool) = seq { for i = 0 to cols - 1 do
                                    let col = lines[*, i]
                                    yield col  
                                    |> Seq.countBy id 
                                    |> Seq.sortBy (snd) 
                                    |> if reversed then Seq.last else Seq.head 
                                    |> fst
                                    |> string }

// part 1
chars true |> String.concat "" |> printfn "%s"
// part 2
chars false |> String.concat "" |> printfn "%s"