summary refs log tree commit diff stats
path: root/day6.fsx
diff options
context:
space:
mode:
authorBrian Chu <brianmchu42@gmail.com>2022-01-04 22:14:05 -0800
committerBrian Chu <brianmchu42@gmail.com>2022-01-04 22:14:05 -0800
commit102086e040577a4f6b3e7d97e442ee32e12f3e27 (patch)
treec88f097b0a798bc9e1cd4ed09684216ac0f0946d /day6.fsx
downloadAdventOfCode2016-102086e040577a4f6b3e7d97e442ee32e12f3e27.tar.gz
solutions to day 8
Diffstat (limited to 'day6.fsx')
-rw-r--r--day6.fsx18
1 files changed, 18 insertions, 0 deletions
diff --git a/day6.fsx b/day6.fsx
new file mode 100644
index 0000000..251dba1
--- /dev/null
+++ b/day6.fsx
@@ -0,0 +1,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"
\ No newline at end of file