-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProgram.fs
36 lines (26 loc) · 836 Bytes
/
Program.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
31
32
33
34
35
36
module Day25
open System.IO
let transform x subjectNumber = (x * subjectNumber) % 20201227L
let findLoopSize publicKey =
let mutable loops = 0
let mutable result = 1L
while result <> publicKey do
result <- transform result 7L
loops <- loops + 1
loops
let findEncryptionKey publicKey loopSize =
let mutable key = 1L
for _ in 1 .. loopSize do
key <- transform key publicKey
key
[<EntryPoint>]
let main argv =
let pk1, pk2 =
File.ReadLines("Input.txt")
|> Seq.map int64
|> Seq.toList
|> fun s -> s.[0], s.[1]
let ls1, ls2 = findLoopSize pk1, findLoopSize pk2
let ek1, ek2 = findEncryptionKey pk1 ls2, findEncryptionKey pk2 ls1
printfn "EncryptionKey1: %d, EncryptionKey2: %d" ek1 ek2
0