-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathday03_part01.fs
27 lines (22 loc) · 1002 Bytes
/
day03_part01.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
module day03_part01
open System
open System.IO
let path = "day03_input.txt"
//let path = "test_input.txt"
let inputLines = File.ReadLines(__SOURCE_DIRECTORY__ + @"../../" + path) |> Seq.map (fun x -> x.ToCharArray() |> Array.map string) |> Seq.toList
let calculateGammaRate(input: list<string[]>) =
let maxIdx = input.Head.Length - 1
let tmp = seq {
for i in 0 .. maxIdx do
let numberOfOnes = input |> List.map(fun l -> l.[i]) |> List.filter (fun e -> e = "1") |> List.length
match numberOfOnes >= (input.Length / 2) with
| true -> yield "1"
| false -> yield "0"
}
tmp |> Seq.toList
let execute =
let gammarate = calculateGammaRate(inputLines)
let gammarateValue = Convert.ToInt32(gammarate |> List.fold (+) "", 2)
let epsilonrate = gammarate |> List.map(fun x -> if x = "1" then "0" else "1")
let epsilonrateValue = Convert.ToInt32(epsilonrate |> List.fold (+) "", 2)
gammarateValue * epsilonrateValue