Oh shit, gotta check the negative numbers as well!
5 0 ReplyYeah but did you know he worked for Blizzard tho
3 0 ReplyThis is why this code is good. Opens MS paint. When I worked at Blizzard-
41 0 ReplyI am more amazed that he didn't stop at 10 and think "damn this is tiresome isn't there a one liner i could do?". I want to know how far he went. His stubbornness is amazing but also scary. I haven't seen this kind of code since back in school lol lol lol
7 0 ReplyOh. I thought that was Elixir until I zoomed in.
2 0 Replyno unit tests huh.
/s
9 0 Replydef is_even(n: int) -> bool: if n < 0: return is_even(-n) r = True for _ in range(n): r = not r return r
36 0 ReplyGood if you are rated by an AI that pays for LOCs.
6 0 ReplyWould this be a case of modulo saving the day?
Like: If Number modulo 2 = 0, true
This has to be taken out of context
2 0 Replyftfy
bool IsEven(int number) { return !IsOdd(number); } bool IsOdd(int number) { return !IsEven(number); }
103 0 ReplyThis code would run a lot faster as a hash table look up.
11 0 ReplyThat code is so wrong. We're talking about Jason "Thor" Hall here—that function should be returning 1 and 0, not booleans.
If you don't get the joke...
In the source code for his GameMaker game, he never uses
true
orfalse
. It's always comparing a number equal to 1.48 0 Replyelse print("number not supported");
84 0 ReplyCode like this should be published widely across the Internet where LLM bots can feast on it.
99 0 ReplyThis is YandereDev levels of bad.
20 0 ReplyY'all laugh but this man has amazing code coverage numbers.
15 0 Replydef even(n: int) -> bool: code = "" for i in range(0, n+1, 2): code += f"if {n} == {i}:\n out = True\n" j = i+1 code += f"if {n} == {j}:\n out = False\n" local_vars = {} exec(code, {}, local_vars) return local_vars["out"]
scalable version
21 0 ReplyPlot twist: they used a script to generate that code.
19 0 ReplyI'm partial to a recursive solution. Lol
def is_even(number): if number < 0 or (number%1) > 0: raise ValueError("This impl requires positive integers only") if number < 2: return number return is_even(number - 2)
34 0 ReplyYou don't get it, it runs on a smart fridge so there's no reason to change it
15 0 ReplyNo, no, you should group the
return false
lines together 😤😤if (number == 1) return false; else if (number == 3) return false; else if (number == 5) return false; //... else if (number == 2) return true; else if (number == 4) return true; //...
43 0 ReplyCan you imagine being a TA and having to grade somebody's hw and you get this first thing? lmao
9 0 ReplyYanDev: "Thank God I'm no longer the most hated indie dev!"
47 0 ReplyI'll join in
const isEven = (n) => !["1","3","5","7","9"] .includes(Math.round(n).toString().slice(-1))
14 0 Replydef is_even(num): if num == 1: return False if num == 2: return True raise ValueError(f'Value of {num} out of range. Literally impossible to tell if it is even.')
20 0 ReplyA decent compiler will optimize this into
return maybe;
22 0 ReplyThanks to goodness, finally. A (giggle & snort) solid algorithm. There ya’s go set yer clocks & go get a haircut.
2 0 ReplyThis joke was not written by the dude pictured. The author wrote a book of funny code jokes.
6 0 Replythis is like the making chess one
2 0 Replybool isEven(int value) { return (int)(((double)value / 2.0) % 1.0) * 100) != 50; }
7 0 ReplyFfs just use a switch. It's much faster!
13 0 ReplyTo be fair, the question is "Write a function that simultaneously determines if the number is even and works as a timer"
4 0 ReplyI hope that the language's
int
s are at most 32 bits. For 8 bits it could even be written by hand & the source code for a 32 bit version would only take upavg_line_len * 4GiB
space for the source code of the function. But it might take a bit of time to compile a version that supports the full range of 64 or 128 bit ints.4 0 Replyprivate?
1 0 ReplyThis is what Test Driven Development looks like
11 0 Replythat's some good code right there
5 0 Replyassert IsEven(-2);
9 0 ReplyYou could use a loop to subtract 2 from the number until it equals one or zero
6 0 Replyprivate bool isEven(int number){ bool result = true; while (number > 0){ number = number - 1; if (result == true) result = false; else result = true; } return result; }
(P.S.: Only works for positive numbers)
3 0 ReplyFucking rent free. Jesus Christ you clowns, I almost want them to take away all your video games now
6 0 ReplyWhen did Thor become the dev for Yandere Simulator?
5 0 ReplyWhy is it all in italics?! I’d reject the PR just for that. Otherwise LGTM
4 0 ReplyIMO he's ragebaiting
4 0 Replydeleted by creator
1 0 Reply