AoC/2017/Advent1.playground/Pages/Day 3 - 1 Spiral.xcplaygroundpage/Contents.swift

24 lines
398 B
Swift
Raw Permalink Normal View History

2022-11-23 16:46:31 +01:00
//: [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)