Fibonacci numbers in Chef
This example uses iterative calculation of Fibonacci numbers. Last and one-before-last calculated numbers are stored in ingredients fib1
and fib2
, respectively. In one iteration of loop chop ... until choped
the next number is calculated, and the previous one is written to the stack for being printed later. Second loop mash ... until mashed
pours the values from first bowl into second one, so that they can be printed in correct (increasing) order.
This version of the interpreter doesn’t allow to hold liquid and dry ingredients on one stack, and thus disallows printing both numbers and characters in one message. This punctuation has been dropped from the output; the result looks as follows:
1 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987
Fibonacci numbers.
This recipe calculates and prints first Fibonacci numbers.
Ingredients.
0 g fib1
1 g fib2
16 g iterator
16 g second iterator
Method.
Chop iterator.
Put fib2 into 1st mixing bowl.
Put fib2 into 1st mixing bowl.
Add fib1 into 1st mixing bowl.
Fold fib2 into 1st mixing bowl.
Fold fib1 into 1st mixing bowl.
Put fib1 into 1st mixing bowl.
Chop iterator until choped.
Mash second iterator.
Fold fib1 into 1st mixing bowl.
Put fib1 into 2nd mixing bowl.
Mash second iterator until mashed.
Pour contents of 2nd mixing bowl into the baking dish.
Serves 1.
Comments
]]>blog comments powered by Disqus
]]>