Last active
December 2, 2025 07:40
-
-
Save object/beb359ac234e6fec477c1e1aba4664cd to your computer and use it in GitHub Desktop.
AdventOfCode2025.Day01.fsx
This file contains hidden or 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
| #time "on" | |
| open System | |
| open System.IO | |
| let input = | |
| File.ReadAllLines(__SOURCE_DIRECTORY__ + "/../data/input01.txt") | |
| |> Seq.toList | |
| // Part One | |
| input | |
| |> List.fold (fun (sum, count) cmd -> | |
| let steps = Int32.Parse (cmd.Substring 1) | |
| let sum = if cmd[0] = 'R' then sum + steps else sum - steps | |
| let count = if sum % 100 = 0 then count+1 else count | |
| sum % 100, count) (50, 0) | |
| // Part Two | |
| input | |
| |> List.fold (fun (sum, count) cmd -> | |
| let steps = Int32.Parse (cmd.Substring 1) | |
| let new_sum = ((if cmd[0] = 'R' then sum + steps else sum - steps) % 100 + 100) % 100 | |
| let count = | |
| (if cmd[0] = 'R' && new_sum < sum || cmd[0] = 'L' && (sum <> 0 && new_sum > sum || new_sum = 0) | |
| then count + 1 | |
| else | |
| count) | |
| + steps / 100 | |
| new_sum, count) (50, 0) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment