# generate a list of Fibonacci numbers to a maximum value, show the last one, the count, and the list
{ object Fibonacci
private int fibs[] = [0, 1]
{ mode begin (ulong maxFib) # constructor
{ ulong n = fibs.lastIndex
begin
ulong fn= fibs[n] + fibs[n-1] # next Fibonacci number
until fn > maxFib
fibs[] = fn
n++
}
} # end constructor
{ method Report
ulong ndx = fibs.lastIndex, maxfn = fibs[ndx]
@ "The max Fibonacci produced is {maxfn}. The number of Fibocaccis is {fibs.count}."
string FibList = fibs.join(', ')
@ "The Fibonacci numbers are: {FibList}."
}
} # end object def
{ object @Main
{ mode begin # this constructor is the main program
@ "Fibonacci Program"
Fibonacci fibs = Fibonacci(4_000) # compute the numbers, up to the last one below 4,000
fibs.Report # result produced
signal _CON_end # all done!
}
}