nave@lemmy.zip to Lemmy Shitpost@lemmy.worldEnglish · 10 months agoI wishi.imgur.comimagemessage-square189fedilinkarrow-up1923arrow-down117
arrow-up1906arrow-down1imageI wishi.imgur.comnave@lemmy.zip to Lemmy Shitpost@lemmy.worldEnglish · 10 months agomessage-square189fedilink
minus-squareRentlar@lemmy.calinkfedilinkarrow-up107·edit-210 months agoThey call me a StackOverflow expert: private bool isEven(int num) { if (num == 0) return true; if (num == 1) return false; if (num < 0) return isEven(-1 * num); return isEven(num - 2); }
minus-squarenyoooom@lemmy.worldlinkfedilinkarrow-up35·10 months agobool isEven(int num) { return num == 0 || !isEven(num - (num > 0 ? 1 : -1)); }
minus-squareJohanno@feddit.delinkfedilinkarrow-up17·edit-210 months agoStackoverflowException. What do I do now? Nvm. Got it. if(num % 2 == 0){ int num1 = num/2 int num2 = num/2 return isEven(num1) && isEven(num2) } if(num % 3 == 0){ int num1 = num/3 int num2 = num/3 int num3 = num/3 return isEven(num1) && isEven(num2) && isEven(num3) } Obviously we need to check each part of the division to make sure if they are even or not. /s
minus-squareReluctantMuskrat@lemmy.worldlinkfedilinkarrow-up5·10 months agoMan I love how horrible this is!
minus-squarecallyral [he/they]@pawb.sociallinkfedilinkEnglisharrow-up3·10 months ago…a recursive is-even wow
They call me a StackOverflow expert:
bool isEven(int num) { return num == 0 || !isEven(num - (num > 0 ? 1 : -1)); }
Damn that’s some solid optimization.
StackoverflowException.
What do I do now?
Nvm. Got it.
Obviously we need to check each part of the division to make sure if they are even or not. /s
Man I love how horrible this is!
…a recursive is-even
wow