-
Notifications
You must be signed in to change notification settings - Fork 0
/
day03_part01.fs
36 lines (32 loc) · 1.04 KB
/
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
28
29
30
31
32
33
34
35
36
module day03_part01
open AdventOfCode_2024.Modules
open System.Text.RegularExpressions
let parsecontent(lines: string array) =
let parts =
lines
|> Array.map(fun line ->
let regex = @"mul\(\d+,\d+\)"
let matches = Regex.Matches(line, regex)
match matches.Count with
| 0 -> [(0,0)]
| _ ->
let elems =
seq {
for m in matches do
let tosplit = m.Value.Replace("mul(", "").Replace(")", "")
yield ((int)(tosplit.Split(",")[0]), (int)(tosplit.Split(",")[1]))
}
elems |> List.ofSeq
)
parts |> List.ofArray
let calculateLine(part: (int*int) list) =
part
|> List.map(fun (a, b) -> a*b)
|> List.reduce (+)
let execute() =
let path = "day03/day03_input.txt"
let content = LocalHelper.GetLinesFromFile path
let elements = parsecontent content
elements
|> List.map calculateLine
|> List.sum