# Situations when recursion helps [closed]

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

• Honestly, I don't understand the actual question or goal here. Is this supposed to be some kind of meme? I don't see how anyone can answer this, or how it would be rated. Mar 15 at 18:20
• Helpful for what? Mar 16 at 21:46
• @WheatWizard For whatever, though more likely code-golf
– l4m2
Mar 17 at 3:07

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.

# 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.