21
8
The Four fours puzzle is a popular recreational mathematical puzzle that involves using exactly four 4s (and no other number) and a defined set of operations to reach every number from 0 to a given maximum.
In this version, the only following operators are allowed:
- Any grouping symbols may be used
- Addition (
+
), Subtraction (-
), Multiplication (*
), Division (/
) - Factorial (
!
), Gamma function (Γ
) - Exponentiation (
^
), Square root (√
) - Concatenation (eg.
44
is two4
s) - Decimal point (eg.
4.4
is two4
s), Overbar (eg..4~ = 4/9
)
Standard order of operations applies.
Your program should generate, given an input between 0 and 100 inclusive, a correct solution for that input. If the program outputs an invalid solution to any input, that program is invalid.
For example, with an input of 0
, your program might generate 44-44
.
The use of external modules is not allowed. Only _.4~
is allowed for the overbar operator - that is, only one 4
can be behind the decimal point.
This is code golf, so shortest solution wins.
Edit: To be extra clear, the program must output a set of the above operations applied to exactly four 4
s - no more, no less. Also, .4 = 4/10
is a valid term, and counts as using only one 4
.
no rounding operations? :-( – John Dvorak – 2013-07-13T15:54:49.150
@JanDvorak err, no, that wouldn't be allowed. – Volatility – 2013-07-13T16:01:52.803
gamma and factorial are both allowed? – John Dvorak – 2013-07-13T16:10:56.160
@JanDvorak everthing that is listed (but only the things that are listed) can be used. – Volatility – 2013-07-13T16:17:15.867
are we allowed to output factorial as a prefix function (
!(4)
rather than(4)!
)? – John Dvorak – 2013-07-13T16:40:33.260@JanDvorak no, factorial should be postfix, like it normally is. – Volatility – 2013-07-14T00:51:37.307
I've made some ruby code, but I want to wait until it finishes before I upload. – John Dvorak – 2013-07-15T18:42:46.533