Hector_McG ,

I first saw this joke back in the days of 8-bit home microcomputers. Of course then it only needed 256 lines of code, and took up about 8k of your precious, precious RAM.

mexicancartel ,

Well i hate this:

PS > .\program.exe 0

THIS:

.\

case_when ,

This is poetry.

My favourite part is that he uses the modulo operator in his Python script to generate the C code.

merc ,

I like this bit at the end:

As a side note, the program is amazingly performant. For small numbers the results are instantaneous and for the large number close to the 2^32 limit the result is still returned in around 10 seconds.

caellian ,

Really makes you question your sanity when optimizing jumps in code without benchmarks.

merc ,

For a long time I’ve been of the opinion that you should only ever optimize for the next sucker colleague who might need to read and edit your code. If you ever optimize for speed, it needs to be done with massive benchmarking / profiling support to ensure that the changes you make are worth it. This is especially true with modern compilers / interpreters that try to use clever techniques to optimize your code either on the fly, or before making the executable.

Klear ,

The first rule of optimization: Don’t do it
The second rule of optimization: Don’t do it yet (experts only)

blusterydayve26 ,

I’m still mad he didn’t use the size of the number to tell the system which block to read first. I feel like that would be a great use of division or maybe modulus?

merc ,

I just like how he used “% 2” in the Python code he used to generate the C++ code.

GreatBlueHeron ,

I’m not a good reader - I skim most articles and often miss most of the meaning. I read, and enjoyed, every word of that!

librecat ,

Thanks, I totally would’ve skipped it without this comment.

Aatube ,
@Aatube@kbin.social avatar

@programming_horror , anyone? We have an in production version of this used in Wikipedia

onlinepersona ,

I honestly thought this was going to be about AI 😅

CC BY-NC-SA 4.0

DarkGamer ,
@DarkGamer@kbin.social avatar

This is why every programmer needs to understand the modulo operator.

MxM111 ,
@MxM111@kbin.social avatar

I would divide by two (floating point) and check the fractional part.

ThrowawayPermanente ,

Let’s be real though, everything is IF statements all the way down

Th4tGuyII ,
@Th4tGuyII@kbin.social avatar

There's not a single thing in this universe that cannot be accomplished with enough IF statements... as long as you've got infinite time to wait

Hotzilla ,

Could be easily made 50% space saving by only iffin all odds and return even on else. Maybe one if before to handle overflow to avoid wrong even if over the last if.

Deebster ,
@Deebster@programming.dev avatar

Well yeah, if you allow cheating!

bjorney ,

Yeah but then ALL even numbers would be slow to compute because you would have to chain through every odd before you know that 2 is even.

Depends on the expected distribution of input values

Ephera ,

Now we just need to someone to package it and upload it to NPM.

NovaPrime ,
@NovaPrime@lemmy.ml avatar

Andreas is a maniac

  • All
  • Subscribed
  • Moderated
  • Favorites
  • random
  • [email protected]
  • tech
  • kbinEarth
  • testing
  • interstellar
  • wanderlust
  • All magazines