A higher resolution is required to access the IDE
- 97
Learning Opportunities
This puzzle can be solved using the following concepts. Practice using these concepts and improve your skills.
Statement
The Goal
You will be given an integer and have to decide whether it is a prime number or not.
But beware, you have to write your program in a slightly modified version of CG Funge (description below).
This is an optimization problem, your program should use as few execution steps as possible to find the correct answer.
But beware, you have to write your program in a slightly modified version of CG Funge (description below).
This is an optimization problem, your program should use as few execution steps as possible to find the correct answer.
Rules
CGFunge is a 2-dimensional, positional programming language. This means that execution of a CGFunge program follows a designated pattern on a grid of ASCII characters. Execution always starts on the first character of the first line and proceeds to the right. Each command in the language is a single character. The commands
are as follow:
Any other character will simply be ignored.
Command | Effect |
---|---|
| Continue to the right |
| Continue to the left |
| Continue up |
| Continue down |
| Skip the next character and continue with the subsequent character |
| End the program immediately |
| Push a number onto the stack |
| Add the first two numbers of the stack (e.g. |
| Subtract the first two numbers of the stack (e.g. |
| Multiply the first two numbers of the stack (e.g. |
| Divide the first two numbers of the stack (e.g. |
| Pop the top of the stack |
| Removes the top value of the stack and takes it as an index. Then removes the value at the index from the stack and push it on top (e.g.: |
| Push a duplicate of the top value onto the stack |
| Pop the top value of the stack. If it is negative, turn left. If it is positive, turn right. If it is |
| Pop the top integer from the stack and print it |
| Pop the top integer from the stack and print it as a character (using the ASCII code) |
| Toggle string mode. In string mode, every character will push the corresponding ASCII value on the stack |
Any other character will simply be ignored.
Game Input
Initially the program will hold one single value N on the stack: the number which shall be tested for being prime.
Output
A single line saying PRIME or NOT PRIME
To submit your solution, write a program in any language that prints CGFunge code to stdout. The first line of output should be the lineCount. The next lineCount lines should be the actual program.
It is recommended to code in PHP, then you can write CGFunge code directly (you have to delete<?php as well).
To submit your solution, write a program in any language that prints CGFunge code to stdout. The first line of output should be the lineCount. The next lineCount lines should be the actual program.
It is recommended to code in PHP, then you can write CGFunge code directly (you have to delete
Constraints
lineCount ≤
lineLength ≤
maximum number of turns ≤
A higher resolution is required to access the IDE