Add tasks for all the new languages
This commit is contained in:
parent
9dc3c2bb62
commit
bba7bfd280
13208 changed files with 134745 additions and 0 deletions
45
Task/Fibonacci-sequence/Ra/fibonacci-sequence.ra
Normal file
45
Task/Fibonacci-sequence/Ra/fibonacci-sequence.ra
Normal file
|
|
@ -0,0 +1,45 @@
|
|||
class FibonacciSequence
|
||||
**Prints the nth fibonacci number**
|
||||
|
||||
on start
|
||||
|
||||
args := program arguments
|
||||
|
||||
if args empty
|
||||
print .fibonacci(8)
|
||||
|
||||
else
|
||||
|
||||
try
|
||||
print .fibonacci(integer.parse(args[0]))
|
||||
|
||||
catch FormatException
|
||||
print to Console.error made !, "Input must be an integer"
|
||||
exit program with error code
|
||||
|
||||
catch OverflowException
|
||||
print to Console.error made !, "Number too large"
|
||||
exit program with error code
|
||||
|
||||
define fibonacci(n as integer) as integer is shared
|
||||
**Returns the nth fibonacci number**
|
||||
|
||||
test
|
||||
assert fibonacci(0) = 0
|
||||
assert fibonacci(1) = 1
|
||||
assert fibonacci(2) = 1
|
||||
assert fibonacci(3) = 2
|
||||
assert fibonacci(4) = 3
|
||||
assert fibonacci(5) = 5
|
||||
assert fibonacci(6) = 8
|
||||
assert fibonacci(7) = 13
|
||||
assert fibonacci(8) = 21
|
||||
|
||||
|
||||
body
|
||||
a, b := 0, 1
|
||||
|
||||
for n
|
||||
a, b := b, a + b
|
||||
|
||||
return a
|
||||
Loading…
Add table
Add a link
Reference in a new issue