Skip to content

Instantly share code, notes, and snippets.

@cdaven
Last active December 2, 2020 07:43
Show Gist options
  • Save cdaven/e2a10a46b452817eda1715ad195446c4 to your computer and use it in GitHub Desktop.
Save cdaven/e2a10a46b452817eda1715ad195446c4 to your computer and use it in GitHub Desktop.
Advent of Code 2020, Day1 (F#)
open System
let readLines filePath = System.IO.File.ReadAllLines(filePath)
let day1 =
printfn "** Day 1 **"
// Läs in alla rader till ett set av heltal
let entries = readLines "data/1.txt" |> Set.ofArray |> Set.map Int32.Parse
// Ta fram alla "2020-kompis-par" för varje tal
let pairs = entries |> Set.map (fun i -> 2020 - i)
// Hitta det enda "par" som har båda talen i ursprungslistan och multiplicera
let product = Set.intersect entries pairs |> Seq.reduce (fun x y -> x * y)
printfn $"{product}"
[<EntryPoint>]
let main argv =
day1
0 // return an integer exit code
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment