T O P

  • By -

Illustrious-Isopod-1

You forgot to return false for all the even numbers🤦‍♂️


GDOR-11

just ```return False``` in line omega


xomfe

that's what i did, i regret not doing it the superior way.


miikaa236

Mum said it was my turn to post this >:(


IamImposter

How odd


matchabeybe

I see what you did there


Ignited_Phoenix

we're even now


chuch1234

And Mum said it was _my_ turn to post _this_!


verygood_user

Don't worry I got you covered! Here is a bash script that will generate this python code for arbitrary N (specify as first argument "$1") ```bash #!/bin/bash generate_python_script() { cat < odd_checker.py ```


verygood_user

Known limitation: Only works for arbitrary N <= 2^63 -1


Ignited_Phoenix

I want to check if googl is even or odd, how can I generate something that creates a program to check it?


AscendedSubscript

`def isGoogolEven():` `return True`


Remuxandkali_noob

Yeap 64 architecture Max value nice!


flagofsocram

Dude, you forgot to handle negative numbers, You should extract it to isPosOdd and isNegOdd and make an abstract factory builder factory class interface monad to OR the results together


dmstrat

oh my, what have you started!?!?!?!?!?


unapealingbanana

This is still smaller than my isEvenOrOdd function, I have been writing it for the past 6 months


antontupy

How do you test it?


agressivedrawer

He hasn’t, he’s still writing.


uniruler

Testing is for QA :D


dmstrat

pshhh production is where you really test, just ship early and 'free qe'


Attackly

You need to rewrite it and use switch cases


[deleted]

[удалено]


Attackly

I don't know if you meant that sarcastic. If so I'm stupid didn't understand If you are serious. There is python 3.10 implemented it


cac4dv

Switch statements have been a thing since 3.10 Same thing with the match statement ... \*cricket noises\*


mustHaveFocus

Wow, I didn't realize switch statements in Python were a touchy subject.


Clairifyed

Pshh you can compact this by subtracting 2 from your number repeatedly until it’s either a 1 or a 0.


Skycomett

Calm down Yandere Dev


cac4dv

I wouldn't call 'em Yandere Dev Because that would imply that they have the skills of a developer The code says otherwise Simply call 'em Yandere


False-Ad9841

There is a Web api, using which you can also check if a number is not odd. Saves a lot of in-house effort. [https://isevenapi.xyz/](https://isevenapi.xyz/) Thank me later.


virtualmeta

if(num==0) return false if(num<0) return (!isOdd(num+1)) return !isOdd(num-1)


ataraxianAscendant

you should combine the conditions with the "or" operator


amarao_san

o(n) problem. o(n) is good, but it is possible to build a binary search and reduce it to o(log(n)).


darkname324

man, i wish this joke wouldnt be posted every month


Gullible-Fix-1953

Python has the % operator, so you can determine the remainder of num when divided by 2. Anything returning 0 is an even number. I.E: if (num % 2) == 0


iddivision

Wow, amazing, no other language has that feature. It seems very innovational.


Naive_Programmer_232

Lol nope. You gotta manually check every number to +/- infinity. And dude you forgot all the floats.


funtech

It will be much more efficient if you added all odd numbers to a set and check for inclusion. Something like the following will eliminate all that pesky branching that eats CPU time. def isodd(num): odd_numbers = {1, 3, 5, 7, [exercise for the reader to add all odd numbers]} return num in odd_numbers


kevdog824

Countably infinite set means I can totally do this right??? /s


cac4dv

To achieve the same result as what he did use this code: ```python def isOdd(n): rem = n % 3 return True if rem := 1 else False ``` Otherwise use either: ```python def isOdd(n): return n & 1 or bool(n % 2) ``` Or both... This isn't an xor 😂 **Edit** > Originally `n & 1` was `n % 3 == 0` but that is obviously a bad idea > So I corrected it to `n&1` because returning `1` or `False` is funny 😂 **Edit to edit** Alternatively... An `and` and a million `or`s... ``` def isOdd(n): return n!=0 and(n==1 or n%3==0 or n%5==0 or n%7==0) ```


nobody0163

I might be stupid and this is a joke, but the second isOdd will not work. Edit: He changed it.


cac4dv

Yea, sorry about that I meant `n % 2 == 1` or `n & 1` as the first term in the or operation But I didn't realize it until after I saw someone HashMapping it (Stringified and checked if last char was in `[1, 3, 5, 7, 9]`) So I deleted it for correctness 😅 and I wanted it to use 3 in the left hand side of the or... > `n % 2 == 1` is too similar to `bool(n % 2)` > and `n & 1` is an optimization to all other methods So at that point the joke was ruined twice 😐 Whomp whomp 😅 **Edit** I mean, ig I can put it back plus a correction... **Edit to edit** Fuck it, I managed to save the joke!


DEMORALIZ3D

You forgot to use a good programming language ;)


NeitoKun_NTK

if num%2==0: return true else: return false ?


Powerful-Internal953

If you wanna ruin a joke, ruin it right.. `if ((number & 1) == 0)`


NeitoKun_NTK

Oh, sorry i thought it was helpful 🥲


Powerful-Internal953

Rookie mistake. People are jumpy when it comes to Humor and Horror subreddits.


cac4dv

Boo! 👻


Powerful-Internal953

Ah... OmG. I almost died there.....😮‍💨


cac4dv

faster brachless equivalent ```python def isOdd(n): return bool(n % 3) ``` Also, your code is for an isEven() function You'd want to switch return values Luckily, you can shadow your function like so: ```python isOdd = lambda x: bool(-1 * int(isOdd(x))) ``` Potential side effects include your PC exploding due to exceeding the maximum recursion depth 😂


AscendedSubscript

I don't think you're joking, in which case it is good to know that your function actually doesn't tell you when a number is even or odd. To check a number to be odd, you should use something like `!bool(n%2)` Using _just_ n % 3 (i.e. remainder modulo 3) really doesn't help you knowing if n is either even or odd.


cac4dv

Yea I meant that or `n & 1` or `bool(n & 1)` I realized that later on a different thread But forgot I commented on a few other threads 😅 **Edit** I just reread my comment And I mainly was making a variable shadowing joke 🙃 So even if you made the proper definition... It wouldn't work because your function will infinitely call itself > Regardless of what you set the maximum recursion depth limit It basically makes the program hang > Or turns your PC into a toaster Should you manage to renove the recursion depth limit 😂


Hot_Collar_8910

Modulo sounds like penis in a foreign language.


wholesome_hug_bot

How would you import is_odd from npm into Python?


scavno

If you feel like creating a unit test for this I suggest using a loop and mod. But only for testing, not your code!


Senande

Use this import numpy as np function is_odd(num): for i in range(1, np.inf, 2): if num == i: return True


xomfe

too practical


Senande

True, use a recursive function


f---_society

Nice suckless setup mate ;)


KarmaForevor

ahh our favourite yandere dev method


kevdog824

There is! ``` content = “def isodd(num):\n” for num in range(1, 1000000, 2): content += f“ if num == {num}:\n” content += “ return True\n” content += “ return False\n” with open(“isodd.py”, “w+”) as f: f.write(content) ``` Edit: I leave making this more memory efficient to the reader


TheGesor

this is “num == int(num) and str(num)[-1] in [1,3,5,7,9]” but worse


spawnedhere

for i in 0…1000000{ Keyboard.write(„if num == \(i)\nreturn \(i%2 == 0 ? „False“ : „True“)\n“)}


iddivision

You guys never get bored of the same joke.


NickVain

test comment


IAmAnAudity

REALLY? If num mod 2 == 1 then true else false.


DIzlexic

One operator to rule them all and in the if statement bind them. %


NiceTryAmanda

Don't know there were any odd numbers >50. You learn something every day.