module advent_of_code.tasks.day_3.Star2 open System.IO let stream = new StreamReader("tasks/day-3/input.txt") let rec getJoltage (line: string) (count: int) = let firstDigit = List.max(Seq.toList(line[0 .. line.Length - (count)])) let firstDigitPos = line.IndexOf firstDigit if count = 1 then $"{firstDigit}" |> int64 else $"{firstDigit}{getJoltage line[firstDigitPos + 1 ..] (count - 1) }" |> int64 let rec mainLoop (lines: string list) = let line, tail = lines.Head, lines.Tail let joltage = getJoltage line 12 if (tail.IsEmpty) then joltage else joltage + mainLoop tail let rec main = let lines = stream.ReadToEnd().Split("\n") |> Array.toList mainLoop lines