After preparing for years, you go to the 51st Intergalactic Coding Olympiad. The moment the test starts, you flip over the question paper. To your surprise, it has only one question which involves... none of the programming languages that you studied.
The question describes a programming language called Easy, which can only do five things.
- It can set a variable to 0, creating it if it doesn't exist.
- It can increment a variable if the variable already exists.
- It can create a (possibly infinite) loop containing any set of instructions. Loops can be nested.
- It can break out of a loop if two specified variables are equal. When this type of statement is used nested loops, it only breaks the innermost loop.
- It can return a variable and stop the program.
The syntax is very similar to Java syntax. Each one of the above instructions counts as 1 instruction.
Here's an example Easy program (with 7 instructions) that returns 1, illustrating the syntax:
i = 0;
j = 0;
i++;
loop {
j++;
if (i == j) break;
}
return j;
The question has three parts:
a) Write a program with at most 15 instructions that returns an integer greater than 20.
b) Write a program with at most 20 instructions that returns an integer greater than 1000.
c) Write a program with at most 25 instructions that returns an integer with a decimal representation that cannot fit in this universe.
Bonus: What is the largest number you can return on each part?
Note: The bonus question is well-defined and has a unique answer for each of the 3 cases (15, 20, 25 instructions). For details, see answer by will.octagon.gibson.
Note: Since some tame-looking Easy programs can return HUGE numbers, Easy is not run by directly running the code, but rather by scanning the code with a superintelligent coding AI and making it compute the value that is returned by figuring out what each code segment does.