Skip to content

Instantly share code, notes, and snippets.

@Szer
Last active December 1, 2023 12:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Szer/e6a5c1c8abeb18c9e1be0f043b7d3ad9 to your computer and use it in GitHub Desktop.
Save Szer/e6a5c1c8abeb18c9e1be0f043b7d3ad9 to your computer and use it in GitHub Desktop.
Advent of Code 2023 1-2
let realFirstDigitRegex = Regex("one|two|three|four|five|six|seven|eight|nine|[0-9]")
let realLastDigitRegex = Regex("one|two|three|four|five|six|seven|eight|nine|[0-9]", RegexOptions.RightToLeft)
let matchToInt = function
| "one" -> 1
| "two" -> 2
| "three" -> 3
| "four" -> 4
| "five" -> 5
| "six" -> 6
| "seven" -> 7
| "eight" -> 8
| "nine" -> 9
| x -> int x
let realSumOfCalibrationValues =
Seq.fold (fun acc (line: string) ->
let first = realFirstDigitRegex.Match(line).Value |> matchToInt
let last = realLastDigitRegex.Match(line).Value |> matchToInt
acc + 10*first + last
) 0
["three1abc2"
"pqr3stu8vfourwx"
"a1b2c3d4e5f"
"treb7uche0t" ]
|> realSumOfCalibrationValues
|> System.Console.WriteLine // 151
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment