Implement day 17, in swift.

This commit is contained in:
2017-12-17 17:04:41 +01:00
parent 5b1349be9d
commit 8f59911c20
3 changed files with 27 additions and 0 deletions

1
2017/day-17/.gitignore vendored Normal file
View File

@@ -0,0 +1 @@
solution

View File

@@ -0,0 +1,25 @@
let input = Int(readLine()!)!
var index = 0
var buffer = [0];
for i in 1...2017 {
index = ((index + input) % buffer.count) + 1
buffer.insert(i, at: index)
}
print(buffer[buffer.index(of: 2017)! + 1])
var last = 0
index = 0
for i in 1...50000000 {
index = ((index + input) % i) + 1
if index == 1 {
last = i
}
}
print(last)