Add tasks for all the new languages

This commit is contained in:
Tina Müller 2016-12-05 23:44:36 +01:00
parent 9dc3c2bb62
commit bba7bfd280
13208 changed files with 134745 additions and 0 deletions

View file

@ -0,0 +1,34 @@
func hailstone(var n:Int) -> [Int] {
var arr = [n]
while n != 1 {
if n % 2 == 0 {
n /= 2
} else {
n = (3 * n) + 1
}
arr.append(n)
}
return arr
}
let n = hailstone(27)
println("hailstone(27): \(n[0...3]) ... \(n[n.count-4...n.count-1]) for a count of \(n.count).")
var longest = (n: 1, len: 1)
for i in 1...100_000 {
let new = hailstone(i)
if new.count > longest.len {
longest = (i, new.count)
}
}
println("Longest sequence for numbers under 100,000 is with \(longest.n). Which has \(longest.len) items.")