Skip to content

Instantly share code, notes, and snippets.

@Szer
Created December 1, 2023 11:46
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/2ae901d15105e2693cd0cddcc4619070 to your computer and use it in GitHub Desktop.
Save Szer/2ae901d15105e2693cd0cddcc4619070 to your computer and use it in GitHub Desktop.
Advent of Code 2023 1-1
// https://adventofcode.com/2023/day/1
open System.Text.RegularExpressions
let firstDigitRegex = Regex("[0-9]")
let lastDigitRegex = Regex("[0-9]", RegexOptions.RightToLeft)
let sumOfCalibrationValues =
Seq.fold (fun acc (line: string) ->
let first = firstDigitRegex.Match(line).Value |> int
let last = lastDigitRegex.Match(line).Value |> int
acc + 10*first + last
) 0
["1abc2"
"pqr3stu8vwx"
"a1b2c3d4e5f"
"treb7uchet" ]
|> sumOfCalibrationValues
|> System.Console.WriteLine // 142
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment