6
\$\begingroup\$

Recursion is actually quite powerful, sometimes its doesn't look like that child problem of itself exist, but recursion is just helpful.

One case per answer.

\$\endgroup\$
4

2 Answers 2

6
\$\begingroup\$

Adjusting argument order

E.g. Decide if 3 sticks construct a right triangle:

(a,b,c)=>a*a+b*b==c*c|b*b+c*c==a*a|c*c+a*a==b*b  // 47 bytes
f=(a,b,c)=>a<b|a<c?f(b,c,a):a*a==b*b+c*c         // 40 bytes

(Yeah the hypot solution is also 40, but it's not the point here)

Here it rotates until a is one of the largest elements, and there's no need to write the formula three times.

\$\endgroup\$
2
\$\begingroup\$

Another branch of function happens to fit

In Infinite Turtle, all numbers are between 0 and 100, inclusive. There's only saturated increment and decrement by one operation, and isZero condition. Requires to subtract modulo 101.

My solution:

SUB101(x,y) := y==0?x:SUB101(x==0?GEN100(x):x-1,y-1)
GEN100(x) := SUB101(x+1,x)==0?x:GEN100(x+1)

Here, SUB101(x+1,x) returns 1 if x!=100, or 0 if x==100. GEN100 is never called inside due to input limit. By reusing SUB101, I needn't another SUB or ISEQUAL.

enter image description hereenter image description here

\$\endgroup\$

Not the answer you're looking for? Browse other questions tagged or ask your own question.