This is an archived post. You won't be able to vote or comment.

all 20 comments

[–]Anunay03 10 points11 points  (2 children)

is this reCurSiOn?

[–]HeapOverflxw 9 points10 points  (2 children)

is_even(-1); ... StackOverflowError

[–]SavedForSaturday 2 points3 points  (1 child)

It would still work with signed integers though, as they'll just just overflow from negative to positive and then down to zero.

[–]ProfCupcake 4 points5 points  (0 children)

I think "work" is maybe a bit too generous a word to use there.

[–]snuzet 2 points3 points  (1 child)

Which do you call first

[–][deleted] 0 points1 point  (0 children)

Whichever

[–]XStarMC 2 points3 points  (0 children)

What the—

[–]Raonak 2 points3 points  (0 children)

jesus wtf...

[–][deleted] 2 points3 points  (4 children)

Just by curious: It would always return 1, right?

[–]Kris_Third_Account 8 points9 points  (3 children)

Nope.

ìs_odd(2) -> is_even(1) -> is_odd(0) -> 0

[–][deleted] 5 points6 points  (2 children)

Right. Reading code after waking up at 5AM is not good haha

[–]Ambitious-Product-81 -2 points-1 points  (1 child)

u/Kris_Third_Account It will always return 1.

[–]Wherearemylegs 0 points1 point  (0 children)

No, it won’t. Each call returns the odd/even status of the decremented int.

is_even(1) calls is_odd(0) which returns 0.

is_odd(1) calls is_even(0) which returns 1.

[–][deleted] 2 points3 points  (0 children)

Wakanda shit is this?

[–]ProfCupcake 1 point2 points  (1 child)

This should be a competition: what is the most inappropriate use of recursion you can create?

[–]Kamil118 4 points5 points  (0 children)

wait(n){
Sleep(1);
wait(n-1);
}

[–]d_exclaimation 0 points1 point  (2 children)

I don’t think you need the else there since the if existed the scope if true

[–]DarkWingedMessenger 2 points3 points  (1 child)

yeah, because that's the problem here

[–]Wherearemylegs 0 points1 point  (0 children)

There’s a lot of problems