-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathday08_part02.fs
31 lines (25 loc) · 932 Bytes
/
day08_part02.fs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
module day08_part02
open System.IO
let filepath = __SOURCE_DIRECTORY__ + @"../../day08_input.txt"
//let filepath = __SOURCE_DIRECTORY__ + @"../../test_input.txt"
let width = 25
let height = 6
let values = File.ReadAllText(filepath).ToCharArray() |> Array.map string |> Array.map int
let chunkSize = width * height
let layers = values |> Array.chunkBySize(chunkSize)
let findFirstColorValue(position: int) =
let layersValues = layers |> Array.map (fun x -> x.[position])
layersValues |> Array.find (fun v -> v <> 2)
let result =
let colors = seq {
for idx in [|0..chunkSize - 1|] do
match (findFirstColorValue idx) with
| 0 -> yield ' '
| _ -> yield char 35
}
colors |> Seq.toList
let execute =
for jdx in [|0..result.Length|] do
match jdx % width with
| 0 -> printf "%s" System.Environment.NewLine
| _ -> printf "%c" result.[jdx]