Advertisement
Guest User

AOC 22 D3 F#

a guest
Dec 3rd, 2022
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
F# 0.81 KB | Source Code | 0 0
  1. let splitEq (s: string) =
  2.     let a = s.[0..(s.Length/2)-1] |> Set.ofSeq
  3.     let b = s.[(s.Length/2)..] |> Set.ofSeq
  4.     Seq.ofList [a; b]
  5.  
  6. let dict =
  7.     (List.zip ['a'..'z'] [1..26]) @ (List.zip ['A'..'Z'] [27..52])
  8.     |> Map.ofList
  9.  
  10. let input = System.IO.File.ReadAllLines "input.txt"
  11.             |> Array.toList
  12.  
  13. let score = Seq.map (Seq.distinct >> Set.ofSeq)
  14.             >> Seq.map (fun x -> x |> Set.map (fun y -> dict.[y]))
  15.             >> Seq.map (fun x -> x |> Set.toList |> List.sum)
  16.             >> Seq.sum
  17.  
  18. input   |> List.map (splitEq)
  19.         |> Seq.ofList
  20.         |> Seq.map Set.intersectMany
  21.         |> score
  22.         |> printfn "Part 1: %d"
  23.  
  24. input   |> List.map (Set.ofSeq)
  25.         |> Seq.chunkBySize 3
  26.         |> Seq.map Set.intersectMany
  27.         |> score
  28.         |> printfn "Part 2: %d"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement