r/HelpMeFindThis • • 3d ago

this image

Post image

i don't know how to code in python so i just bullshitted the code based on what i remember but the joke was individually returning "true" or "false" for every number to check if it was even

2.1k Upvotes

110 comments sorted by

323

u/Totaly__a_human 3d ago

226

u/ILikeCarlosThePikmin 3d ago

Watch me make this about my fandom rq

86

u/LogieBearra 3d ago

Which fandom

50

u/Smasher11 3d ago • Heartwarming

More like:

7

u/ILikeCarlosThePikmin 3d ago

Funny thing is that some people would say the right is UT/DR so

4

u/RevolutionaryHat7726 2d ago

Hell vs mega hell

7

u/Mathsboy2718 3d ago

Yeah but which is which tho

Toby is clearly good, but he's got smug energy while Yandere dev's is world-weary

14

u/scooblessly 3d ago

yandev’s a wholeass pedo so pretty sure he’s evil no matter what

1

u/ProbablyNano 3d ago

Sonic and Shadow 

3

u/ThePotatoFromIrak 3d ago edited 3d ago

So inspired by mother 3 that he even has his own evil twin

2

u/beleth____ 23h ago

Toby looks like if you averaged the two guys from shin megami tensei 4

1

u/MarshaIsSoSorry 17h ago

Walter x Jonathan shipchild

18

u/Ninjaguy999 3d ago

I could have sworn the YanDev version was an edited one to make fun of how he codes his games, and the original was just a one off joke

7

u/Clkiscool 3d ago

Yes, the yandev is an edited version

16

u/MasonAttano 3d ago

This is the more popular version that gets spread around but I’m pretty sure it’s an edit

8

u/E-686 3d ago

a friend of mine GENUINELY did this

7

u/Belgrifex 3d ago

Its like when he tried coding chess by programing every single move combination possible

11

u/GoodSause 3d ago

Of course its him

9

u/V_The_1AndOnly1 3d ago edited 3d ago

I haven’t touched any programming software in like 3 or so years or gotten too far in my learning if we’re being completely honest.., but isn’t the solution to make a list and put all of the true numbers in it and then make the if statement say the equivalent to “if (number = [listed value]) return true; else return false”? Something along those lines?

Edit: I cannot read omg this is supposed to be odd/even.. There's probably some flavor of math equation (that I do not know lol) that lets you do this quickly, but I skimmed through it and thought there were specific “answers” and didn’t look further in until I saw someone else say it was just odd/even…

20

u/MarbleGorgon0417 3d ago

Easiest solution (though idk if it exists in every programming language) is to use the modulo operator (%), which returns the remainder after a division. You would put "if number % 2 == 0 return true", and so if it's even, divides evenly, no remainder, so it'd return true, and if it's odd, it wouldnt, remainder would be 1, and would return false.

6

u/tomysshadow 3d ago edited 3d ago

Another common solution is to use bitwise AND.

!(number & 1)

It works because the lowest bit is the 1's position, so only odd numbers will have that bit set.

Compilers will usually optimize the modulo version down to the bitwise version because it avoids a division operation, but it depends on if it has enough context - i.e. if the divisor is not the constant number 2 but is instead taken in as an argument, and it can't see where that argument comes from (it's a virtual function, or the function is exported in a DLL etc.) it can't assume it is 2 so is forced to actually use modulo.

In JavaScript it's preferable to use the modulo solution because using bitwise math requires it to cast the float to a 32-bit integer, perform the bitwise operation, then cast it back to float, instead of being able to perform the operation on the float directly like it can with modulo.

1

u/Efficient_Yard_8247 3d ago

It exists in every programming language

1

u/One_Consideration544 3d ago

Now it's not going to be EVERY language, it could be almost every or anything that you're likely to learn. but no one is saying assembly isn't a language and there are a very large amounts of languages that are for very specific niches.

1

u/0tter501 3d ago

assembly has modulo, every language has modulo because its trivially easy and really useful, if a language doesn't have modulo its an esolang

1

u/TheDarkNerd 2d ago

Esolangs don't belong to the set of all programming languages?

1

u/Efficient_Yard_8247 3d ago

It was a hyperbolic statement, obviously you can invent any programming language that doesn’t have it. But anything worth your time has the remainder operation, it’s easy to implement and incredibly useful.

1

u/Dreamergal9 2d ago

I learned this in one semester of an introductory programming class. 

3

u/vladutzu27 3d ago

`n % 2 == 0 ? "even" : "odd"`

1

u/traintraintraintr 3d ago

yeah i think theres an even simpler solution but i lowkey gave up on learning to program lol

1

u/Confident_Rod_9717 3d ago

you can use the modulo operator, which is % in most languages, which returns the remainder of a division.
i.e. when converting 19:00 from 24 hour time to 12 hour time, 19 % 12 = 7, so 19:00 is 7pm.

Any number % 2 will be either 0 or 1, 0 if its even (no remainder when dividing by 2) or 1 when it's odd (remainder 1 when diving by 2).

So you can use:

private bool IsEven(int number) {
  return (number % 2 == 0)
}

1

u/imsc4red 2d ago

Just take the input from you user then do and if else setup with the condition as “input % 2 == 0” which divides the input by 2 and checks if there is a remainder, if there is one it’s odd, if not it’s even.

0

u/White_Phoenix789034 3d ago

Idk if this would work or not I challenged myself to come up with this. Basically divide the number of the variable by 2 until it’s less than two, then check if it s equal to one. If it is, it’s even. if not, it’s odd. This is my solution no modular operator.

4

u/NatuFabu 3d ago

That's the kind of unoptimised code I keep finding in my 8 year old project that I'm currently trying to update.

Wish me luck...

1

u/Mysterious-Title-251 3d ago

Is this real?

5

u/HeadStrike773 3d ago

The tweet is real but it wasn't actually yandere dev i don't remember who actually posted it

1

u/averagenolifeguy 3d ago

Same mfs would complain "why big walk devs used ai couldn't they just fix the bug"

1

u/ur_pretty_strawberry 1d ago

Fixed it for him If num%2 ==0: return true Return false

1

u/lollolcheese123 1d ago

Even better: return based on the last bit.

1

u/deanominecraft 1d ago

return num&1;

1

u/ur_pretty_strawberry 1d ago

I used python for it specifically, but looking at it he uses a different language lmao

1

u/TypeNull-Gaming 1d ago

The worst code of today (Toby Fox) vs the worst code of all time (YandereDev)

38

u/SovaSperyshkom 3d ago

13

u/SavingsNewspaper2 3d ago

It's almost like some kind of effect

8

u/IlaZiN 3d ago

I'm matting my pat so good rn

3

u/Trotle-bot 2d ago

Just in time for his return too

1

u/NotPinkunobara 3d ago

i cannot accept this

1

u/someSICKusername 1d ago

What's the joke here?

25

u/Head_Holiday9519 3d ago

As someone who just finished a small ish project in python, this is absolutely horrifying

16

u/MagicMushShrooms 3d ago

can someone drop the knowledge of how it's actually done pls?

26

u/Wooden-Paper-872 3d ago

Im pretty sure you allow the user to input a number, and then you get the modulo 2 of that number, aka getting its remainder when divided by 2.

If the result is 0, aka no remainder, its even. But if you get 1, its odd

5

u/MagicMushShrooms 3d ago

surely there's an easier method than modulo in coding?

14

u/Wooden-Paper-872 3d ago

well thats kind of the easiest way already 

Like compared to the long code you see in the post image and the original, it would be something like

if(number%2==0)  return even

else return odd

3

u/MagicMushShrooms 3d ago

thanks man. it makes sense. i have used modulo but in 3d geo nodes in blender and made my own work around in maya as well. i just thought coding had an even easier way to deal with it but it makes sense that this is the bar

3

u/forestwolf42 3d ago

If you're checking for even/odd a lot you could even make a function.

func iseven(int) -> bool:     If int % 2 = 0            return true     Else           return false

Then you can just ask iseven anywhere the function is declared.          

1

u/Tide__Hunter 2d ago

You can get it even shorter with just "return number%2==0" in the case of an "is_even" function.

1

u/gameryesyt 3d ago

If (x % 2 == 1); Y=true; Else if (x % 2 == 0); Y=false;

It doesn't get much simpler than that

2

u/BagelMakesDev 3d ago edited 2d ago

This is false. The second modulo is redundant and a waste of CPU cycles. this can be simplified to
if (x % 2 == 0) { return EVEN; } else { return ODD; }

This uses less CPU cycles.

1

u/Vivid-Key-9032 3d ago

i understand the redundant if statement but your initial claim of "other" remainders i dont get that. there can only be a remainder of either 0 or 1 , there are no other remainders possible when dividing a number by 2 or am i missing something?

1

u/BagelMakesDev 2d ago

oh, you're correct, my bad, im a programmer not a mathematician 😅

1

u/Adventurous-Year-176 3d ago

Well yes, you only need to test one condition.

1

u/explodingtuna 3d ago

Not even bitwise AND or bit shifts back and forth?

1

u/qlexc 3d ago

bool odd(unsigned int x) { return x & 1; }

1

u/HostOfTheCamp2 3d ago

If its less than 1 add 2 until its equal to 1 or 2 if its greater than 2 then subtract until its equal to 1 or 2

1

u/meerproposition 3d ago

modulo is what the cpu does

1

u/0tter501 3d ago

you can do bitwise AND 1 with any  number, returns the exact same result just more likely to be faster

i could say with zero doubt that every modern language, compiler, hell, every language compiler with any optimizations will automatically convert a % 2 into a AND 1

1

u/behemothtyphoon 3d ago

this is a single short line, cant get much simpler

1

u/IcyEffort2841 3d ago

This comment pissed me off. Have a horrible day.

1

u/MagicMushShrooms 3d ago

didnt mean to piss you off. i used modulo often in blender (3d software) for shading. just thought that behind it, there was an easier code/way to do this. i was wrong. this is the bar

1

u/jpk64- 3d ago

Basically just:

bool isEven(int value) { return !(value & 1); }

The rightmost bit (so the 1 bit) is only set dor odd numbers. So invert the result, because if it is not odd, then it is even.

Most compilers are smart enough to optimize your code for you, though, and turn the following, more readable approach into the function above for you:

bool isEven(int value) { return value % 2 == 0; }

Do value mod 2. If it is 0 (so dividing value by 2 does not leave a rest), then value is even.

1

u/scallywag_software 2d ago

return (number & 1) == 0; // bitwise and. If the bottom-most bit is 0, it's even.

1

u/I_Exist_Let_Me_Alone 2d ago

In python you can divide the number by 2, check if it's an int(whole number) or float (not whole number)

1

u/L30N1337 1d ago

that's... an interesting solution.

the default solution is modulus (since that's literally what it's for)

and I guess you could compare the last bit

1

u/I_Exist_Let_Me_Alone 1d ago

... I forgot about modulus. I mean sure, it's been a year since I've actually used the thing but damn.

1

u/solar_sausage 1d ago

return number%2 == 0;

36

u/mrbeck1 3d ago

For starters, just declare it false and then list the even numbers which change it to true. Cut 50% of your code for you. You’re welcome.

4

u/behemothtyphoon 3d ago

if someone were to do it like that thatd be like barely 1% less embarrassing icl

1

u/GreatValueBradPitt 3d ago

I’d say equally embarrassing if not more so. Imagine your galaxy-brain optimization of determining whether or not something is even or odd being “just manually test half of an infinite number sequence”.

1

u/TheDarkNerd 2d ago

You can easily do this with a "while" loop that starts with a variable of the value you want to return as "true", then for each iteration of the loop, increments a variable counting which iteration of the loop you're on, checks if the variable is equal to the parameter value you're testing against, then goes onto the next iteration of the loop if it isn't.

Doing it this way keeps you from having to list every possible value.

1

u/TeifitV 10h ago

Just use the modulus operand.

3

u/According-Object-521 3d ago

If number % 2 == 0 {return true} ; return false

1

u/NaboriRuta 3d ago

return num % 2 == 0;

1

u/TheDarkNerd 2d ago

return !(num%2)

(No idea if this works, since I'm supposing it would depend on if the ! would negate the num%2 as a bool)

1

u/EmeraldMan25 2d ago

Yeah it would work. Bool is really just 0 and 1, so doing num%2 and then negating the output would give the right value

1

u/According-Object-521 2d ago

I don’t think so modulus operator returns an Int which you can’t negate

1

u/EmeraldMan25 2d ago

Actually, you can! In every language I've used, anyway. Bits are bits. Boolean is essentially just the negation of the zero flag in most implementations. That means anything can be a boolean. The key is that any bit string that equals 0 is false, anything else is true

1

u/According-Object-521 2d ago

Which languages does that work in? I’m pretty sure you usually can’t negate an Int

1

u/L30N1337 1d ago

depends on the language.

C# is gonna scream at you.

C would probably allow it (I remember "while (1)" from Arduino classes)

2

u/ChknBom205 2d ago

X = Num

Y = X ÷ 2

Repeat X ÷ 2 times: Y = Y - 1

If Y = 0.5: Tails

If Y = 1: Heads

1

u/DarkOriole4 2d ago

Verilog be like

1

u/Neki_Chan_1 1d ago

Beyond the meme, what was the easiest way to do it?

1

u/Ineedlasagnajon 1d ago

I am only somewhat acquainted with Python, so I came up with this

def evenchecker(x)

-----return ".0" in str(x/2)

That's three steps, but I've been shown faster ways by others

def evenchecker(x)

-----return x % 2 == 0

Only two steps, so it's more optimal

1

u/Neki_Chan_1 1d ago

Thanks!

1

u/Creative-Leg2607 1d ago

I wouldnt even define it as a function. Hell in some languages you could cast to boolean and just say ! bool(x%2), but at that point its getting a bit silly.

1

u/Papa_Buzzard 1d ago

%2... youve made my head hurt tonight.

1

u/PigsAreCool123 1d ago

return number % 2 == 0

1

u/NightDragoOfficial 17h ago

Python with type hints

def is_even(num: int) -> bool: return (num % 2) == 0

1

u/PoobGnarpy 16h ago

I thought this was Toby Fox lol

0

u/tottalynotpineaple12 3d ago

The original wasn't even python code OP, why mention that you don't know python when you don't even know the programming language in question bruh

1

u/Timely_Succotash8754 3d ago

i misremembered it being python

1

u/astolfoballsHD 3d ago

I was also just looking to see what language that was since it definitely isnt python lol. I guess C# makes the most sense, otherwise Java

1

u/tottalynotpineaple12 3d ago

Yeah my first thought was Java, then C#, their syntax is quite similar

1

u/tottalynotpineaple12 3d ago

Actually nevermind, it has to be C# because its bool not boolean

1

u/behemothtyphoon 3d ago

it doesnt remotely resemble c# either