Skip to content

Instantly share code, notes, and snippets.

@object
Created December 2, 2025 07:40
Show Gist options
  • Select an option

  • Save object/8455c8153561f876f8a1b1d3bfc3ba1a to your computer and use it in GitHub Desktop.

Select an option

Save object/8455c8153561f876f8a1b1d3bfc3ba1a to your computer and use it in GitHub Desktop.
AdventOfCode2025.Day02.fsx
#time "on"
open System
open System.IO
let input =
File.ReadAllText(__SOURCE_DIRECTORY__ + "/../data/input02.txt")
let ranges =
input.Split(',')
|> Seq.map(fun x -> x.Split('-') |> Seq.map int64 |> Seq.toList |> fun x -> x[0], x[1])
|> Seq.toList
// Part One (28844599675)
let rec findDuplicates1 (start: int64) (stop: int64) result =
if start > stop then
result
else
let s = start.ToString()
let result =
if s.Length % 2 = 0 && s.Substring(0, s.Length/2) = s.Substring(s.Length/2) then
s :: result
else
result
findDuplicates1 (start+1L) stop result
ranges
|> List.fold (fun result range ->
let start, stop = range
findDuplicates1 start stop result) []
|> List.map int64
|> List.sum
// Part Two (4174379265)
let hasN (s: string) n =
let rec areDuplicates ndx result =
if (ndx+1) * n = s.Length then
true
else
if s.Substring(0, n) = s.Substring((ndx+1) * n, n) then
areDuplicates (ndx+1) result
else
false
s.Length % n = 0 && s.Length > n && areDuplicates 0 true
let rec findDuplicates2 (start: int64) (stop: int64) result =
if start > stop then
result
else
let s = start.ToString()
let result =
if [1..10] |> List.fold (fun result n -> result || hasN s n) false then
s :: result
else
result
findDuplicates2 (start+1L) stop result
ranges
|> List.fold (fun result (start, stop) ->
findDuplicates2 start stop result) []
|> List.map int64
|> List.sum
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment