This commit is contained in:
2024-12-22 10:09:34 -08:00
parent 4c2c6244db
commit 83979ce5d2
3 changed files with 1548 additions and 0 deletions

18
day22/d22p1.swift Normal file
View File

@@ -0,0 +1,18 @@
import Foundation
func readInput(_ filePath: String) throws -> [Int] {
return try String(contentsOfFile: filePath, encoding: .ascii)
.split(separator: "\n").compactMap { Int($0) }
}
func rand(seed: Int, n: Int) -> Int {
return (0..<n).reduce(seed) { prev, _ in
var res = ((prev << 6) ^ prev) & 0b111111111111111111111111
res = ((res >> 5) ^ res)
return ((res << 11) ^ res) & 0b111111111111111111111111
}
}
let seeds = try readInput(CommandLine.arguments[1])
print(seeds.map { rand(seed: $0, n: 2000) }.reduce(0, +))

1526
day22/input.txt Normal file

File diff suppressed because it is too large Load Diff

4
day22/test.txt Normal file
View File

@@ -0,0 +1,4 @@
1
10
100
2024