Skip to content

Instantly share code, notes, and snippets.

@Karamell
Created December 25, 2020 06:21
Show Gist options
  • Select an option

  • Save Karamell/493a5809f2f20f2ee7637fddb1197ca2 to your computer and use it in GitHub Desktop.

Select an option

Save Karamell/493a5809f2f20f2ee7637fddb1197ca2 to your computer and use it in GitHub Desktop.
Advent of Code 2020 day 25 in F#
#time "on"
let cpk, dpk = System.IO.File.ReadLines( __SOURCE_DIRECTORY__ + "/input.txt") |> Seq.toList |> fun [a;b] -> int64 a, int64 b
let magic = 20201227L
let rec transform no sn n = seq {
yield no, n
let n' = (n * sn) % magic
yield! transform (no + 1) sn n'
}
let ndpk = transform 1 7L 7L |> Seq.find (snd >> (=) dpk)
let ncpk = transform 1 7L 7L |> Seq.find (snd >> (=) cpk)
transform 1 (snd ncpk) (snd ncpk)
|> Seq.find (fst >> (=) (fst ndpk))
|> snd
|> printfn "part 1: %d"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment