mirror of
https://github.com/bertptrs/adventofcode.git
synced 2025-12-25 12:50:32 +01:00
Implement day 17, in swift.
This commit is contained in:
@@ -31,5 +31,6 @@ The current plan, in no particular order:
|
||||
- [x] Scala - [Day 11](./day-11/solution.scala)
|
||||
- [ ] Scheme
|
||||
- [ ] SQL
|
||||
- [ ] Swift - [Day 17](./day-17/solution.swift)
|
||||
|
||||
… and then I will need some more. But that will come in time.
|
||||
|
||||
1
2017/day-17/.gitignore
vendored
Normal file
1
2017/day-17/.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
||||
solution
|
||||
25
2017/day-17/solution.swift
Normal file
25
2017/day-17/solution.swift
Normal 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)
|
||||
Reference in New Issue
Block a user