Skip to content

Instantly share code, notes, and snippets.

@stulevine
Last active February 25, 2017 13:24
Show Gist options
  • Save stulevine/ed9c1096f7038935ab107f22a0babee6 to your computer and use it in GitHub Desktop.
Save stulevine/ed9c1096f7038935ab107f22a0babee6 to your computer and use it in GitHub Desktop.
//: Playground - noun: a place where people can play
import UIKit
var hits = [Int: Bool]()
func collatz(_ n: Int) {
if n == 1 { return }
var new: Int!
if (n % 2) == 0 {
new = n / 2
}
else {
new = 3*n + 1
}
if hits[n] == nil {
hits[n] = true
print("\(n)")
}
collatz(new)
}
collatz(2357693)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment