4 Billion If Statements | Prime Reacts

แชร์
ฝัง
  • เผยแพร่เมื่อ 21 ม.ค. 2024
  • Recorded live on twitch, GET IN
    / theprimeagen
    Become a backend engineer. Its my favorite site
    boot.dev/?promo=PRIMEYT
    This is also the best way to support me is to support yourself becoming a better backend engineer.
    Reviewed video: andreasjhkarlsson.github.io/j...
    By: Andreas Karlsson
    MY MAIN YT CHANNEL: Has well edited engineering videos
    / theprimeagen
    Discord
    / discord
    Have something for me to read or react to?: / theprimeagenreact
    Kinesis Advantage 360: bit.ly/Prime-Kinesis
    Hey I am sponsored by Turso, an edge database. I think they are pretty neet. Give them a try for free and if you want you can get a decent amount off (the free tier is the best (better than planetscale or any other))
    turso.tech/deeznuts
  • วิทยาศาสตร์และเทคโนโลยี

ความคิดเห็น • 579

  • @Sousa22ko
    @Sousa22ko 3 หลายเดือนก่อน +3536

    programmers in 1969: send a spaceship to the moon with only 4KB of RAM
    programmers in 2024: i need 30GB to check if a number is even or odd

    • @muhammadabdulsalam602
      @muhammadabdulsalam602 3 หลายเดือนก่อน +20

      😂😂😂

    • @Mystery_Glitch
      @Mystery_Glitch 3 หลายเดือนก่อน +139

      The power of optimization and deoptimization

    • @cewla3348
      @cewla3348 2 หลายเดือนก่อน

      @@falconheavy595 yes. i wont argue it, but yes.

    • @MrAntiKnowledge
      @MrAntiKnowledge 2 หลายเดือนก่อน +75

      You can't send a spaceship to the moon, you need a moonship for that, duh.

    • @shroomer3867
      @shroomer3867 2 หลายเดือนก่อน +80

      The benefit of AI is that it would never write this.
      The drawback of AI is that it would never write this.

  • @davidjohnston4240
    @davidjohnston4240 3 หลายเดือนก่อน +1888

    Dynamic meta programming optimization - Take the number, write the single line of code to check that number to a file, compile it, run it.

    • @smanzoli
      @smanzoli 3 หลายเดือนก่อน +67

      In case the challenge was "not to use aby math, just IFs" (not sure), we could just set a list like odd_array = [1,3,5,7,9] and check IF the last digit of the input number is in odd_array. Number is odd IF it is, else it's even.
      But it would not be funny and challenging, lol.
      Loved his solution.

    • @TJackson736
      @TJackson736 3 หลายเดือนก่อน +28

      ​@smanzoli depending if it is unsigned, you can just bit mask the least significant bit and check if it is equal to 1. If it is, return true in isodd. Else return false.
      This should also work with 2's complement representations as well.
      If we are going with all negative numbers are not odd, we simply have to check ifNegative before checking the odd process explained before.

    • @prodkinetik
      @prodkinetik 3 หลายเดือนก่อน +8

      built-in caching by checking if the if statement already exists in the file before writing to it and compiling

    • @youtubeenjoyer1743
      @youtubeenjoyer1743 3 หลายเดือนก่อน +21

      @@TJackson736 sounds like math. No math allowed

    • @anon-fz2bo
      @anon-fz2bo 3 หลายเดือนก่อน +1

      ​@@youtubeenjoyer1743 the math behid that is not that complicated, its more theory heavy tbh but yeah kinda genius ngl

  • @dboss112
    @dboss112 3 หลายเดือนก่อน +2099

    I took my first programming class in high school and one of my assignments was to write a program that let you select a month/year and the program displayed the calendar layout for that month. I proceeded to write out every possible calendar layout for each combination of days in the month and starting day of the week all chained together with if statements.
    After a few hours of copy pasting calendars and moving around the numbers my program was ready to be printed and passed in. Yes my teacher graded our programs by hand with pen and paper. After several minutes of the printer chugging along nonstop my classmates began to notice the monstrosity I had created. My teacher was not happy when I handed in 100+ pages.

    • @andarba2148
      @andarba2148 3 หลายเดือนก่อน +223

      He didn’t know what a loop was 🤣🫵

    • @dboss112
      @dboss112 3 หลายเดือนก่อน +521

      ​@@andarba2148 I think we learned loops the following week 😭

    • @tirushone6446
      @tirushone6446 3 หลายเดือนก่อน +82

      bruh there is no way 💀

    • @fus132
      @fus132 3 หลายเดือนก่อน +16

      @@dboss112 RiP

    • @ZeroUm_
      @ZeroUm_ 3 หลายเดือนก่อน +191

      ​@@dboss112I love stories where the teacher is the one learning lessons.

  • @tukan1652
    @tukan1652 3 หลายเดือนก่อน +958

    conclusion:
    9:16
    If windows says you can't compile a 40gb file you say yes you can

    • @ThePrimeTimeagen
      @ThePrimeTimeagen  3 หลายเดือนก่อน +249

      never stop stopping

    • @lordender_kitty_official
      @lordender_kitty_official 3 หลายเดือนก่อน +27

      but would other operating systems be chill with it? because we all know that windows is gay and everyone should convert to linux.

    • @cewla3348
      @cewla3348 2 หลายเดือนก่อน +14

      @@lordender_kitty_official 1. homophobic intent, please fix yourself
      2. bro who do you think uses linux???

    • @treanttrooper6349
      @treanttrooper6349 2 หลายเดือนก่อน +26

      ​@@cewla3348 how do you know he isnt gay?

    • @cewla3348
      @cewla3348 2 หลายเดือนก่อน +7

      @@treanttrooper6349 because he’s using gay as a negative adjective, which is homophobic. Read his damn comment.

  • @db_2112
    @db_2112 3 หลายเดือนก่อน +992

    I love that the guy used modulo in python to generate the first file

    • @davidboeger6766
      @davidboeger6766 3 หลายเดือนก่อน +180

      The algorithm wasn't self-hosting yet. This article was about the bootstrapping process. Python will now replace its current implementation of % with this one and see 10x performance increases.

    • @KleptomaniacJames
      @KleptomaniacJames 3 หลายเดือนก่อน +16

      @@davidboeger6766 a bit wise AND would be a far better implementation

    • @katrinabryce
      @katrinabryce 3 หลายเดือนก่อน

      @@davidboeger6766 Do something along the lines of this 💁🏻‍♀
      iseven = True
      for n in range(4294967296):
      print(n,"is even" if iseven else "is odd")
      iseven = not iseven
      Substitute in your actual code in the print statement.

    • @marko1395
      @marko1395 3 หลายเดือนก่อน +3

      @@KleptomaniacJames The correct way is to go in batches of two. i is even, i + 1 is odd.

    • @MisterAssasine
      @MisterAssasine 2 หลายเดือนก่อน

      before doing that I would first check if the compiler doesnt already do that for me and keep my good maintainable code@@KleptomaniacJames

  • @w0cker
    @w0cker 3 หลายเดือนก่อน +434

    now make that an npm package for the world to depend on

    • @bekiraltindal9053
      @bekiraltindal9053 3 หลายเดือนก่อน +5

      😂

    • @oleksiistri8429
      @oleksiistri8429 3 หลายเดือนก่อน +11

      That's too cruel

    • @Rudxain
      @Rudxain 3 หลายเดือนก่อน +42

      `node_modules` about to bloat harder than a black-hole with the mass of all observable galaxies

    • @abeidiot
      @abeidiot 2 หลายเดือนก่อน

      now that is true evil

  • @RubixCubed3
    @RubixCubed3 3 หลายเดือนก่อน +796

    Using the slowest programming language to automate writing 4 billion if statements in the fastest programming language. That is gangster.

    • @Rio-zh2wb
      @Rio-zh2wb 3 หลายเดือนก่อน +5

      Indeed

    • @aoeu256
      @aoeu256 13 วันที่ผ่านมา +2

      actually haskell and especially lisp programmers build real-time programs by embedding low level languages, a high level representation, and building a compiler between the low level and high level representation.

  • @nrwchd
    @nrwchd 3 หลายเดือนก่อน +416

    paid by the lines

    • @grawss
      @grawss หลายเดือนก่อน +17

      "I've written over four billion lines of code." - Every programming resume ever.

  • @electrpaleo
    @electrpaleo 3 หลายเดือนก่อน +258

    Now I needs a part 2 comparing the performance of a 4 billion switch statement

    • @Ipanienko
      @Ipanienko 3 หลายเดือนก่อน +24

      Actually, it could be a lot faster if the switch statement gets compiled to a jump table.

    • @gregorymorse8423
      @gregorymorse8423 3 หลายเดือนก่อน +8

      It would be a jump table with 4 billion entries one byte each as per how most compilers work. Obviously optimization could do bits or with two cases change to a conditional jump or even just recognize its simplifiable to a parity condition.

    • @rosomak8244
      @rosomak8244 2 หลายเดือนก่อน +9

      @@Ipanienko No. Memory access times will kill the performance.

    • @icegiant1000
      @icegiant1000 2 หลายเดือนก่อน +4

      That was the first thing out of my mouth, "Ya know, a switch statement would be faster..."

  • @Slateproc
    @Slateproc 2 หลายเดือนก่อน +75

    someone really saw Yandere-Dev's code and said "bet"

  • @Void_Dragon
    @Void_Dragon 2 หลายเดือนก่อน +137

    "All unauthorized distribution of this source code will be persecuted to the fullest extent of the law" 💀

  • @emeraldbonsai
    @emeraldbonsai 3 หลายเดือนก่อน +161

    In theory you could have several 1000 people try out this program then record all there inputs then reorganize the ifs so that more common numbers are higher up in the if list to optimize it

    • @meekrab9027
      @meekrab9027 3 หลายเดือนก่อน +5

      Reminds me of the story Chandler Carruth told about optimizing some C++ code written by Ken Thompson: th-cam.com/video/nXaxk27zwlk/w-d-xo.html

    • @user-sv3dc5nz8w
      @user-sv3dc5nz8w 3 หลายเดือนก่อน +22

      A better approach is to pre-calculate. We can do it for every number using our first version from the article. Then embed the results into an array of 2**32 items.

    • @KariArgillander
      @KariArgillander 3 หลายเดือนก่อน

      @@user-sv3dc5nz8w definetly this. I would happy to give some memory to program so it can run faster.

    • @knutharald9814
      @knutharald9814 3 หลายเดือนก่อน +2

      Apply some bitwise magic and the storage requirements go down to 0.5GB

    • @ironbard4901
      @ironbard4901 3 หลายเดือนก่อน

      @@knutharald9814 ... what?

  • @justuseodysee7348
    @justuseodysee7348 3 หลายเดือนก่อน +172

    This software is written and optimized for next gen hardware. You can't expect that your 10y old 4760k with 16GB of ram will be supported forever.
    This is unavoidable progress, it's time for an upgrade

    • @flipwonderland4181
      @flipwonderland4181 หลายเดือนก่อน +1

      so true

    • @WHEELES
      @WHEELES 14 วันที่ผ่านมา

      16 gb ram - a NOT old PC. Old PC - it's a max 8 gb.
      Yes, I use really old pc...

  • @hungrymusicwolf
    @hungrymusicwolf 3 หลายเดือนก่อน +105

    No matter how many times I hear this story I keep laughing out loud. This guy better be a writer as a side hustle.

  • @real1cytv
    @real1cytv 3 หลายเดือนก่อน +313

    I think theo said it best, when he said: Imagine showing this to a programmer 15-20 years ago. They would have an aneurysm.

    • @youtubeenjoyer1743
      @youtubeenjoyer1743 3 หลายเดือนก่อน +20

      if it works, don't fix it

    • @gardian06_85
      @gardian06_85 3 หลายเดือนก่อน +51

      because people actually cared about performance, and sizes back then (when the program must fit on a 1.4 MB floppy or you have to write an installer, size of everything mattered)
      we now live in a world where with a processor, memory, and busses run 400x faster still takes the same amount of time to determine if "hte" is a word or not.

    • @berniecat8756
      @berniecat8756 3 หลายเดือนก่อน +18

      Yeah Gigabyte was not a unit of measurement back then so a 330 GB “program” is incomprehensible

    • @HrHaakon
      @HrHaakon 3 หลายเดือนก่อน

      @@berniecat8756
      In 2004? It would certainly be. We had DVDs back then which had 4.8 gigabytes.

    • @FLMKane
      @FLMKane 3 หลายเดือนก่อน +45

      Um... Guys. 20 years ago was 2004. We had multi GB games back then. And 500gb hard drives.
      Halo 2 and half life 2 came out 20 years ago

  • @zambumm
    @zambumm 3 หลายเดือนก่อน +153

    why not create an api call to chatgpt for every number?

    • @macchiato_1881
      @macchiato_1881 3 หลายเดือนก่อน +37

      What are you? Elon Musk?

    • @darekmistrz4364
      @darekmistrz4364 หลายเดือนก่อน +13

      @@macchiato_1881Tesla's co-founder and CEO. Elon is inventor and maverick entrepreneur

    • @captainace1277
      @captainace1277 หลายเดือนก่อน +3

      This is Elon Musk

    • @critamine
      @critamine 20 วันที่ผ่านมา +2

      Careful, someone might steal your startup idea!

    • @CyborusYT
      @CyborusYT วันที่ผ่านมา

      @@darekmistrz4364 lmao he did not cofound tesla

  • @eitanseri-levi2169
    @eitanseri-levi2169 3 หลายเดือนก่อน +67

    YOU MIGHT NOT LIKE IT, BUT THIS IS WHAT PEAK ENGINEERING LOOKS LIKE

    • @kormannn1
      @kormannn1 หลายเดือนก่อน +4

      Yandere sim dev style?

  • @davidboeger6766
    @davidboeger6766 3 หลายเดือนก่อน +204

    Rust Programmer: Writes 4 billion if statements.
    Rust Compiler: "Cannot use moved value. Value moved in first if statement."

    • @emeraldbonsai
      @emeraldbonsai 3 หลายเดือนก่อน

      Thats easy to solve just use python to put .clone() behind every one that will fix it

    • @zhongcena
      @zhongcena 3 หลายเดือนก่อน +36

      Integers in Rust implement Copy. Meaning they shouldn't have that problem.

    • @Codotaku
      @Codotaku 3 หลายเดือนก่อน +20

      A rust programmer would always use a match statement anyway

    • @BambeH
      @BambeH 3 หลายเดือนก่อน +14

      ​@@Codotaku time to
      match bool {
      true => { /* ... */ },
      false => { /* ... */ },
      }

    • @hanszotark5098
      @hanszotark5098 3 หลายเดือนก่อน +1

      match and enumeration with assigned discriminate value is the recipe.

  • @emjizone
    @emjizone 2 หลายเดือนก่อน +43

    3:30 *"What could go wrong?"* is really THE fundamental question that drives the entire IT industry.

  • @baranjan6969
    @baranjan6969 2 หลายเดือนก่อน +21

    My favorite compiler. Python.
    Just as Ross van der Gussom envisioned.

  • @Jadinandrews
    @Jadinandrews หลายเดือนก่อน +31

    You could achieve this by training 4 billion pigeons to peck a button if their number comes up.

  • @bransonS
    @bransonS 3 หลายเดือนก่อน +47

    Dang that’s bad….
    Ever heard of a switch statement? That’d clean that right up

    • @Tntpker
      @Tntpker หลายเดือนก่อน +11

      "The CIA wants you to think ifelse is the same as switch"
      - Terry Davis

    • @kiwikemist
      @kiwikemist หลายเดือนก่อน +1

      Switch? What are we, gay?!

  • @RobTheQuant
    @RobTheQuant 3 หลายเดือนก่อน +22

    windows leaves some of the memory mapped pages in RAM even after quitting the program. So next time you run the program, it does not have to load all of them from disk, that's the magic why it's faster than loading from the disk. On a cold start will be much slower.

    • @delta3244
      @delta3244 3 หลายเดือนก่อน +10

      (40 - 32 Gb)/800 Mb s⁻¹= 10 s, so that explains it pretty neatly.

  • @noredine
    @noredine 3 หลายเดือนก่อน +31

    I'd have a foot pedal mapped to SHIFT if i was programming DirectX

    • @darekmistrz4364
      @darekmistrz4364 หลายเดือนก่อน

      Genius

    • @Frommerman
      @Frommerman หลายเดือนก่อน

      I have left click mapped to my scroll wheel and all I do is play Old School Runescape.

    • @lancelotthefallen763
      @lancelotthefallen763 27 วันที่ผ่านมา +3

      and then they will ask you, why you only train your left leg on leg days

  • @Burgo361
    @Burgo361 3 หลายเดือนก่อน +67

    This reminds me of some advice I got at uni, if you have to jump through a lot of hoops to do something you might be doing it wrong. (paraphrasing a bit here but it applies)

    • @1DJRikkiBee
      @1DJRikkiBee 3 หลายเดือนก่อน +41

      True, unless you're trying to win a hoop jumping competition.

    • @robonator2945
      @robonator2945 3 หลายเดือนก่อน +7

      Borrow Checker : "Finally, someone who appreciates my work!"

    • @robonator2945
      @robonator2945 2 หลายเดือนก่อน +1

      ​@@nathanielalderson9111 and I'm sure your users will appreciate that explanation when your software doesn't work because 'well the API to do the thing I'm trying to do is made in a way I find inconvenient, so until they refactor it how I want I'm not making anything'
      You can either complain about the world being imperfect or put in the work to make it better. You are the only variable that you can control, blaming external factors can't solve much of anything but it can break a hell of a lot. Sure, you *can* give european politicians the right to dictate the hardware on the devices you (and everyone else) are allowed to buy, or you can just stop buying from Apple - which of those routes has more knock-on cobras?

    • @robonator2945
      @robonator2945 2 หลายเดือนก่อน

      ​@@nathanielalderson9111 because the lifepsan of the joke is shorter than the length of time we've been churning out shitty sub-par software and it's quite hard to keep laughing all the while you keep getting kicked in the balls because it's always [someone-else]'s fault.
      More generally because this 'I'll just force the rest of the world to change because I know I'm right and don't need to rethink anything' philosophy is just plain really fucking annoying. Once yesterday's parody becomes today's philosophy it's kinda hard to laugh at the parody anymore.

    • @nathanielalderson9111
      @nathanielalderson9111 2 หลายเดือนก่อน

      @@robonator2945 good grief man!
      Go away! Go take your bitterness and harshness elsewhere.
      No, seriously. Go get some therapy. Programming is always going to be a headache, and it really sounds like you either need to deal with some heavy stuff, or find a way to let it go.
      Aggressively attacking (with words) a random on the net just shows me that you also have the attitude of "I'll change the world because I'm right" attitude that you seem to think I have, from a freaky dumb joke.
      Go kick rocks.

  • @noobrebuilder8260
    @noobrebuilder8260 29 วันที่ผ่านมา +8

    Average YandereDev script

  • @iyziejane
    @iyziejane 2 หลายเดือนก่อน +25

    In 5-10 years the compiler will notice that you could optimize all this with a mod function. He's just ahead of his time.

    • @Sandromatic
      @Sandromatic 28 วันที่ผ่านมา +3

      Ah but optimization was turned off. I wonder if the compiler *actually would* notice if optimization *was* turned on.

  • @thingsiplay
    @thingsiplay 3 หลายเดือนก่อน +52

    What a Chad.
    Hats off, my dude.

  • @1thevm1
    @1thevm1 3 หลายเดือนก่อน +10

    From the title I thought we'd be reviewing YandereDev's code lmfao

  • @wolverine9632
    @wolverine9632 3 หลายเดือนก่อน +16

    Amazing solution! Now we just need a JS version so we can add this to npm!

  • @rave400v6
    @rave400v6 หลายเดือนก่อน +4

    "And they call me a madman."
    "Who created 4 billions if statements. "
    "I'm a survivor. "

  • @privacyvalued4134
    @privacyvalued4134 3 หลายเดือนก่อน +6

    The 4GB file size limitation in the Windows PE file format is an artifact of its design and also how the Windows loader handles loading binary files. However, you can load multiple EXEs and DLLs into main memory that are each up to 4GB in size. The Windows loader performs a LOT of work when it loads a PE file into memory, including spending time remapping addresses in the code section so that the code inside executes properly. So to get it to compile, they could have broken up the file into multiple 4GB DLLs and then...loaded all of them with each one dependent upon the next one.

  • @janbrtka4322
    @janbrtka4322 3 หลายเดือนก่อน +9

    The logical evolution of this program would be, to publish it as a npm library which uses performant C library under the hood. I'd bet it would get 100k+ downloads within a year - if we figure out a nice, short and catchy name for it!

    • @HrHaakon
      @HrHaakon 3 หลายเดือนก่อน +7

      StEven.
      Saint Even, written by Steven,
      answer the holy question: Is this thing even?

  • @estranhokonsta
    @estranhokonsta 2 หลายเดือนก่อน +1

    Wow. That was fun. Reminded me of what programming was all about when i was younger. That guy deserves respect.

  • @CCCW
    @CCCW 3 หลายเดือนก่อน +16

    this is absolutely deranged, and I mean in in the best possible way. I love it

    • @darekmistrz4364
      @darekmistrz4364 หลายเดือนก่อน +1

      Pushing the limits of computing!

  • @Cethris
    @Cethris 3 หลายเดือนก่อน +8

    That article is a work of art

  • @Sancarn
    @Sancarn 3 หลายเดือนก่อน +9

    0:28 You should see some of the code I've seen in our core business critical systems...

  • @OneEyeShadow
    @OneEyeShadow 5 วันที่ผ่านมา +1

    I like the idea that at the end of it all there's some variation of
    "else: return x%2==0"
    Just in case there are any numbers not covered by the 4gb if statement.

  • @peterbonnema8913
    @peterbonnema8913 3 หลายเดือนก่อน +24

    Imagine the CPU franticly trying to pre-execute all those alternative code paths right from the start.

    • @Jason9637
      @Jason9637 หลายเดือนก่อน +2

      No need to pre execute, it's comparing a register with an immediate, so there is nothing to wait for, the only limitation should be how fast the CPU can load the code

    • @FLMKane
      @FLMKane หลายเดือนก่อน

      @@Jason9637 my dude. Most of us don't understand assembly so most wouldn't be able to predict that.
      But that means with 4 billion comparisons, there are 4 billion data chunks to compare, and assuming they're all integers that should mean each input for comparison is 4 bytes.
      That means 4 billion comparisons would result in 16 gigabytes of data flow through the CPU, which means you'd better have a lot of ram. I'm not even going to bother thinking about floats or strings

    • @Jason9637
      @Jason9637 หลายเดือนก่อน

      @@FLMKane That's not at all how this works. The CPU doesn't need to store every value in system memory then wait for it. Maybe it would be helpful to learn the basics of assembly (it's really not that hard)

  • @moharexx3128
    @moharexx3128 2 หลายเดือนก่อน +3

    still faster than python

  • @kwisin1337
    @kwisin1337 3 หลายเดือนก่อน

    I needed this! Thank you❤❤😂😂😂😂

  • @MarcCastellsBallesta
    @MarcCastellsBallesta 3 หลายเดือนก่อน +2

    Loving these challenges!

  • @energistixgames6067
    @energistixgames6067 27 วันที่ผ่านมา +1

    I love how those programs that generate the code to check if the number is odd or even, always have a "x % 2 == 0" somewhere

  • @nox5282
    @nox5282 3 หลายเดือนก่อน +7

    I’m ashamed to say, it took me a few rewatches until I grasped every step in this article.

    • @darekmistrz4364
      @darekmistrz4364 หลายเดือนก่อน +1

      Most important is that you enjoyed it (probably?)

  • @sergokovaltsov3427
    @sergokovaltsov3427 3 หลายเดือนก่อน +11

    That's some NPM worthy algorithm. Hats off

    • @Tobsson
      @Tobsson 3 หลายเดือนก่อน +4

      Couldnt stop thinking that finding this as an npm package would not seem unimaginable to me.

  • @chrisclark5746
    @chrisclark5746 หลายเดือนก่อน

    Laughed so hard I almost snorted my coffee :-) classic episode, thanks again primeagen

  • @whiskeytuesday
    @whiskeytuesday 3 หลายเดือนก่อน +8

    Why are we calling Guido van Rossum Ross van der Gussom? Is this a meme i missed?

  • @lxmcf
    @lxmcf 3 หลายเดือนก่อน +2

    The person who rote the article woke up and chose violence with no witnesses, 11/10

  • @hodayfa000h
    @hodayfa000h 3 หลายเดือนก่อน +24

    This code is STILL more efficient than the code game devs make today

  • @niks660097
    @niks660097 18 ชั่วโมงที่ผ่านมา

    7:28 WIN32 and their handles, messages, dwords was designed by a polish engineer who first introduced the idea of dynamically defining APIs with just prefixes.

  • @Jake9066
    @Jake9066 3 หลายเดือนก่อน +16

    Here I was thinking an "is-even" would be done well enough just by returning the inverse of the final bit of the number.
    This is so much better!

  • @fernabianer1898
    @fernabianer1898 3 หลายเดือนก่อน

    this made me laugh so hard, thank you sir! : D

  • @markusjohansson6245
    @markusjohansson6245 2 หลายเดือนก่อน

    Funny ;-)
    Reminds me when I started to learn to program using the manual for C64 back in the days. I wrote a text-based adventure game using like only if, goto, print and input. Storage took up two sides of a cassette tape and the game wasnt long at all. Nevermind that when you played you had to type in the exact correct string to move on in the game.

  • @thygrrr
    @thygrrr 3 หลายเดือนก่อน +18

    I think you could short-circuit this and jump directly to the address where the comparison for the input number is done.
    Then, you can pre-compute the result.
    Then, you can pack this, because the result is always just a bit.
    PROFIT!

    • @Oler-yx7xj
      @Oler-yx7xj 3 หลายเดือนก่อน +13

      This is essentially a lookup table, which is essentially a switch-statement, which is definitely not 4 billion if-statements

    • @aeghohloechu5022
      @aeghohloechu5022 3 หลายเดือนก่อน +9

      The thing is that he specifically turned off all optimisations, otherwise the if blocks would have gotten compiled down to jump tables

  • @AxidoDE
    @AxidoDE 2 หลายเดือนก่อน +2

    And now we just need another 4 Billion of these and another function that determines which of them to use to get a universal modulo function. It's just that easy.

  • @grex2595
    @grex2595 3 หลายเดือนก่อน

    Modified this for fun. Did a while loop with with a fll where the odd node pointed to the even node and vice versa and just moved to the next node and added one if the number didn't match. Not as impressive, but still a fun way to do it in the spirit of doing almost no math.

  • @EvgenyVinnik
    @EvgenyVinnik 3 หลายเดือนก่อน

    this is a fantastic video!

  • @aidynladouceur8369
    @aidynladouceur8369 หลายเดือนก่อน

    This might be my new favorite piece of programming media ever

  • @darkquaesar2460
    @darkquaesar2460 หลายเดือนก่อน

    This is the funniest goddamn thing i've seen all week. People don't even know how efficient if statements are compared to switch statements or even if else statements.

  • @nanachris5559
    @nanachris5559 10 วันที่ผ่านมา

    You also wrote a program like this once and that's one thing beautiful about learning how to program.

  • @KrisRogos
    @KrisRogos 3 หลายเดือนก่อน +2

    I strongly suspect the speed came from the CPU's branch prediction. After a few iterations, it would realise all previous cases are false and start pre-loading page after page of the code for the false paths only. Eventually, when the correct number rolled around, it would be true and, therefore, a prediction miss, but it only needs to go back and re-evaluate the true branch once and then quit the program.

  • @mahidulislamzihan7760
    @mahidulislamzihan7760 3 หลายเดือนก่อน

    This is pure madness. I like it 🤣

  • @alienrenders
    @alienrenders 3 หลายเดือนก่อน

    This is beautiful!

  • @mzhvis
    @mzhvis 3 หลายเดือนก่อน +11

    "This is where the machines can rise up" 😂

  • @alexander-yermolenko
    @alexander-yermolenko 3 หลายเดือนก่อน

    I am just new in programming(start in the end of 2022 with C++, and now from November 2023 use C#), but that sounds so crazy😵

  • @havannaonana4554
    @havannaonana4554 3 หลายเดือนก่อน +47

    Aint no way even as a beginner i ain't writing that much if statements. Too lazy

    • @jerichaux9219
      @jerichaux9219 3 หลายเดือนก่อน +13

      If you wrote one entire if statement per second, it would take you 138 years.

    • @FlorianWendelborn
      @FlorianWendelborn 3 หลายเดือนก่อน

      @@jerichaux9219 that’s a short time to finally solve isEven

    • @PristinePerceptions
      @PristinePerceptions 3 หลายเดือนก่อน +7

      You write a program to generate the program. Simple 🙂

    • @prukenope
      @prukenope 3 หลายเดือนก่อน +3

      You come the right way. If you're lazy, you can make a great code lol

  • @Kuratius
    @Kuratius หลายเดือนก่อน +1

    You don't even need modulo for this. Bit mask the input with bit wise & 1 and checking if it's >0 works.
    Probably faster than running the division instruction that gets run when you do a modulo operation.

    • @williamdrum9899
      @williamdrum9899 3 วันที่ผ่านมา

      That's how modulo is actually implemented- bitwise ands for powers of 2 and "magic number" multiplication for the rest

  • @NeunEinser
    @NeunEinser 3 หลายเดือนก่อน

    This is amazing

  • @HrHaakon
    @HrHaakon 3 หลายเดือนก่อน

    This is much better than bitmasking the int, and using that as a boolean. I am truly humbled by this genius gigachad.

  • @piotrprs572
    @piotrprs572 หลายเดือนก่อน

    it's OS 'magic'.. that jump multiple block of mapped memory, to find a proper one. Mapped file is used by Memory Manager and split into blocks to fast access.
    Also ALL 'if' are linear, so system can do proper predictions. It will take much... much longer if this "if"s ware more random.

  • @averytheloftier
    @averytheloftier 3 หลายเดือนก่อน

    having not yet finished the video I think the solution to the line limit problem is fairly obvious. make separate executables for each possible number. convert the number to a string and then call the file associated with that number.

  • @alexeyklepikov2770
    @alexeyklepikov2770 3 หลายเดือนก่อน +6

    These articles are so fun and very well written compared to the geniuses at the ny post who came up with such bangers as “Reddit user praised after refusing to swap airplane seats with pregnant woman”

  • @GRHmedia
    @GRHmedia 20 วันที่ผ่านมา

    Hmm, I think we can go larger, we use compression to store the machine code pull out the section we need and set the instruction pointer to it. What could go wrong. Or maybe we could generate the next if statement at the end of the last one.

  • @VodShod
    @VodShod 13 วันที่ผ่านมา

    7:25 I think you should get a pedal that you can map to a specific button like caps lock and/or shift, that way you are not causing problems with your hands. After all your feet are just laying around being lazy.

  • @MaybeADragon
    @MaybeADragon 3 หลายเดือนก่อน +1

    Tried to do this in Rust with a 4 billion item long match statement that covered the entirety of u32, sadly I do not have enough ram or knowhow to get that working. Macros let you get around the whole 4gb file size limit but that's my limit.
    However with u16 it took something like 200ns to work out if a number was odd or even.

    • @Aidiakapi
      @Aidiakapi 3 หลายเดือนก่อน

      No language feature can let you get around the 4GB limit of .exe files. That's just a Windows limitation.

  • @adamrak7560
    @adamrak7560 3 หลายเดือนก่อน +1

    You all laugh at this, but some form of this is actually _really_ highly performant for ab-initio quantum chemistry.
    It has really complicated numerical algorithms for the integrator, which if unrolled may be gigabytes of code, but the unrolled code runs on GPU an order of magnitude faster.

  • @RaylaRayV
    @RaylaRayV 19 วันที่ผ่านมา

    dude i need MORE from this Blabbin' guy! I can't believe he hasnt got more posts up fuck he's funny

  • @bug5654
    @bug5654 หลายเดือนก่อน

    Reminds me of making PHP code that wrote javascript functions for each column dynamically based on the type of column because javascript didn't like polymorphic sorts.

  • @waperboy
    @waperboy 29 วันที่ผ่านมา

    Once worked with guy, we were supposed to convert data to a flexible third-party api, and different customers had different needs. He started coding, and his approach was code with lots and lots of if-statements. I had to step in and build a more abstract per-customer configurable solution that didn't involve hundreds of if-statements per customer.
    But I'm sorry I had to watch this to the end... :-/

  • @Berzeger
    @Berzeger 3 หลายเดือนก่อน

    The pronuciation of strtoul was spot on :D

  • @RushSho
    @RushSho 18 วันที่ผ่านมา

    I loved to pratice string manipulation without saving the results in a variable. If I need the result I had to rewrite the whole code again and again and again😂

  • @jabuci
    @jabuci 3 หลายเดือนก่อน

    The funny thing is that in the latest code generator he uses the modulo operator :)

  • @zeo4481
    @zeo4481 หลายเดือนก่อน +1

    Imagine if we used that compiling power to check any useful info instead of odd and even numbers 😢

  • @DomskiPlays
    @DomskiPlays 3 หลายเดือนก่อน

    Respect for going through that whole ordeal tho

  • @NathanaelNewton
    @NathanaelNewton หลายเดือนก่อน

    This is pure genius

  • @tutacat
    @tutacat 3 หลายเดือนก่อน

    When dealing with python nesting limitations, all you need to do is believe. Convert it to single if statements, when when Python still says no, write your own mapping python interpreter in C (or python)

  • @georgecop9538
    @georgecop9538 3 หลายเดือนก่อน

    6:14 We need long long long(or int128_t I suppose). what exfat and ntfs, if an fs could support 2 ^ 128 - 1 bytes/blocks/etc. then it's next level

  • @danielvest9602
    @danielvest9602 13 วันที่ผ่านมา

    I was actually naive enough to attempt something like this. Around 1992 I began learning C. My only experience before this was with gwbasic. I wanted to display a bit maped picture and wrote a basic program to create a C source that was just a bunch putpixel calls, one for each pixel of a 640x480 image.

  • @sadikkadom9566
    @sadikkadom9566 3 หลายเดือนก่อน

    Just a have lookup table for that if statement. It'll greatly reduce the waiting.

  • @sjinja4321
    @sjinja4321 หลายเดือนก่อน

    This one made my day 😂😂

  • @Time-yo5mw
    @Time-yo5mw 29 วันที่ผ่านมา

    i just started learning python the other day.... shouldn't you be able to use bitwise comparison and if the final bit is 1 its odd and if its 0 its even?

  • @user-uo1yn4se8r
    @user-uo1yn4se8r 17 วันที่ผ่านมา

    for the problem you mentioned at 7:25 - consider getting a shift key foot pedal.

  • @rubansrirambabu7771
    @rubansrirambabu7771 4 วันที่ผ่านมา

    "Can we have O(1) code mom?"
    Mom: "We have O(1) code at home"
    The O(1) code:

  • @ThrowTop
    @ThrowTop 3 หลายเดือนก่อน +1

    most interesting 10 minutes of 2024

  • @imblackmagic1209
    @imblackmagic1209 2 หลายเดือนก่อน

    i would've tried to make multiple dlls to call from the main program, so we check every number every time, just in case, one can never be too sure

  • @BusinessWolf1
    @BusinessWolf1 24 วันที่ผ่านมา

    Say what you will about deoptimization but it's allowing us to make a whole lot of technology. And we're also looking backward and optimizing ground-up whilst keeping the knowledge of what's possible which we gained by shipping to production on save, and saving on alt tab.

  • @francoisdujardin874
    @francoisdujardin874 3 หลายเดือนก่อน

    I see a few ways to optimize this a little bit further:
    1. make it multi threaded and run it on a 32 core CPU.
    2. implement it as a compute shader and take advantage of the massively parallel design of GPUs. Get an NVidia RTX 4090 to run the program.
    3. take advantage of the cloud. Create a website where users can enter any number, and have each request processed on a bunch of AWS machines.
    4. the ultimiate solution would be to have it implemented directly in specialized hardware (remove one core of those intel CPUs, we don't need that many, and replace it with a 4B-gates dedicated even/odd detector).

  • @TheCheD3
    @TheCheD3 3 หลายเดือนก่อน

    Thank you study time. Mvp of the video and maybe the whole stream

  • @da40au40
    @da40au40 2 หลายเดือนก่อน

    1:47 😂. the way he said what he said gives me chills.... this guy is the coldest and most badass TH-camr😂

  • @IanMcLerran
    @IanMcLerran 3 หลายเดือนก่อน

    Oh my goodness, I just died!! 😂🤣😂🤣👏👏👏