-
Notifications
You must be signed in to change notification settings - Fork 10
/
Day04.fs
30 lines (24 loc) · 868 Bytes
/
Day04.fs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
module Year2015Day04
open AdventOfCode.FSharp.Common
open System.Security.Cryptography
open System.Text
let parse = parseFirstLine asString
let getHash (input : string) =
let md5Obj = MD5.Create()
let inputAsBytes = Encoding.ASCII.GetBytes input
let getHash' index =
let indexBytes = Encoding.ASCII.GetBytes (string index)
let byteArr = Array.append inputAsBytes indexBytes
md5Obj.ComputeHash byteArr
getHash'
let solvePart1 input =
Seq.initInfinite (getHash input)
|> Seq.indexed
|> Seq.find (fun (i, h) -> h.[0] = 0uy && h.[1] = 0uy && h.[2] &&& 0xF0uy = 0uy)
|> fst
let solvePart2 input =
Seq.initInfinite (getHash input)
|> Seq.indexed
|> Seq.find (fun (i, h) -> h.[0] = 0uy && h.[1] = 0uy && h.[2] = 0uy)
|> fst
let solver = { parse = parse; part1 = solvePart1; part2 = solvePart2 }