# Factorial in Chef

Example for versions Acme-Chef-1.01

This example uses iterative factorial definition. Ingredients measured in `ml` are liquid (characters), the ones measured in `g` are dry (numbers).

The program consists of two loops. First one, `chop ... until choped`, calculates the factorials in ascending order and pushes elements to be printed in the first bowl, characters and numbers alike. Smaller values which should be printed first end up at the bottom of the stack. This is cured by using the second bowl and the second loop, `mash ... until mashed`, which moves elements from the first bowl to the second one, so that they get to be printed in correct order.

Unfortunately, the current version of the interpreter processes liquid ingredients in a wrong way — neither liquid units of measurement, nor the command `luquify` modify their state, so they are printed as dry. Thus, the program output looks as follows:

`0 33 32 61 32 1 10 1 33 32 61 32 1 10 2 33 32 61 32 2 10 3 33 32 61 32 6 10 4 33 32 61 32 24 10 5 33 32 61 32 120 10 6 33 32 61 32 720 10 7 33 32 61 32 5040 10 8 33 32 61 32 40320 10 9 33 32 61 32 362880 10 10 33 32 61 32 3628800 10 11 33 32 61 32 39916800 10 12 33 32 61 32 479001600 10 13 33 32 61 32 6227020800 10 14 33 32 61 32 87178291200 10 15 33 32 61 32 1307674368000 10 16 33 32 61 32 20922789888000 10`

``````Factorial as a Piece of Cake.

This recipe calculates and prints factorials of first integers.

Ingredients.
33 ml exclamation
32 ml space
61 ml equal
10 ml newline
0 g n
1 g f
1 g one
17 g iterator
119 g second iterator

Method.
Liquify exclamation.
Liquify space.
Liquify equal.
Liquify newline.
Chop iterator.
Put n into 1st mixing bowl.
Put exclamation into 1st mixing bowl.
Put space into 1st mixing bowl.
Put equal into 1st mixing bowl.
Put space into 1st mixing bowl.
Put f into 1st mixing bowl.
Put newline into 1st mixing bowl.
Put n into 1st mixing bowl.
Add one into 1st mixing bowl.
Fold n into 1st mixing bowl.
Put f into 1st mixing bowl.
Combine n into 1st mixing bowl.
Fold f into 1st mixing bowl.
Chop iterator until choped.
Mash second iterator.
Fold n into 1st mixing bowl.
Put n 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

]]>

Top 10 users: