Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
35
Task/Fibonacci-sequence/Kabap/fibonacci-sequence.kabap
Normal file
35
Task/Fibonacci-sequence/Kabap/fibonacci-sequence.kabap
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
// Calculate the $n'th Fibonacci number
|
||||
|
||||
// Set this to how many in the sequence to generate
|
||||
$n = 10;
|
||||
|
||||
// These are what hold the current calculation
|
||||
$a = 0;
|
||||
$b = 1;
|
||||
|
||||
// This holds the complete sequence that is generated
|
||||
$sequence = "";
|
||||
|
||||
// Prepare a loop
|
||||
$i = 0;
|
||||
:calcnextnumber;
|
||||
$i = $i++;
|
||||
|
||||
// Do the calculation for this loop iteration
|
||||
$b = $a + $b;
|
||||
$a = $b - $a;
|
||||
|
||||
// Add the result to the sequence
|
||||
$sequence = $sequence << $a;
|
||||
|
||||
// Make the loop run a fixed number of times
|
||||
if $i < $n; {
|
||||
$sequence = $sequence << ", ";
|
||||
goto calcnextnumber;
|
||||
}
|
||||
|
||||
// Use the loop counter as the placeholder
|
||||
$i--;
|
||||
|
||||
// Return the sequence
|
||||
return = "Fibonacci number " << $i << " is " << $a << " (" << $sequence << ")";
|
||||
Loading…
Add table
Add a link
Reference in a new issue