God I wish there was an easier way to do thisprogramming.devimage andioop ( @andioop@programming.dev ) Programming Horror@programming.devEnglish • edit-210 months ago message-square27fedilinkarrow-up1115
arrow-up1115imageGod I wish there was an easier way to do thisprogramming.dev andioop ( @andioop@programming.dev ) Programming Horror@programming.devEnglish • edit-210 months ago message-square27fedilink
minus-square neidu ( @neidu@feddit.nl ) linkfedilink15•edit-210 months agoMy solution in perl back in the day when I was a teenage hobbyist who didn’t know about the modulus operator: Divide by 2 and use regex to check for a decimal point. if ($num / 2 =~ /\./) { return “odd” } else { return “even” }
minus-square lysdexic ( @lysdexic@programming.dev ) linkfedilinkEnglish15•10 months ago Divide by 2 and check for a decimal point. I mean, it ain’t wrong.
My solution in perl back in the day when I was a teenage hobbyist who didn’t know about the modulus operator: Divide by 2 and use regex to check for a decimal point.
if ($num / 2 =~ /\./) { return “odd” }
else { return “even” }
I mean, it ain’t wrong.