Would this be a case of modulo saving the day?
Like: If Number modulo 2 = 0, true
This has to be taken out of context
well that’s the joke, isn’t it
I mean, is it a joke? Because i have no context other than, after making a bad opinion known, there is a lot of talk about his code being terrible. So i guess this is fabricated then yea?
oh. is it assumed we know who the person is? i have no idea who that is.
When did Thor become the dev for Yandere Simulator?
I’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)I prefer good ole regex test of a binary num
function isEven(number){ binary=$(echo "obase=2; $number" | bc) if [ "${binary:-1}" = "1" ]; then return 255 fi return 0 }If your codebase is closed source there’s no risk of that happening, if it’s open source there’s nothing you can do about it.
Either way there’s no use worrying.
Amateur! I can read and understand that almost right away. Now I present a better solution:
even() ((($1+1)&1))(I mean, it’s funny cause it’s unreadable, but I suspect this is also one of the most efficient bash implementations possible)(Actually the obvious one is a slight bit faster. But this impl for
oddis the fastest one as far as I can tellodd() (($1&1)))I’m waiting for a code golf style solution now.
I don’t think there’s much to codegolf. The “obvious” solution (
even() (($1%2))) is both shorter and faster. Don’t think it can be optimized much more.
woah your bash is legit good. I thought numeric pretexts needed
(( blah )), but you’re ommiting the $ like an absolute madman. How is this wizardy possibleSee:
man bash, “Compound Commands” and “Shell Function Definitions”Oh I see it, but for some reason I was taught to always use
(( arith ))instead of(( arith ))and I guess I’m just wondering what the difference isThe difference is that
((is a “compound command”, similar to[[(evaluate conditional expression), while(( ))is “aritmetic expansion”. They behave in almost exactly the same way but are used in different contexts - the former uses “exit codes” while the latter returns a string, so the former would be used where you would expect a command, while the latter would be used where you expect an expression.This is similar to how there is
(compound command (run in a subshell), and$( )(command substitution). You can actually use the former to define a function too (as it’s a compound command):real_exit() { exit 1; } fake_exit() ( exit 1 )Calling
real_exitwill exit from the shell, while callingfake_exitwill do nothing as theexit 1command is executed in a separate subshell. Notice how you can also do the same in a command substition (because it runs in a subshell):echo $(echo foo; exit 1)Will run successfully and output
foo.It is another one of those unknown, very rarely useful features of bash.
amazing, thanks!
What you do is use a for loop to generate a million lines for you, then paste it in. Writing it manually is moronic. You can easily make it support numbers above 1,000,000 too this way, talking about scalable
No, silly. You ask chatgpt to write (steal) a loop that would generate all those lines. Haven’t you heard about meta-vibe template-programming?
I once saw someone unironically sharing their new trick of “if you need to write a bunch of really similar lines just with different numbers, chatGPT does it really well”.
Kind of blew my mind (and everyone else that saw the thread)
that’s some good code right there
A decent compiler will optimize this into
return maybe;I want to assess coders by lines written! The more the better!
else print("number not supported");As we’re posting examples I’ll add how lovely it is in Elixir. Elixir def not putting the fun in programmer memes do. One reason I picked it because I can’t be trusted to not be the meme.
def is_even?(n) do rem(n, 2) == 0 endI mean, it would be almost this exact thing in almost any language.
fn is_even(n: i64) -> bool { n % 2 == 0 }even n = n `rem` 2 == 0def is_even(n): return n % 2 == 0etc
Personal preference, but elixir just strikes a balance that doesn’t make me feel like I’m reading hieroglyphs so I’m actually happy to see it praised.
I would have preferred for the function to be called mod, since it’s the modulo operation, which in math is represented with a percentage or “mod”. Most programming languages use a percentage because of that, so do a lot of calculators.
Yeah, I agree that Elixir is a fine language for some tasks. I personally find the readability somewhat average, but it’s very maintainable (due to how it enables clear program structure), the error handling is great, and the lightweight process system is amazing.
Fucking rent free. Jesus Christ you clowns, I almost want them to take away all your video games now
oh no not my toys, like all good consoomers i put 99% of my self worth and identity into the things i consume mindlessly so this is devastating.
I think you got wooshed here
The guy in the picture is PirateSoftware, accused of sabotaging the Stop Killing Games initiative in the EU.
This post is part of a coordinated harassment campaign by big angy gamers because bad nerd man say companies won’t listen to their little lib demands to the EU
So instead of regrouping their efforts (which, I might add, they did, and they got their day in parliament) they (started off by) basically trashing this dude until he lost a large portion of his community. Because like they didn’t like how he defended his position. About video games. And now the fucking internet won’t shut up about it even though they got their way again through toxic bullying. And it annoys me. So I shitpost about it wherever I can because I hope it annoys them too.
There’s a lot of distorted facts here, but the weirdest one to me is “instead of regrouping their efforts (which, I might add, they did, and they got their day in parliament)”. The first half just contradicts itself (“instead of doing X, which they did, …”???) and the second half (“they got their day in parliament”) is verifiably, obviously false: The EU petition is still ongoing and collecting signatures. The deadline is July 31.
people IRL: hey man how’s it going
I have never met anyone cool who says “rent free”
I’ve never met anyone cool who cooks up strawmen memes because they’re exhausted all their actual criticisms.
The piratesoftware shit is so tiresome. Who the fuck cares? What is this going to accomplish? He’s not even popular anymore
Who cares? You. You’re the one who knows what this even is. ReNt FrEe is always a sign of having no argument
IMO he’s ragebaiting
OP is. This is just a remix of a popular meme.
I think he’s leaning into the drama for attention, but he’s also just bad
ftfy
bool IsEven(int number) { return !IsOdd(number); } bool IsOdd(int number) { return !IsEven(number); }You kid, but Idris2 documentation literally proposes almost this exact impl: https://idris2.readthedocs.io/en/latest/tutorial/typesfuns.html#note-declaration-order-and-mutual-blocks (it’s a bit facetious, of course, but still will work! the actual impl in the language is a lot more boring: https://github.com/idris-lang/Idris2/blob/main/libs/base/Data/Integral.idr)
I hadn’t seen Idris2. Thank you for providing me with a new rabbit hole!
I’m glad to tell more people about it. It’s really quite amazing (I could write a somewhat complex algorithm and prove some properties about it in a couple afternoons, despite limited formal verification experience) and I’m sure that in 20 odd years the ideas behind it will make it into mainstream languages, just as with ML/Haskell.
bool isEven(int value) { return (int)(((double)value / 2.0) % 1.0) * 100) != 50; }Why is it all in italics?! I’d reject the PR just for that. Otherwise LGTM
Throwback to when someone shared the OG version of this meme to my uni chat, I replied with "Oh you can simply do
def is_even(n: int) -> boolean: if n > 0 return not is_even(n - 1) elif n < 0 return not is_even(n + 1) else return TrueAnd instead of laughing at the joke the TA in the chat said “When you start getting internships you’ll do
n % 2” like I was being serious.Thanks to goodness, finally. A (giggle & snort) solid algorithm. There ya’s go set yer clocks & go get a haircut.














