orhtej2@eviltoast.org to Programmer Humor@programming.devEnglish · 1 day agoPeak code reuseeviltoast.orgimagemessage-square41fedilinkarrow-up1440arrow-down15
arrow-up1435arrow-down1imagePeak code reuseeviltoast.orgorhtej2@eviltoast.org to Programmer Humor@programming.devEnglish · 1 day agomessage-square41fedilink
minus-squarecogman@lemmy.worldlinkfedilinkarrow-up7·edit-218 hours agoFixed boolean isOdd(int num) { if(num == 1) return true; if(num > 0) return isEven(num - 1); else return isEven(num + 1); } boolean isEven(int num) { if(num > 0) return isOdd(num - 1); else return isOdd(num + 1); }
minus-squareaffiliate@lemmy.worldlinkfedilinkarrow-up11·17 hours agothe downside with this approach is that it will eventually terminate. the version in the original post has the advantage of giving me plenty of time to contemplate life’s many mysteries.
minus-squarecogman@lemmy.worldlinkfedilinkarrow-up4·17 hours agoWhat can I say, I’m a performance nerd.
minus-squareRednax@lemmy.worldlinkfedilinkarrow-up3arrow-down2·17 hours agoWhy the complicated if statements to check the sign? Just let the number overflow. Would be functionaly the same, and result in much prettier code.
minus-squarecogman@lemmy.worldlinkfedilinkarrow-up6·17 hours agoThat’s a platform dependent change. Overflow is undefined behavior. I’d rather have my code portable so it can run on my Univac 1101.
Fixed
isEeven(∞);
the downside with this approach is that it will eventually terminate. the version in the original post has the advantage of giving me plenty of time to contemplate life’s many mysteries.
What can I say, I’m a performance nerd.
Why the complicated if statements to check the sign? Just let the number overflow. Would be functionaly the same, and result in much prettier code.
That’s a platform dependent change. Overflow is undefined behavior. I’d rather have my code portable so it can run on my Univac 1101.