Chaos Chef

Posted by Mariia Mykhailova on January 22, 2012

Today we participated in a nice contest named Chaos. It required solving problems in a language announced only minutes before the start of the contest - a concept similar to Unknown Language Rounds at Codeforces. Today the language turned out to be Chef, which I know quite well, so it took only one hour to solve all 6 problems and win.

Here are the solutions to the problems.

Problem 1. Write a program ("recipe") which prints the given message.

This task requires only as much knowledge of the language as "Hello World" does, but quite some code. In fact, our solution to this problem is twice as long as the next longest one - over 1k characters :-) Luckily, some time ago I wrote a program which generated Chef programs to output given messages, so I just used it and voila - we're on the fifth place in the scoreboard (serves me well for getting 15 minutes late for the contest).

Fruit sauce.

This recipe encodes a message in Chef language. Don't try to actually cook it - the results can be unpredictable!

Ingredients.
33 g pear
115 g tamarind
111 g velvet apple
97 g lychee
104 g longan
67 g peach
32 g strawberry
111 g canistel
116 g raspberry
32 g rambutan
101 g orange
109 g breadfruit
111 g durian
99 g jackfruit
108 g gooseberry
101 g plum
87 g roselle

Method.
Put pear into the mixing bowl.
Put tamarind into the mixing bowl.
Put velvet apple into the mixing bowl.
Put lychee into the mixing bowl.
Put longan into the mixing bowl.
Put peach into the mixing bowl.
Put strawberry into the mixing bowl.
Put canistel into the mixing bowl.
Put raspberry into the mixing bowl.
Put rambutan into the mixing bowl.
Put orange into the mixing bowl.
Put breadfruit into the mixing bowl.
Put durian into the mixing bowl.
Put jackfruit into the mixing bowl.
Put gooseberry into the mixing bowl.
Put plum into the mixing bowl.
Put roselle into the mixing bowl.
Liquify contents of the mixing bowl.
Pour contents of the mixing bowl into the baking dish.

Serves 1.

Problem 2. Multiply two numbers.

This problem required nothing more complicated than numeric input ("take from refrigerator") and multiplication ("combine"), and it brought us to the top position in the ranklist which we occupied till the very end of the contest.

Multiplication sauce.

This recipe multiplies two numbers in Chef language. Don't try to actually cook it - the results can be unpredictable!

Ingredients.
1 pear
1 peach

Method.
Take pear from refrigerator.
Take peach from refrigerator.
Put pear into the mixing bowl.
Combine peach into the mixing bowl.
Pour contents of the mixing bowl into the baking dish.

Serves 1.

Problem 3. Sum N given numbers.

This problem required a loop, which be default runs downward from N to 0 in Chef.

Sum of Numbers as a Piece of Cake.

This recipe sums N given numbers.

Ingredients.
1 N
0 sum
1 number

Method.
Put sum into the mixing bowl.
Take N from refrigerator.
Chop N.
Take number from refrigerator.
Add number into the mixing bowl.
Chop N until choped.
Pour contents of the mixing bowl into the baking dish.

Serves 1.

Problem 4. Print a triangle of asterisks of given size.

A double-loop which required some care about the order of printing asterisks and newline characters - they are printed in reverse order compared to the order they are put in the mixing bowl, so the order of pushing was "newline - N asterisks - newline - N-1 asterisks - ... - 1 asterisk.". Took me several attempts to get the order right, so I used the interpreter locally to avoid crowding the submission queue.

Asterisks Cake.

This recipe prints a triangle of asterisks.

Ingredients.
1 N
1 i
1 j
42 ml asterisk
10 ml newline
1 one

Method.
Take N from refrigerator.
Put N into the mixing bowl.
Fold i into the mixing bowl.
Put N into the mixing bowl.
Add one into the mixing bowl.
Fold N into the mixing bowl.
Chop i.
Put i into the mixing bowl.
Fold j into the mixing bowl.
Put newline into the mixing bowl.
Mash j.
Put asterisk into the mixing bowl.
Mash j until mashed.
Chop i until choped.
Pour contents of the mixing bowl into the baking dish.

Serves 1.

Problem 5. Figure out the problem statement from two sample inputs and outputs and code it.

Sample Input #1:
3
2
4
6
9

Sample Output #1:
11
8
6


Sample Input #2:
4
5
123
32
45
76

Sample Output #2:
81
50
37
128

Oh, this was a fun one, thanks to the problemsetters :-) It took me more than one glance to figure out that the first number N was the quantity of lines in the output, and the second number had to be added to each of the N following numbers, which than had to be printed in reverse order. The only pitfall after guessing this was that this problem required mixing the output - numeric and character values. To do this, the variable holding newline value had to be declared as liquid (for example, measured in ml).

Mystery souffle.

This recipe does this mysterious task.

Ingredients.
1 N
1 adder
1 number
10 ml newline

Method.
Take N from refrigerator.
Take adder from refrigerator.
Chop N.
Put newline into the mixing bowl.
Take number from refrigerator.
Put number into the mixing bowl.
Add adder into the mixing bowl.
Chop N until choped.
Pour contents of the mixing bowl into the baking dish.

Serves 1.

Problem 6. Find the area of Vicsek Fractal of given size on given iteration.

Wikipedia article on this fractal has the formula for the area, so all we had to do was to believe that it will be integer in all test cases (remember that Chef doesn't work with floating-point numbers, only with integer ones).

Vicsek Fractal.

This recipe calculates the area of Vicsek Fractal.

Ingredients.
1 a
1 b
5 multiplier
9 divisor

Method.
Take a from refrigerator.
Take b from refrigerator.
Put a into the mixing bowl.
Combine a into the mixing bowl.
Chop b.
Combine multiplier into the mixing bowl.
Divide divisor into the mixing bowl.
Chop b until choped.
Pour contents of the mixing bowl into the baking dish.

Serves 1.

In conclusion I have to say that I really enjoyed this contest, though partly because I already knew the language. I'm looking forward to more competitions like this one!

Freelance Jobs

blog comments powered by Disqus