d22p1
This commit is contained in:
18
day22/d22p1.swift
Normal file
18
day22/d22p1.swift
Normal 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
1526
day22/input.txt
Normal file
File diff suppressed because it is too large
Load Diff
4
day22/test.txt
Normal file
4
day22/test.txt
Normal file
@@ -0,0 +1,4 @@
|
||||
1
|
||||
10
|
||||
100
|
||||
2024
|
Reference in New Issue
Block a user