RosettaCodeData/Task/Fusc-sequence/Dyalect/fusc-sequence.dyalect

47 lines
939 B
Plaintext

let n = 61
let l = [0, 1]
func fusc(n) {
return l[n] when n < l.Length()
let f = (n &&& 1) == 0 ? l[n >>> 1] : l[(n - 1) >>> 1] + l[(n + 1) >>> 1]
l.Add(f)
return f
}
var lst = true
var w = -1
var c = 0
var t = nil
var res = ""
print("First \(n) numbers in the fusc sequence:")
for i in 0..Integer.Max {
let f = fusc(i)
if lst {
if i < 61 {
print("\(f) ", terminator: "")
} else {
lst = false
print("")
print("Points in the sequence where an item has more digits than any previous items:")
print("Index/Value:")
print(res)
res = ""
}
}
t = f.ToString().Length()
if t > w {
w = t
res += (res == "" ? "" : "\n") + "\(i)/\(f)"
if !lst {
print(res)
res = ""
}
c += 1
if c > 5 {
break
}
}
}
l.Clear()