One day, at school, I overheard some people talking about math homework, and getting problems wrong on said homework. One of them suggested that the number they got as an answer was actually a variable that stood for the correct answer... which gave me an idea.
Statements are entered one-per-line. Each statement consists of some expression (described below). Some expressions are special:
-1at compile time end a loop.
42will cause the current answer to be displayed. The answer is always
9(or the value of the variable
-42will prompt the user for input. User input is stored in the variable
In order of precedence:
:), it will be replaced with its value. The replacement only happens once, when the number is directly in the code (i.e., not a result of an expression); for example, if the variable
5has the value
6and the variable
6has the value
5will give the value
7; likewise, typing
2+3will give the value
Ø(uppercase O with slash) respectively give pi, infinity, and not-a-number.
∅(empty set) for
Ø, and τ for 2π.
6. If the variable has not been assigned, the brackets don't do anything.
-2negates the value of the variable
2, rather than finding the value of the variable
1is used instead. If the prefix form of
/is used after an operator of equal or higher precedence, the result is undefined.
1for true and
|is only evaluated if necessary.
:operator is a number or a bracketed expression, one less level of indirection is used than normal. Reassigning
1will change how math works; assigning
1to the same value is not recommended.
Any character not mentioned above (including all letters, apostrophe, and comma) is treated as whitespace.
Programs written in Brainf*** can be translated into 42 as follows:
|(start of the program)|
This has cell sizes up to the largest integer that can be stored in a double-precision floating-point number, memory up to the largest number ending in .5 that can be stored, and memory only extends to the right (to make memory extend to the left, copy the code at the end of > to <; this code is needed to initialize the memory to 0). Variable 10 stores the current position in memory; the actual memory values are at n.5 for integers n.
Old Java version: Applet, Download (125 KB), Download source (19 KB) (downloads also include Try and CLWPA)