Making 4 Billion If Statements For Some Reason...

  Рет қаралды 292,066

Theo - t3․gg

Theo - t3․gg

5 ай бұрын

What if we implemented isEven the hard way? What a wild journey this was. From C to Python to Assembly...I am genuinely impressed by the chaos on display.
SOURCES
andreasjhkarlsson.github.io//...
Check out my Twitch, Twitter, Discord more at t3.gg
S/O Ph4se0n3 for the awesome edit 🙏

Пікірлер: 647
@flamakespark
@flamakespark 5 ай бұрын
Programmer in 1969: I need only 72KB to send astronauts to the Moon Programmers in 2024: I need only 30GB to check if the number is even
@RedVio972
@RedVio972 5 ай бұрын
Programmers in 1960s: We're NAND gating out of Earth with this one
@spicybaguette7706
@spicybaguette7706 5 ай бұрын
​​@@RedVio972The AGC is legitimately mind-blowing. It even had a software VM for a machine language to do the linear algebra required for heading calculations (kind of like the JVM but in the sixties, Apollo engineers were truly wild)
@user72974
@user72974 5 ай бұрын
Now, now, no need to exaggerate. You're an order magnitude off. The number checking program was 330 GB, not 30 GB.
@Wyld1one
@Wyld1one 5 ай бұрын
Charles Moore (creator of the FORTH programming language) all I need is 1K for the operating system. Maybe 12-14 bytes for the program
@rahulshah1408
@rahulshah1408 5 ай бұрын
The 72kb moved the slide rule back and forth.
@xBiggs
@xBiggs 5 ай бұрын
Can't wait for Yandere dev to install this package
@t3dotgg
@t3dotgg 5 ай бұрын
I hate that I get this reference
@captainplasma1012
@captainplasma1012 5 ай бұрын
didn't he literally do the exact same thing? with a clock or smth
@Nessie14
@Nessie14 5 ай бұрын
Don't think I get it~ 😅
@FireSiku
@FireSiku 5 ай бұрын
@@Nessie14 YanDev is infamous for having written some of the worst code in teh gaming industry. For example, Instead of having a logical event handler for the many things that could happen in their game, it's just a GIANT IF/ELSE block
@potatoheadpokemario1931
@potatoheadpokemario1931 5 ай бұрын
​@@FireSikuand not only that, he'll refuse any help and insists he'll clean it up when he's done, but the longer it goes like that the harder it'll be to clean up, eventually he might as well make a new game
@SandTurtle
@SandTurtle 5 ай бұрын
i love the pure irony of putting "if i % 2 = 0" to generate this
@flameofthephoenix8395
@flameofthephoenix8395 5 ай бұрын
Yes, he used a lesser thing to make a greater one.
@qsquared8833
@qsquared8833 5 ай бұрын
​@@flameofthephoenix8395that depends on your definition of lesser and greater
@whohan779
@whohan779 5 ай бұрын
The even worse irony is that you don't even need modulo for this. Assuming your base dimension is even, you can do the check for the last digit only. Here is my entire codeframe (&yes, I'm aware this video is intentional gore and can be 'solved' by checking for the last bit only): #include //the program wants to talk #include //technically superfluous if you check for termination (see below) int main(int argc, char* argv[]){ //the main function needs arguments (and their count) for (short i=1; i
@fal4770
@fal4770 5 ай бұрын
​@@whohan779 You're right about only needing the final bit but all you need to do is a bitwise AND with 0x1 unless there's something I'm missing with this approach: #include int main(int argc, char* argv[]) { if (argc < 2) { fprintf(stderr, "No input number given!"); return -1; //can't be bothered to check all invalid inputs rn lol } int number = atoi(argv[1]); if (number & 0x1) { printf("%d is odd.", number); } else { printf"%d is even.", number); } return 0; }
@qsquared8833
@qsquared8833 5 ай бұрын
@@whohan779 my dude, you would never do this, it would be easiest to return the value of the last bit in the integer as a bool It's value of true means odd, and false means even.
@pavolkomlos3343
@pavolkomlos3343 5 ай бұрын
Might be a good idea to optimize this by doing a binary search to find the correct if statement.
@volodyanarchist
@volodyanarchist 5 ай бұрын
But... the binary search needs the division operation, and i think we can implement it thusly: uint32_t divide(uint32_t a, uint32_t b, uint32_t potentialResult=0) { if(potentialResult*b >= a) return potentialResult; return divide(a, b, potentialResult+1); }
@Avighna
@Avighna 5 ай бұрын
Smart!
@igotnoname4557
@igotnoname4557 5 ай бұрын
Definitely! Then you can offload the work to a cluster to take care of the heavy lifting.
@pacomatic9833
@pacomatic9833 5 ай бұрын
...or don't use if statements. Ah wait, this is crackhouse, how about we use IF statements to find which statement?
@Guhlius
@Guhlius 5 ай бұрын
Second function starting at the highest number going down, add wrapper with bool to indicate if number is propably big, half execution time
@nikilk
@nikilk 5 ай бұрын
Imagine the tech lead explaining to the CFO, of why they need quarter a million dollars of cloud funding because of this new crazy even/odd algorithm the crack dev team came up with.
@MrLordLowbob
@MrLordLowbob 5 ай бұрын
move it to the edge!
@photoniccannon2117
@photoniccannon2117 5 ай бұрын
Show this to the KZfaqr “tech lead” (who admitted to lying about being a former Google tech lead) and watch him try to figure it out. 😂
@rahulshah1408
@rahulshah1408 5 ай бұрын
I’ve worked at a shop that refused to add indexes to the oracle exadata database. They were forcing the issue to purchase in-memory licensing. A million dollar solution before trying the free one.
@photoniccannon2117
@photoniccannon2117 5 ай бұрын
​@@rahulshah1408 That's... amazing. Was it the shop's idea to do this on purpose? Knowing Oracle, they were probably quite pleased.
@davidmartin8089
@davidmartin8089 5 ай бұрын
more like dev team on crack haha
@MelkeyDev
@MelkeyDev 5 ай бұрын
Wait.. so im NOT supposed to have 4 billion if statements..?
@t3dotgg
@t3dotgg 5 ай бұрын
No more than 2.5 billion in go :(
@user-pl9xu5sd5x
@user-pl9xu5sd5x 5 ай бұрын
It's actually using a switch statement would improve performance.
@rohit-gupta
@rohit-gupta 5 ай бұрын
a hashmap of numberboolean would have been faster but not sure about memory
@maxz999
@maxz999 5 ай бұрын
@@rohit-guptaarray of length 4 billion?
@beck4715
@beck4715 5 ай бұрын
​@@t3dotgg3/4 of that would be error handling so closer to 625 million
@joppekoers3992
@joppekoers3992 5 ай бұрын
Of course we need 64 bit numbers. For storing the amount of build warings I get for example
@JetJockey87
@JetJockey87 5 ай бұрын
4,200,000,000 warnings but no errors, if it's good enough for the compiler it's good enough for me. Ship it to prod
@whohan779
@whohan779 5 ай бұрын
@@JetJockey87 For real though: while just building a program that checks the last digit for oddity as a joke I know probably now most of the warnings and errors and can vouch that most of them are valid and deserved.
@Eyeclops_
@Eyeclops_ 5 ай бұрын
I'm a graduate student, and this reminds me of an assignment I had gotten for a class I TA'd a few years back. The assignment was an assembler for a slimmed down version of MIPS that would convert instructions from their assembly representation to a binary representation. Since the instructions were small enough and it was simply a conversion, it took most students around 130 - 200 lines of code to get it up and running. It was basically done in two passes. Converting simple instructions in one of the passes, and the other to resolve labels. One student submitted an 15000 line C program that was a single while loop in main which attempted to exhaustively read in every possible input into the program and convert it into binary. It had no comments, all variables were in a single array, and there were no functions aside from main. Not only did it not work with labels (since offsets for labels you haven't seen can't be calculated without a second pass) and it did not output anything remotely correct, it somehow managed to delete all of my test input files in the process. That student got no points anywhere, aside from the "effort" category, because while they sure didn't work smart, they definitely worked hard.
@minerscale
@minerscale 5 ай бұрын
Did you run the program and then read it or did you read the code and then decided it would be a good idea to run it? :P I'd hide malware on line 8,500.
@rickquackstley
@rickquackstley 5 ай бұрын
@@minerscale8543
@Wyld1one
@Wyld1one 5 ай бұрын
All I had one of those group projects once we were supposed to each do a specific chunk of the code merge them together and then compile the result. Had one of the people who didn't understand recursion totally rewrite my code which wasn't his job. The project was for a simple calculator. Where you would put it in an equation and it would spit out the answer. We're just talking plus minus times divides no higher functions at all. Well my simple recursive solution was about a page of code. His rewrite took over 20 ft of paper to print out. I refused to take that so I submitted my solution to the teacher as well saying that wasn't my code. I passed with an A
@minerscale
@minerscale 5 ай бұрын
@@Wyld1one was the recursion for processing brackets? That's like the poster child for recursion is it not!
@heikkiaho6605
@heikkiaho6605 5 ай бұрын
sounds like me XD
@theaninova
@theaninova 5 ай бұрын
Have a file with 2^32 bytes alternating between 0-1 Compress the file with gzip to practically zero size Have the program load and unpack the file Use the input as a memory address
@photoniccannon2117
@photoniccannon2117 5 ай бұрын
I’m gonna try this just for the heck of it. 😂
@nextgenstudios335
@nextgenstudios335 5 ай бұрын
@@photoniccannon2117 post the results 👀I HAVE to know now
@photoniccannon2117
@photoniccannon2117 5 ай бұрын
@@nextgenstudios335 See I was thinking about how to do this. Here is problem number 1: I literally don’t have a drive large enough to store the file with the code (I have a hard drive, but that’s way too slow). So I need to get a gigantic SSD first (or find a way to clear space on my Mac). I think the latter is manageable, so we will see.
@flameofthephoenix8395
@flameofthephoenix8395 5 ай бұрын
Should be able to split it into more than one file to avoid having to decompress too much at once.
@decycle2912
@decycle2912 5 ай бұрын
the file size is only a gb without compression!
@otter502
@otter502 5 ай бұрын
8:58 the comedy of using the modulus operator to code a program to replace the modulus operator
@jsonkody
@jsonkody 5 ай бұрын
world would be much better place if every math function would be implemented in such elegant way
@simono.899
@simono.899 5 ай бұрын
A function to add two values with convoluted switch statements to account for all combinations
@VivekYadav-ds8oz
@VivekYadav-ds8oz 5 ай бұрын
hell yeah. Imagine how faster computers will be when we can throw away all the ALUs and just lookup the answer for any calculation in a lookup table!
@Ultrajuiced
@Ultrajuiced 5 ай бұрын
Clear and concise.
@AnsisPlepis
@AnsisPlepis 5 ай бұрын
If only pi was a function that computed it with the odd reciprocal formula at runtime
@hungrymusicwolf
@hungrymusicwolf 5 ай бұрын
@@simono.899Now that would be a sight to see.
@astral6749
@astral6749 5 ай бұрын
When he reached the compiler part, I thought he's just gonna make python output an assembly file then use an assembler to turn it into a binary. I wasn't expecting him to write the binary directly. lol
@fltfathin
@fltfathin 5 ай бұрын
First time i understand how things actually work it is kinda dumb that toolchains got so scary for me
@volodyanarchist
@volodyanarchist 5 ай бұрын
I was expecting him to remove new line characters from the file, this way it was just one line...
@finminder2928
@finminder2928 5 ай бұрын
Would removing beeline characters from the file actually work?
@volodyanarchist
@volodyanarchist 5 ай бұрын
@@finminder2928 C separates commands with ; it treats new-line as any other space. Exception is precompile directives, so a couple of includes would have to be on the line of their own.
@moistness482
@moistness482 5 ай бұрын
Time to call this as a new process each time I check if a number is even
@TomNook.
@TomNook. 5 ай бұрын
"a very thick c file" Thicccc. Missed opportunity
@Exilum
@Exilum 5 ай бұрын
The even funnier thing is you can probably optimize it by hardcoding using binary search. The file would be even bigger but I wouldn't be surprised if it was faster, considering the main bottleneck at that point is the reading speed.
@OMGclueless
@OMGclueless 5 ай бұрын
Binary search is unnecessary. Can just index directly into the right memory location.
@Exilum
@Exilum 5 ай бұрын
@@OMGclueless Isn't not counting the time spent building an index cheating? And if you do it from a file, then there's still the same issue of file reading speed. If it is counted and still is faster, it's pretty much functionally equivalent to avoiding the self-imposed problem rather than trying to solve it as you go from 4 billion conditions with jumps to read to... 4 billion references in an index. If you use indexing to 'turn' it into a single condition leading to the right condition, then the 4 billion conditions aren't used, so it's cheating as well. Binary search has the advantage of hypothetically being able to use all conditions in two calls. Using all conditions in 4 billion calls seems a bit *too* spread out to not be cheating your way out.
@OMGclueless
@OMGclueless 5 ай бұрын
​@@Exilum Mapping a file into memory is a constant-time operation: just setting up a page mapping in the OS. Jumping into the middle of the file and reading the answer there is also a constant time operation, it takes a single page fault to go read the file from disk and map the page you accessed into memory (this step technically takes log time, most likely, since the file's blocks are probably stored in a structure like a btree). Creating the file takes a long time, of course, but you only do it once and then can answer as many queries as you like with no extra work. Re: binary search vs indexing. I think if one is allowed they both are allowed. log(n) operations to find the right answer and 1 operation to find the right answer are both skipping billions of comparisons so both are cheating by just about as much.
@Exilum
@Exilum 5 ай бұрын
@@OMGclueless Hmm, I see your point. I still think think they're far from cheating equally.
@OMGclueless
@OMGclueless 5 ай бұрын
@@Exilum Well, look at it this way, binary search skips ~2 billion - 32 comparisons, while indexing skips ~2 billion - 1 comparisons, so the amount of cheating is pretty close :D
@Remiwi-bp6nw
@Remiwi-bp6nw 5 ай бұрын
That's so interesting that you have that trauma with Assembly, because when I took that equivalent class the compiler/runtime was my favorite thing! I even made a slightly different one again the summer after that class ended lol
@smallfox8623
@smallfox8623 5 ай бұрын
Same the compiler class I took was my favorite and I learned so much about programming in that one class. The assembly class which was separate was my 2nd favorite 😊
@BrandonVout
@BrandonVout 5 ай бұрын
I have a lot of nostalgia for PIC assembly. I wouldn't do it again but it was a lot of fun. VHDL too.
@keineahnung2339
@keineahnung2339 5 ай бұрын
I have an even bigger idea: return 1 or 0 instead of even or odd. Then we have implemented the mod operator for 2 (number mod 2) so we execute that program with all the 2^32-2 numbers and we have implemented the whole mod operator. I have heard that AWS S3 has enough storage for a program this huge
@williamdrum9899
@williamdrum9899 5 ай бұрын
That's ridiculous. What's next? Using bit rotates and carry flags? Poppycock!
@Sandromatic
@Sandromatic 2 ай бұрын
That's actually what the assembly version does by the looks of things, so there you go. :P
@martini9388
@martini9388 5 ай бұрын
This is pure gold. Ty you made my day
@Slashx92
@Slashx92 5 ай бұрын
I love the "fully functioning and PERFORMANT program" in the conclussion, just after mentioning that the program can take up to 10 seconds to give a response LMAO
@HippieInHeart
@HippieInHeart 4 ай бұрын
It takes only 10 seconds at most, I'd say that is extremely performant and efficient. He's done a very good job. XD
@steves9250
@steves9250 5 ай бұрын
Next option would be to code each if statement into its own executable and call it dynamically😂
@NeroDefogger
@NeroDefogger 4 ай бұрын
reading that gave me nausea... I love it...
@dreamecho100
@dreamecho100 5 ай бұрын
Package and ship it to npm
@codetoil
@codetoil 5 ай бұрын
npm is a javascript/typescript package manager. The code was written in c(++) and assembly.
@Slashx92
@Slashx92 5 ай бұрын
@@codetoil package it as a node script that executes the original program
@spicybaguette7706
@spicybaguette7706 5 ай бұрын
​@@codetoilwe just need to modify it to produce a 30gb wasm file instead
@minerscale
@minerscale 5 ай бұрын
@@codetoil just write an x86 interpreter in javascript and ship the bin as a blob.
@volodyanarchist
@volodyanarchist 5 ай бұрын
@@codetoilI volunteer you to write a wrapper for it.
@omkelderman
@omkelderman 5 ай бұрын
I remember reading that blogpost a while back, absolutely amazing work. One thing I kinda hoped for what didnt happen was instead of writing that asm to bin madness and then loading it as a memory mapped file and executing a function pointer, I hoped he would output it as an object file that he then could reference in his main.c file and link together with an actual linker. But this was also pretty fun xd
@TurtleKwitty
@TurtleKwitty 5 ай бұрын
the linker would run into the 4gb limit though no?
@omkelderman
@omkelderman 5 ай бұрын
@@TurtleKwitty uuuh, good point lol, honestly no idea
@EddyVinck
@EddyVinck 5 ай бұрын
Looks like an O(1) algorithm Prime would be proud
@user-hv4nl9rn8t
@user-hv4nl9rn8t 3 ай бұрын
Wouldn’t it be O(N)?
@polygontower
@polygontower 2 ай бұрын
@@user-hv4nl9rn8t You seem to be conflating 'if' with 'else if'. If statements don't terminate once one outputs True, logically. That's what else ifs do, hence the name, 'else, if......., then .........'
@photoniccannon2117
@photoniccannon2117 5 ай бұрын
It’d be torture if this was written in such a way as to purposefully hint at the branch predictors to mispredict it at every branch. It would take hours instead of seconds and force the pipeline to be flushed on every single if statement!
@KontarAlt
@KontarAlt 5 ай бұрын
This is the most fun ive had watching a video in *years*
@gomi-hako
@gomi-hako 5 ай бұрын
Actually I've needed a bigger number than 64 bits for my number conversion program from japanese to our numeral system, where the biggest power of then is 一千無量大数 = 1E71. Even 128 bit didn't cut it.
@Xudmud
@Xudmud 5 ай бұрын
Why stop there? At that point couldn't you easily do 九万九千九百九十九無量大数, just to add more bits to account for? (now I really want to try and see how long that number would be written out)
@gomi-hako
@gomi-hako 5 ай бұрын
@@Xudmud In the scale used currently 中数(万進) that's not possible. For every big power you can only go up to 千(10^3) since these powers increment like this: 4, 8, 12 ... 68. Maybe with the 中数(万万進) scale, but with the notation of this scale I am not really familiar. 三千三百三十三無量大数三千三百三十三不可思議三千三百三十三那由他三千三百三十三阿僧祇三千三百三十三恒河沙三千三百三十三極三千三百三十三載三千三百三十三正三千三百三十三澗三千三百三十三溝三千三百三十三穰三千三百三十三𥝱三千三百三十三垓三千三百三十三京三千三百三十三兆三千三百三十三億三千三百三十三万三千三百三十三
@Xudmud
@Xudmud 5 ай бұрын
@@gomi-hako Whoops, I knew it was 10^3 per but miscounted where that ends up at. (been long enough since I took Japanese and I'm too used to working with 10^2 per big power). So I guess 九千九百九十九無量大数... would be the highest? (it'd add another two or three bits to the numeric value)
@angelodc1652
@angelodc1652 5 ай бұрын
What about Googolplex?
@FM-kl7oc
@FM-kl7oc 5 ай бұрын
Can be solved heuristically: return ( input != 0 ) Because we know 0 is even and we return false otherwise, we are above 50% accuracy in our heuristic when checked against the set of all digits.
@Mikewee777
@Mikewee777 5 ай бұрын
smart
@prozacgod
@prozacgod 5 ай бұрын
I once found a PHP function that was a cascading layer of if / return statements for formatting the numbers 1-31... every single number. function formatNumber($n) { if ($n == 1) return '1st'; if ($n == 2) return '2nd'; if ($n == 3) return '3rd'; if ($n == 4) return '4th'; if ($n == 5) return '5th'; ... } top notch, beautiful, works to spec...
@volodyanarchist
@volodyanarchist 5 ай бұрын
In all honesty it is possible that it started with strings like "first", "second", etc, and only then got changed... which would make sense. And let's be honest, there is a slight difference between 31 and 2**32-1.
@GRBtutorials
@GRBtutorials 5 ай бұрын
@@volodyanarchistI’d use an array or at least a switch statement, though…
@volodyanarchist
@volodyanarchist 5 ай бұрын
@@GRBtutorials I agree with switch. But again can think of a caveat. Assume you also have language like russian. First would be первый if it's masculine, первая feminine, первое neuter, первые plural... And also different cases. And you only had 1, 2, and 3. But i would definitely advise anybody to do a multidimensional array. Anyhow, just to be clear, i agree with you, but am trying to find a reason why somebody would do something like that where it made sense at least initially.
@_scourvinate
@_scourvinate 5 ай бұрын
Soo... funny story, I actually did a similar thing because of Tiktok. I used the same meta programing idea except I used python to write python. The "advantage" my method had was because python is just "so quirky", I was able to write the python code, save it to a file and then import it and use the function in the same program.
@Solarbonite
@Solarbonite 5 ай бұрын
That's code generation with self-modifying code. Yeah it's useful sometimes. Beats writing it yourself!
@SoreBrain
@SoreBrain 5 ай бұрын
What is the yarn command to install this?
@n0mad385
@n0mad385 5 ай бұрын
You should write some code that bruteforces that command
@the_disco_option
@the_disco_option 5 ай бұрын
that was one wild descent into into madness. loved it!
@heinrichagrippa1259
@heinrichagrippa1259 5 ай бұрын
By the title I thought this is going to be about AI/ML.
@ea_naseer
@ea_naseer 5 ай бұрын
Akshually....
@neoney
@neoney 5 ай бұрын
O(1) memory, O(n) time!
@93N13
@93N13 5 ай бұрын
I normally don't like KZfaq thumbnails, but the aneurysm depiction in this one is just great.
@julianemery718
@julianemery718 5 ай бұрын
Wow, what a glorious trainwreck of an article.
@bren.r
@bren.r 5 ай бұрын
Thanks for including the source! You have no idea how often creators never leave sources.
@dylanvidal2221
@dylanvidal2221 5 ай бұрын
sat next to 3 maniacs who wrote tic-tac-toe with only if statements in C for a hackathon…
@cubed.public
@cubed.public 4 ай бұрын
Idk what people are complaining about, this is an O(1) solution, it’s perfect!
@MrWaterraft
@MrWaterraft 5 ай бұрын
I like how much you added to the other person’s well written blog post
@AnAnonymousAuditor
@AnAnonymousAuditor 5 ай бұрын
"fun" is definitely one of the descriptors of all time for this.
@CodecrafterArtemis
@CodecrafterArtemis 5 ай бұрын
‼FUN‼
@exoZelia
@exoZelia 4 ай бұрын
oh we're still doing this joke format. okay
@lupirite6373
@lupirite6373 5 ай бұрын
I was visiting my friends high school programming class when I saw the absolute horror of the checkers game one of his classmates made. It was a simple javascript checkers game, yet he programmed it by checking every single possible state of the board and then allowing the player to take each corrisponding move based on it. The final script ended up being over 4000 lines of code.
@radspiderjackson
@radspiderjackson 5 ай бұрын
i never once tried reading assembly, and i only just now feel like i got a decent grasp on all of the concepts covered in that CS50 course, but after learning the absolute bare minimum about logic gates and seeing this 'isEven' assembly code I really feel like starting with assembly before c++ might be the best route to thoroughly learn computer science concepts. It could just be because a few key ideas finally stuck with me, but it really feels like learning assembly logic gates to some degree woulda really gave me a better idea of what was really going on behind the scenes.
@BrocoliMan2002
@BrocoliMan2002 5 ай бұрын
I spent a lot of time looking at assembly before learning higher level languages like java and it worked out fine for me so I say go for it.
@Aim54Delta
@Aim54Delta 5 ай бұрын
I come from digital electronics - so, logic gates, op amps (for some analog applications) and DSP functions. I built a digital clock before touching an 8080 microprocessor and writing programs to it using its assembly and tracking memory use by pen and paper.... which... you can write more to a sheet of paper than it had memory to work with in many cases. This was all back when Pokemon was 8 bit and taking the world by storm. I highly recommend people learn assembly and make use of it on small scale computers before studying more modern architectures and using higher level languages. It's also recommended to study operating systems, file/drive structures, etc. Speaking of Pokemon, the original red/blue games are highly recommended case studies in programming. On the surface, it all generally works. There are some accidental bugs with how things work vs their intent - but the big ones play out when dealing with the fact that there js a shared memory space between many different parts of the program. The missingno glitch is abaolutely fascinating from a programming perspective and is an example of why coding conventions exist or, in some cases, compilers/languages handle it in the background (and why you might want to, in some cases, not initialize a variable if you know where it's pointed in memory - granted, it's bad practice, but that's what comments are for - when you're performing voodoo rituals). So, in a sense: Logic gates and boolean algebra Possibly op amps for those who want to delve into ancient dark rituals to be able to contract the demons of solomon with mixed signal processing. Then 8080/z80 etc assembly and program mapping. Then C compilers. Then Pokemon code and bug analysis (end by catching mew without tools and/or hacking the game to put mew under the damned truck). Then disc structures Then Operating Systems (start with a command line operating system - dos or something). Then 32 bit computing, risc vs cisc (everything is actually risc - cisc just has schedulers trying to keep the ALUs busy) - which leads us into floats vs ints and some other paradigms. Which is still C, but now we add C++ because larger programs tend to use that next higher level. After that, a programmer can go almost anywhere and do anything at least in terms of core computing. Networking should be a separate step, but require completion of what I consider to be the basic computer course above. Networking is just a lot more involved and not really necessary for most programming. To do it properly, it's both the underlying hardware which facilitates network topologies/protocols, but also the implementation of operating system access controls and accounts. I have a friend who works the helpdesk, mostly for internal issues for the company (they have field agents and customers who also get routed into their ticket system) the network admin got herself locked out of her computer in a situation she was convinced was unrecoverable. People mentioned he'd probably be able to fix it, and of course she was skeptical some help desk goon from a community college could undo a problem her networking degree couldn't solve. He just used basic system tools and 5 minutes to have her password wiped and her account ready to be claimed. The look on her face was that of abject horror. People are not being taught the basics and don't have the tools to solve their problems - which gives them a warped and distorted view of the present standards/claims of products.
@radspiderjackson
@radspiderjackson 5 ай бұрын
that last statement in this comment is pretty much exactly what i have feared for the past decade or so. Like sure i could mimic whats done in a high level java script or python course and be able to output the desired results, but i hated not knowing how it was even possible to get to that point. I also know that harvards cs50 is an excellent resource to get started but even that doesnt have this level of what i guess could be called first principle knowledge. Im sure what you outlined isnt something that could be thoroughly grasped from 0 over the course of just a year or so but it has that "Nand to tetris" route where i feel the most vital information will be learned. @@Aim54Delta
@eldonad
@eldonad 5 ай бұрын
The if lines spacing on the miniature matches exactly the scroll increment on my browser. When this popped up in my feed, it was a trippy experience ! 😵‍💫
@gubiithefish
@gubiithefish 5 ай бұрын
This is amazing, thank you for sharing🎉😂
@the-answer-is-42
@the-answer-is-42 5 ай бұрын
That final solution is so beautiful. Who needs type safty when we can throw a bunch of bytes from disc into a function?
@lukasalt6294
@lukasalt6294 5 ай бұрын
I'd suggest to check the input modulo 2 at the beginning. This way, we can skip every 2nd if statement and have a impressive 2x Speedup
@wacpas
@wacpas 5 ай бұрын
We've implemented the MIPS architecture on a Xilinx FPGA in university and then loaded some assembly onto it. One of the best classes tbh!
@umbaupause
@umbaupause 3 ай бұрын
"What's wrong with getting paid by line?"
@fgregerfeaxcwfeffece
@fgregerfeaxcwfeffece 5 ай бұрын
That's why I am excited. Stuff like this will make me look better even more consistently.
@maxz999
@maxz999 5 ай бұрын
Dang, you got this video out quick
@binaryguru
@binaryguru 5 ай бұрын
I work with multi-terabyte files regularly in windows and I never have a problem with them.
@Trizzi2931
@Trizzi2931 5 ай бұрын
I was continuously laughing through the video thank you for this
@brycemw
@brycemw 5 ай бұрын
I use x86_64 assembly quite often yet I am still finding out surprises. SHL and SHR affect flags differently depending on shift count. If BT or BTS are given a memory argument, rather than truncating the bit index, it adds the top bits to the memory address in a way that’s slower than you doing it yourself. As some examples of recent things
@DaxSudo
@DaxSudo 5 ай бұрын
I am wondering if looking at last bit is more efficient than the modulus. I wanna know now
@gardian06_85
@gardian06_85 4 ай бұрын
64-bit numbers I use quite often: 0, 1 what?
@jacoblockwood4034
@jacoblockwood4034 5 ай бұрын
Yeah I saw this article last week, it's incredible
@immortaldev1489
@immortaldev1489 5 ай бұрын
the forbidden O(N) time complexity is even method
@RodolfoDeNadai
@RodolfoDeNadai 5 ай бұрын
What a journey!!
@Amonimus
@Amonimus 3 ай бұрын
To be honest, it's good that someone has benchmarked this. When you're engineering military or space machinery, anything may happen and every bit matters, so even the silliest things can be interesting.
@matt.loupe.
@matt.loupe. 5 ай бұрын
Seems like it would end up just being a hashtable and a single comparison with O(1) complexity
@TurtleKwitty
@TurtleKwitty 5 ай бұрын
I love that the blog essentially describes how JIT works "make machine code, put in read and exec memory and just call it" but for such a ridiculous usecase is absolutely magnificent
@witchofengineering
@witchofengineering 5 ай бұрын
"There's no need for more than 32 bits, give me an example of a 64-bit value" Astronomers: *burst in laughter*
@CocoTheMii
@CocoTheMii 5 ай бұрын
2:16 i love that it says "unauthorized distribution will be *persecuted* to the fullest extent of the law" basically saying "copy my code and you won't get in trouble but everyone will hate you"
@Dom-zy1qy
@Dom-zy1qy 5 ай бұрын
Idk why i just always assumed you couldnt pipe outputs from the windows terminal. This article has taught me something very valuable
@ericvandruten
@ericvandruten 5 ай бұрын
that video thumbnail is meme-worthy.
@rawallon
@rawallon 5 ай бұрын
I only know of one 64 bit value: ya moma's weight
@LeTtRrZ
@LeTtRrZ 4 ай бұрын
Cant wait for version 2.0 that performs a sum by adding 1 several times.
@KnightSwordAG
@KnightSwordAG 4 ай бұрын
I did the same project in my architecture class in college, and I didn't think it was that bad. But my professor also said my implementation was the most correct.
@TourFaint
@TourFaint 3 ай бұрын
the 330 gb c file made me remember that one time VLC started going crazy and generating some error code as fast as it could, resulting in a 400+gb log file. good times
@BrittonWinterrose
@BrittonWinterrose 5 ай бұрын
Hell yeah Let’s take it to 10 Billy
@ganmullet
@ganmullet 5 ай бұрын
How would this elegant solution compare to the amount of compute needed by gpt4 to decide if the number is even?
@user-mv2os7ti5t
@user-mv2os7ti5t 4 ай бұрын
Interesting video and article
@something3194
@something3194 5 ай бұрын
I remember that one of the nvidia implementation for sqrt and a few other basic functions uses a switch case hardcoded for the most common values
@bebobauomy1265
@bebobauomy1265 5 ай бұрын
I tried inlining 1 million function call instead of using the for loop, and it improved the performance in Go by a lot.
@1Poiuytgfdsa1
@1Poiuytgfdsa1 5 ай бұрын
had to do the same exact mips project in my computer architecture course, wanted to cry
@plague180
@plague180 5 ай бұрын
This reminded me of the nightmares I had to deal with a 500 gig single file years ago
@cagdasucar3932
@cagdasucar3932 5 ай бұрын
The problem is ridiculous, but these are valuable techniques that can be useful in real life. I don't know how OpenAI handles their models, but I imagine the C++ assembly loader technique may come in handy for large programs like LLMs.
@Fiercesoulking
@Fiercesoulking 5 ай бұрын
There are more weird limits on windows or better said limits you can hit easily as devs but not as user. I mean with certain projects where dependencies are inside of projects you hit the 260(MAX_PATH) symbol limit fast you don't know how often I needed to move projects up to the hard drive root directory . Sure such projects on its own are not nice and should be better organize but its most of the time not in your hand. The 4GB limit on exe its really rare to hit it but if I would compile a neural network model into the exe I would hit the limit with ease. There is also another limit which is a bit harder to reach 64-bit are not used for pointers not sure what the limit was 40 or 48-bit the problem is so far I remember it is also packed into assembler upgrading it later is also super hard.
@irbaboon1979
@irbaboon1979 5 ай бұрын
Many of these weird limits are in place for backwards/legacy compatibility - maxpath is still from windows 95 days, short 8.3 filenames from dos days. Microsoft really doubles down and excels in maintaining compatibility for decades; enterprises tend to demand this even if it sometimes doesn’t make sense but their crappy custom, no longer supported (because vendor went belly up) ‘business critical’ applications. You can disable maxpath btw, but then random applications might go flaky…
@TurtleKwitty
@TurtleKwitty 5 ай бұрын
Moving thep roject as a whole is kinda funny, at one of my jobs the antivirus would delete anything that looks like code or executables not on whitelist outside of specific folders deep inthe hierarchy (246 characters deep without the name of the project) so we instead had a special route whitelisted that allowed us to put shortcuts in a root folder XD Doing a deep scan of filesystems for a project that needed to to so still lead to a lot of issues so I had to actually use shortcuts as file pointers in that directory, the memory thrashing of recreating shortcuts for every folder on as it explored was wildddddd
@deleted-something
@deleted-something 5 ай бұрын
Now he should do it for every long value!
@vorrnth8734
@vorrnth8734 5 ай бұрын
The next step after loop unrolling -> function unrolling.
@Netro1992
@Netro1992 5 ай бұрын
This is so horribly beautiful.
@zaffyr
@zaffyr 5 ай бұрын
I have a great suggestion to make the code more efficient: if the number ends in 0 2 4 6 or 8, you can have it skip every second number. if the number ends in 1 3 5 7 or 9, do the same. Truly remarkable how much mathematics is advancing thanks to computers.
@Woeden
@Woeden 5 ай бұрын
Sanest Holy C developer
@benschubert9830
@benschubert9830 4 ай бұрын
I’m so glad the modulo operator isn’t real, I love if statements
@attilatorok5767
@attilatorok5767 5 ай бұрын
I wonder how fast this would be with a switch statement. Probably much faster as it is basically a lookup table, but you still need to load a very large file into memory.
@smellthel
@smellthel 5 ай бұрын
Imagine if a huge technological leap happens and this somehow becomes more efficient than the modulo operator
@volodyanarchist
@volodyanarchist 5 ай бұрын
Quantum computers, that can somehow do all of those ifs at the same time.
@sebay4654
@sebay4654 5 ай бұрын
Well the first way of checking if a number is odd or even id think of is through evaluating the validity of an Equation (N(some Number) ÷ 2 (smallest even number) = Int(an integer which cannot possess any odd Numbers when divided By 2 as as any odd number when divided will always either produce a reminder which we could evaluate or create Decimal Places so instead I'm checking if the Equation itself is Valid rather then directly working with the result (Data validation so if it divides an odd Number the Equation becomes invalid as the result Of the Equation isn't an Integer
@Tomas-yg1xz
@Tomas-yg1xz 4 ай бұрын
Been a while since I last coded anything but if you just wanted to know if a number is odd or even, you could just look at the last bit (of a 32 bit int so no need to guess the length) and spit out an answer, which will be way faster than the modulo operator. last bit 0 = even last bit 1 = odd This obviously wouldn't work for any other multiple like %3 or %4 but neither would the if-else monstrosity.
@DaxSudo
@DaxSudo 5 ай бұрын
Wait if we are going w bit comparison operations at the assembly level couldn’t we just know if it’s even based on the first(/last depending on how u look at it) bit of the number.
@binaryguru
@binaryguru 5 ай бұрын
Yup!
@Andoxico
@Andoxico 5 ай бұрын
You don't need to go to assembly level to do that, C has bit manipulation bool is_odd = x & 1;
@DaxSudo
@DaxSudo 5 ай бұрын
@@Andoxico Fair enough i was just saying if we are gonna go to that extreme might as well do it the most effective way
@SiLentX-pu3bu
@SiLentX-pu3bu 5 ай бұрын
Absolute madlad
@Vlad-Ra
@Vlad-Ra 5 ай бұрын
This is funny as hell!
@rangedfighter
@rangedfighter 5 ай бұрын
I wonder what the performance would be if you made a binary search with nested ifs.
@rapzid3536
@rapzid3536 5 ай бұрын
Every number in javascript.
@GenericInternetter
@GenericInternetter 5 ай бұрын
python, then suddenly assembly well that escalated quickly
@ZealotPewPewPew
@ZealotPewPewPew 5 ай бұрын
Name ONE 64-bit value that isn't Jackie Chan.
@majidmehmood3780
@majidmehmood3780 5 ай бұрын
i looked this guy up and he is an apple software engineer
@SamualN
@SamualN 5 ай бұрын
4:08 a date
@thezoque_
@thezoque_ 5 ай бұрын
i think the next step now is to put all the results from this program into a hashtable and then we can all easily find out what numbers are even or odd! this could be revolutionary
@ChannelSho
@ChannelSho 5 ай бұрын
Now we just need to synthesize this in a hardware accelerator.
@judebreheny3925
@judebreheny3925 5 ай бұрын
I only understood like half of this but it was still very entertaining. One huge advantage of this code is it's very readable - you probably wouldn't need to comment it. I think I'll start trying this strategy in my future projects.
@danielgilleland8611
@danielgilleland8611 5 ай бұрын
Drain the ocean, one thimble at a time.....
@NiklasZiermann
@NiklasZiermann 5 ай бұрын
I enjoyed this more than i should have 😅
} } } } else { { { {
8:11
Theo - t3․gg
Рет қаралды 128 М.
We Need To Talk About Ternaries
19:09
Theo - t3․gg
Рет қаралды 79 М.
Smart Sigma Kid #funny #sigma #comedy
00:25
CRAZY GREAPA
Рет қаралды 14 МЛН
That's how money comes into our family
00:14
Mamasoboliha
Рет қаралды 6 МЛН
Projects Every Programmer Should Try
16:58
ThePrimeTime
Рет қаралды 392 М.
The Weirdest Language I've Ever Seen (I kinda love it...)
58:11
Theo - t3․gg
Рет қаралды 54 М.
UI Libraries Are Dying, Here's Why
13:28
Theo - t3․gg
Рет қаралды 276 М.
STOP Nit Picking In Code Reviews
14:05
ThePrimeTime
Рет қаралды 188 М.
There's A New Browser (That ISN'T Chrome Based)
47:59
Theo - t3․gg
Рет қаралды 74 М.
Don't Contribute to Open Source
9:55
Theo - t3․gg
Рет қаралды 222 М.
a strange but powerful interview question
7:01
Low Level Learning
Рет қаралды 266 М.
One Script Tag Just Pwn'd Over 100,000 Websites
16:04
Theo - t3․gg
Рет қаралды 102 М.
Why You Shouldn't Nest Your Code
8:30
CodeAesthetic
Рет қаралды 2,6 МЛН
When Optimisations Work, But for the Wrong Reasons
22:19
SimonDev
Рет қаралды 866 М.
1$ vs 500$ ВИРТУАЛЬНАЯ РЕАЛЬНОСТЬ !
23:20
GoldenBurst
Рет қаралды 1,5 МЛН
Хотела заскамить на Айфон!😱📱(@gertieinar)
0:21
Взрывная История
Рет қаралды 5 МЛН