-
Notifications
You must be signed in to change notification settings - Fork 0
/
day09_part01.fs
27 lines (24 loc) · 1.06 KB
/
day09_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 day09_part01
open AdventOfCode_2016.Modules
open System.Text.RegularExpressions
let rec processContent (content: string) (currentIdx: int) =
match currentIdx = content.Length with
| true -> content.Length
| false ->
let regex = new Regex("\((?<size>\d+)x(?<times>\d+)\)")
let found = regex.Match( content, currentIdx)
match found.Success with
| true ->
let endIdx = (found.Value.Length + found.Index)
let size = (int)found.Groups["size"].Value
let times = (int)found.Groups["times"].Value
let toRepeat = content.Substring(endIdx, size)
let repeatedContent = toRepeat |> String.replicate(times)
let newContent = content.Substring(0, found.Index) + repeatedContent + content.Substring(endIdx + size)
processContent newContent (currentIdx + size * times)
| false ->
content.Length
let execute =
let path = "day09/day09_input.txt"
let content = LocalHelper.GetContentFromFile path
processContent content 0