Created
December 1, 2023 11:46
-
-
Save Szer/2ae901d15105e2693cd0cddcc4619070 to your computer and use it in GitHub Desktop.
Advent of Code 2023 1-1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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