-
Notifications
You must be signed in to change notification settings - Fork 0
/
day09_part02.fs
26 lines (21 loc) · 887 Bytes
/
day09_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
module day09_part02
open AdventOfCode_2016.Modules
open System.Text.RegularExpressions
open System.Numerics
let rec processContent (content: string) (currentLength: bigint)=
let regex = new Regex("\((?<size>\d+)x(?<times>\d+)\)")
let found = regex.Match( content)
match found.Success with
| true ->
let endIdx = (found.Value.Length + found.Index)
let size = (int)found.Groups["size"].Value
let times = BigInteger.Parse(found.Groups["times"].Value)
currentLength + bigint(found.Index) +
times * (processContent (content.Substring(endIdx, size)) 0I) +
(processContent (content.Substring(endIdx + size)) 0I)
| false ->
bigint(content.Length)
let execute =
let path = "day09/day09_input.txt"
let content = (LocalHelper.GetContentFromFile path)
(processContent content 0I)