diff --git a/2017/README.md b/2017/README.md index d81b0db..dc0209c 100644 --- a/2017/README.md +++ b/2017/README.md @@ -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. diff --git a/2017/day-17/.gitignore b/2017/day-17/.gitignore new file mode 100644 index 0000000..a4bd26d --- /dev/null +++ b/2017/day-17/.gitignore @@ -0,0 +1 @@ +solution diff --git a/2017/day-17/solution.swift b/2017/day-17/solution.swift new file mode 100644 index 0000000..434a58f --- /dev/null +++ b/2017/day-17/solution.swift @@ -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)