Persona3Reload@lemmy.blahaj.zone to 196@lemmy.blahaj.zoneEnglish · 22 days agoRulelemmy.blahaj.zoneimagemessage-square57fedilinkarrow-up1393arrow-down16
arrow-up1387arrow-down1imageRulelemmy.blahaj.zonePersona3Reload@lemmy.blahaj.zone to 196@lemmy.blahaj.zoneEnglish · 22 days agomessage-square57fedilink
minus-squaregerryflap@feddit.nllinkfedilinkEnglisharrow-up23arrow-down1·21 days agoUsing Haskell you can write it way more concise: iseven :: Int -> Bool iseven 0 = True iseven 1 = False iseven 2 = True iseven 3 = False iseven 4 = True iseven 5 = False iseven 6 = True iseven 7 = False iseven 8 = True ... However, we can be way smarter by only defining the 2 base cases and then a recursive definition for all other numbers: iseven :: Int -> Bool iseven 0 = True iseven 1 = False iseven n = iseven (n-2) It’s having a hard time with negative numbers, but honestly that’s quite a mood
Using Haskell you can write it way more concise:
However, we can be way smarter by only defining the 2 base cases and then a recursive definition for all other numbers:
It’s having a hard time with negative numbers, but honestly that’s quite a mood
Recursion is its own reward