Add 2017 solutions
This commit is contained in:
parent
8146a794a3
commit
6f9b51146c
11 changed files with 2285 additions and 0 deletions
|
@ -0,0 +1,23 @@
|
|||
//: [Previous](@previous)
|
||||
|
||||
import Foundation
|
||||
|
||||
func shell(_ value: Int) -> Int {
|
||||
return Int(ceil((sqrt(Double(value)) - 1) / 2))
|
||||
}
|
||||
|
||||
func biggestValue(_ shell: Int) -> Int {
|
||||
return (2 * shell + 1) * (2 * shell + 1)
|
||||
}
|
||||
|
||||
let value = 16
|
||||
|
||||
let s = shell(value)
|
||||
|
||||
let shellStart = biggestValue(s - 1) + 1
|
||||
|
||||
let shellPosition = value - shellStart
|
||||
|
||||
(Float(shellPosition) / 2 + 1) / 2
|
||||
|
||||
//: [Next](@next)
|
Loading…
Add table
Add a link
Reference in a new issue