Making 4 Billion If Statements For Some Reason...

  Рет қаралды 290,864

Theo - t3․gg

Theo - t3․gg

4 ай бұрын

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 🙏

Пікірлер: 652
@flamakespark
@flamakespark 4 ай бұрын
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 4 ай бұрын
Programmers in 1960s: We're NAND gating out of Earth with this one
@spicybaguette7706
@spicybaguette7706 4 ай бұрын
​​@@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 4 ай бұрын
Now, now, no need to exaggerate. You're an order magnitude off. The number checking program was 330 GB, not 30 GB.
@Wyld1one
@Wyld1one 4 ай бұрын
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 4 ай бұрын
The 72kb moved the slide rule back and forth.
@xBiggs
@xBiggs 4 ай бұрын
Can't wait for Yandere dev to install this package
@t3dotgg
@t3dotgg 4 ай бұрын
I hate that I get this reference
@captainplasma1012
@captainplasma1012 4 ай бұрын
didn't he literally do the exact same thing? with a clock or smth
@Nessie14
@Nessie14 4 ай бұрын
Don't think I get it~ 😅
@FireSiku
@FireSiku 4 ай бұрын
@@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 4 ай бұрын
​@@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 4 ай бұрын
i love the pure irony of putting "if i % 2 = 0" to generate this
@flameofthephoenix8395
@flameofthephoenix8395 4 ай бұрын
Yes, he used a lesser thing to make a greater one.
@qsquared8833
@qsquared8833 4 ай бұрын
​@@flameofthephoenix8395that depends on your definition of lesser and greater
@whohan779
@whohan779 4 ай бұрын
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 4 ай бұрын
​@@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 4 ай бұрын
@@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.
@MelkeyDev
@MelkeyDev 4 ай бұрын
Wait.. so im NOT supposed to have 4 billion if statements..?
@t3dotgg
@t3dotgg 4 ай бұрын
No more than 2.5 billion in go :(
@user-pl9xu5sd5x
@user-pl9xu5sd5x 4 ай бұрын
It's actually using a switch statement would improve performance.
@rohit-gupta
@rohit-gupta 4 ай бұрын
a hashmap of numberboolean would have been faster but not sure about memory
@maxz999
@maxz999 4 ай бұрын
@@rohit-guptaarray of length 4 billion?
@beck4715
@beck4715 4 ай бұрын
​@@t3dotgg3/4 of that would be error handling so closer to 625 million
@nikilk
@nikilk 4 ай бұрын
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 4 ай бұрын
move it to the edge!
@photoniccannon2117
@photoniccannon2117 4 ай бұрын
Show this to the KZbinr “tech lead” (who admitted to lying about being a former Google tech lead) and watch him try to figure it out. 😂
@rahulshah1408
@rahulshah1408 4 ай бұрын
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 4 ай бұрын
​@@rahulshah1408 That's... amazing. Was it the shop's idea to do this on purpose? Knowing Oracle, they were probably quite pleased.
@davidmartin8089
@davidmartin8089 4 ай бұрын
more like dev team on crack haha
@pavolkomlos3343
@pavolkomlos3343 4 ай бұрын
Might be a good idea to optimize this by doing a binary search to find the correct if statement.
@volodyanarchist
@volodyanarchist 4 ай бұрын
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 4 ай бұрын
Smart!
@igotnoname4557
@igotnoname4557 4 ай бұрын
Definitely! Then you can offload the work to a cluster to take care of the heavy lifting.
@pacomatic9833
@pacomatic9833 4 ай бұрын
...or don't use if statements. Ah wait, this is crackhouse, how about we use IF statements to find which statement?
@Guhlius
@Guhlius 4 ай бұрын
Second function starting at the highest number going down, add wrapper with bool to indicate if number is propably big, half execution time
@Eyeclops_
@Eyeclops_ 4 ай бұрын
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 4 ай бұрын
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 4 ай бұрын
@@minerscale8543
@Wyld1one
@Wyld1one 4 ай бұрын
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 4 ай бұрын
@@Wyld1one was the recursion for processing brackets? That's like the poster child for recursion is it not!
@heikkiaho6605
@heikkiaho6605 4 ай бұрын
sounds like me XD
@joppekoers3992
@joppekoers3992 4 ай бұрын
Of course we need 64 bit numbers. For storing the amount of build warings I get for example
@JetJockey87
@JetJockey87 4 ай бұрын
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 4 ай бұрын
@@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.
@theaninova
@theaninova 4 ай бұрын
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 4 ай бұрын
I’m gonna try this just for the heck of it. 😂
@nextgenstudios335
@nextgenstudios335 4 ай бұрын
@@photoniccannon2117 post the results 👀I HAVE to know now
@photoniccannon2117
@photoniccannon2117 4 ай бұрын
@@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 4 ай бұрын
Should be able to split it into more than one file to avoid having to decompress too much at once.
@decycle2912
@decycle2912 4 ай бұрын
the file size is only a gb without compression!
@otter502
@otter502 4 ай бұрын
8:58 the comedy of using the modulus operator to code a program to replace the modulus operator
@jsonkody
@jsonkody 4 ай бұрын
world would be much better place if every math function would be implemented in such elegant way
@simono.899
@simono.899 4 ай бұрын
A function to add two values with convoluted switch statements to account for all combinations
@VivekYadav-ds8oz
@VivekYadav-ds8oz 4 ай бұрын
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 4 ай бұрын
Clear and concise.
@AnsisPlepis
@AnsisPlepis 4 ай бұрын
If only pi was a function that computed it with the odd reciprocal formula at runtime
@hungrymusicwolf
@hungrymusicwolf 4 ай бұрын
@@simono.899Now that would be a sight to see.
@astral6749
@astral6749 4 ай бұрын
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 4 ай бұрын
First time i understand how things actually work it is kinda dumb that toolchains got so scary for me
@volodyanarchist
@volodyanarchist 4 ай бұрын
I was expecting him to remove new line characters from the file, this way it was just one line...
@finminder2928
@finminder2928 4 ай бұрын
Would removing beeline characters from the file actually work?
@volodyanarchist
@volodyanarchist 4 ай бұрын
@@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.
@Exilum
@Exilum 4 ай бұрын
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 4 ай бұрын
Binary search is unnecessary. Can just index directly into the right memory location.
@Exilum
@Exilum 4 ай бұрын
@@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 4 ай бұрын
​@@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 4 ай бұрын
@@OMGclueless Hmm, I see your point. I still think think they're far from cheating equally.
@OMGclueless
@OMGclueless 4 ай бұрын
@@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
@TomNook.
@TomNook. 4 ай бұрын
"a very thick c file" Thicccc. Missed opportunity
@moistness482
@moistness482 4 ай бұрын
Time to call this as a new process each time I check if a number is even
@Remiwi-bp6nw
@Remiwi-bp6nw 4 ай бұрын
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 4 ай бұрын
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 4 ай бұрын
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 4 ай бұрын
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 4 ай бұрын
That's ridiculous. What's next? Using bit rotates and carry flags? Poppycock!
@Sandromatic
@Sandromatic Ай бұрын
That's actually what the assembly version does by the looks of things, so there you go. :P
@prozacgod
@prozacgod 4 ай бұрын
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 4 ай бұрын
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 4 ай бұрын
@@volodyanarchistI’d use an array or at least a switch statement, though…
@volodyanarchist
@volodyanarchist 4 ай бұрын
@@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.
@omkelderman
@omkelderman 4 ай бұрын
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 4 ай бұрын
the linker would run into the 4gb limit though no?
@omkelderman
@omkelderman 4 ай бұрын
@@TurtleKwitty uuuh, good point lol, honestly no idea
@martini9388
@martini9388 4 ай бұрын
This is pure gold. Ty you made my day
@gomi-hako
@gomi-hako 4 ай бұрын
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 4 ай бұрын
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 4 ай бұрын
@@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 4 ай бұрын
@@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 3 ай бұрын
What about Googolplex?
@FM-kl7oc
@FM-kl7oc 4 ай бұрын
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 3 ай бұрын
smart
@SoreBrain
@SoreBrain 4 ай бұрын
What is the yarn command to install this?
@n0mad385
@n0mad385 4 ай бұрын
You should write some code that bruteforces that command
@photoniccannon2117
@photoniccannon2117 4 ай бұрын
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!
@steves9250
@steves9250 4 ай бұрын
Next option would be to code each if statement into its own executable and call it dynamically😂
@NeroDefogger
@NeroDefogger 3 ай бұрын
reading that gave me nausea... I love it...
@_scourvinate
@_scourvinate 4 ай бұрын
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 3 ай бұрын
That's code generation with self-modifying code. Yeah it's useful sometimes. Beats writing it yourself!
@cubed.public
@cubed.public 2 ай бұрын
Idk what people are complaining about, this is an O(1) solution, it’s perfect!
@dreamecho100
@dreamecho100 4 ай бұрын
Package and ship it to npm
@codetoil
@codetoil 4 ай бұрын
npm is a javascript/typescript package manager. The code was written in c(++) and assembly.
@Slashx92
@Slashx92 4 ай бұрын
@@codetoil package it as a node script that executes the original program
@spicybaguette7706
@spicybaguette7706 4 ай бұрын
​@@codetoilwe just need to modify it to produce a 30gb wasm file instead
@minerscale
@minerscale 4 ай бұрын
@@codetoil just write an x86 interpreter in javascript and ship the bin as a blob.
@volodyanarchist
@volodyanarchist 4 ай бұрын
@@codetoilI volunteer you to write a wrapper for it.
@EddyVinck
@EddyVinck 4 ай бұрын
Looks like an O(1) algorithm Prime would be proud
@user-hv4nl9rn8t
@user-hv4nl9rn8t 2 ай бұрын
Wouldn’t it be O(N)?
@polygontower
@polygontower Ай бұрын
@@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 .........'
@KontarAlt
@KontarAlt 4 ай бұрын
This is the most fun ive had watching a video in *years*
@the_disco_option
@the_disco_option 4 ай бұрын
that was one wild descent into into madness. loved it!
@radspiderjackson
@radspiderjackson 4 ай бұрын
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 4 ай бұрын
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 4 ай бұрын
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 4 ай бұрын
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
@Slashx92
@Slashx92 4 ай бұрын
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 3 ай бұрын
It takes only 10 seconds at most, I'd say that is extremely performant and efficient. He's done a very good job. XD
@93N13
@93N13 3 ай бұрын
I normally don't like KZbin thumbnails, but the aneurysm depiction in this one is just great.
@bren.r
@bren.r 4 ай бұрын
Thanks for including the source! You have no idea how often creators never leave sources.
@lukasalt6294
@lukasalt6294 4 ай бұрын
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
@neoney
@neoney 4 ай бұрын
O(1) memory, O(n) time!
@eldonad
@eldonad 4 ай бұрын
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 ! 😵‍💫
@wacpas
@wacpas 4 ай бұрын
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!
@zaffyr
@zaffyr 4 ай бұрын
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.
@gubiithefish
@gubiithefish 4 ай бұрын
This is amazing, thank you for sharing🎉😂
@brycemw
@brycemw 4 ай бұрын
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
@fgregerfeaxcwfeffece
@fgregerfeaxcwfeffece 4 ай бұрын
That's why I am excited. Stuff like this will make me look better even more consistently.
@lupirite6373
@lupirite6373 3 ай бұрын
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.
@the-answer-is-42
@the-answer-is-42 4 ай бұрын
That final solution is so beautiful. Who needs type safty when we can throw a bunch of bytes from disc into a function?
@heinrichagrippa1259
@heinrichagrippa1259 4 ай бұрын
By the title I thought this is going to be about AI/ML.
@ea_naseer
@ea_naseer 4 ай бұрын
Akshually....
@TheHappyKamper
@TheHappyKamper 2 ай бұрын
function isEven(number) { return number % 2 === 0; } function isOdd(number) { return !isEven(number); }
@jacoblockwood4034
@jacoblockwood4034 4 ай бұрын
Yeah I saw this article last week, it's incredible
@julianemery718
@julianemery718 4 ай бұрын
Wow, what a glorious trainwreck of an article.
@AnAnonymousAuditor
@AnAnonymousAuditor 4 ай бұрын
"fun" is definitely one of the descriptors of all time for this.
@CodecrafterArtemis
@CodecrafterArtemis 4 ай бұрын
‼FUN‼
@exoZelia
@exoZelia 3 ай бұрын
oh we're still doing this joke format. okay
@Trizzi2931
@Trizzi2931 4 ай бұрын
I was continuously laughing through the video thank you for this
@MrWaterraft
@MrWaterraft 4 ай бұрын
I like how much you added to the other person’s well written blog post
@maxz999
@maxz999 4 ай бұрын
Dang, you got this video out quick
@alexlowe2054
@alexlowe2054 3 ай бұрын
I was laughing, but holding it together until you read the line "just let the poor OS deal with fitting a 40GB blob into virtual memory", and I completely lost it. Best blog post ever.
@judebreheny3925
@judebreheny3925 3 ай бұрын
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.
@dylanvidal2221
@dylanvidal2221 4 ай бұрын
sat next to 3 maniacs who wrote tic-tac-toe with only if statements in C for a hackathon…
@user-mv2os7ti5t
@user-mv2os7ti5t 3 ай бұрын
Interesting video and article
@binaryguru
@binaryguru 4 ай бұрын
I work with multi-terabyte files regularly in windows and I never have a problem with them.
@KnightSwordAG
@KnightSwordAG 3 ай бұрын
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.
@something3194
@something3194 4 ай бұрын
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
@1Poiuytgfdsa1
@1Poiuytgfdsa1 4 ай бұрын
had to do the same exact mips project in my computer architecture course, wanted to cry
@Amonimus
@Amonimus 2 ай бұрын
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.
@RodolfoDeNadai
@RodolfoDeNadai 4 ай бұрын
What a journey!!
@bebobauomy1265
@bebobauomy1265 4 ай бұрын
I tried inlining 1 million function call instead of using the for loop, and it improved the performance in Go by a lot.
@immortaldev1489
@immortaldev1489 4 ай бұрын
the forbidden O(N) time complexity is even method
@gardian06_85
@gardian06_85 3 ай бұрын
64-bit numbers I use quite often: 0, 1 what?
@TourFaint
@TourFaint 2 ай бұрын
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
@DaxSudo
@DaxSudo 4 ай бұрын
I am wondering if looking at last bit is more efficient than the modulus. I wanna know now
@LeTtRrZ
@LeTtRrZ 3 ай бұрын
Cant wait for version 2.0 that performs a sum by adding 1 several times.
@thezoque_
@thezoque_ 4 ай бұрын
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
@cagdasucar3932
@cagdasucar3932 4 ай бұрын
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.
@CocoTheMii
@CocoTheMii 3 ай бұрын
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"
@umbaupause
@umbaupause 2 ай бұрын
"What's wrong with getting paid by line?"
@Dom-zy1qy
@Dom-zy1qy 4 ай бұрын
Idk why i just always assumed you couldnt pipe outputs from the windows terminal. This article has taught me something very valuable
@matt.loupe.
@matt.loupe. 4 ай бұрын
Seems like it would end up just being a hashtable and a single comparison with O(1) complexity
@Fiercesoulking
@Fiercesoulking 4 ай бұрын
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 4 ай бұрын
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 4 ай бұрын
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
@attilatorok5767
@attilatorok5767 4 ай бұрын
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.
@ganmullet
@ganmullet 4 ай бұрын
How would this elegant solution compare to the amount of compute needed by gpt4 to decide if the number is even?
@carneeki
@carneeki 4 ай бұрын
Because they're unsigned, what about a boolean and operation? Something like `return (input & 0b1)` to look at only the last bit of the input. No need for modulo arithmetic (though, I wouldn't be surprised if that's how the compiler would optimise %2 away).
@SiLentX-pu3bu
@SiLentX-pu3bu 4 ай бұрын
Absolute madlad
@Vlad-Ra
@Vlad-Ra 4 ай бұрын
This is funny as hell!
@plague180
@plague180 4 ай бұрын
This reminded me of the nightmares I had to deal with a 500 gig single file years ago
@vk3fbab
@vk3fbab 4 ай бұрын
Love it. I mean you could write an optimal assembly solution with a handful of instructions which could execute in under 100 cycles. However you decide to write it in a way that still yields a fast result. Great work. This just needs the 64bit version! Imagine the bloat. It might actually be hard to do because ther program space would exceed the address space of 64 bits.
@BrittonWinterrose
@BrittonWinterrose 4 ай бұрын
Hell yeah Let’s take it to 10 Billy
@TurtleKwitty
@TurtleKwitty 4 ай бұрын
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
@muizzsiddique
@muizzsiddique 4 ай бұрын
I have never had explorer crash from a ridiculously large file. I have done screen captures in lossless and typically was left with a 700GiB mkv, some being over 1TiB. Never had any issues here.
@Dream.of.Endless
@Dream.of.Endless 4 ай бұрын
Honestly, this is something similar i did, when i was learning intro to Java programming....23 years ago.
@Netro1992
@Netro1992 4 ай бұрын
This is so horribly beautiful.
@ericvandruten
@ericvandruten 4 ай бұрын
that video thumbnail is meme-worthy.
@deleted-something
@deleted-something 3 ай бұрын
Now he should do it for every long value!
@CodeReign
@CodeReign 4 ай бұрын
I really wanted to see a switch statement because that would be super fast but just absurdly large. Though not this large
@SIRBOB102
@SIRBOB102 3 ай бұрын
i need to figure out how to write a rust macro so this can be created as it compiles
@RandomGeometryDashStuff
@RandomGeometryDashStuff 4 ай бұрын
03:06 isn't this already 16bit ready (any unsigned integer is odd if least significant 8 bits as unsigned integer is odd)?
@witchofengineering
@witchofengineering 4 ай бұрын
"There's no need for more than 32 bits, give me an example of a 64-bit value" Astronomers: *burst in laughter*
@proxy1035
@proxy1035 4 ай бұрын
7:16 it's not fun when it's modern x68_64, but other ISA's like MC68k, 6502, AVR, and such, are pretty fun to write assembly for. :)
@jorgelenny47
@jorgelenny47 3 ай бұрын
Genuinely thought that when he pulled assembly, he was going to check if the number was 0 or 1, and if it wasn't, subtract 2 and try again. Not 4 billion if statements, but that would've been amazing for performance experiments
@Mokrator
@Mokrator 4 ай бұрын
i wonder if loading this code does need more time for "loading the code" than running it. As it does contain 4 billion 'odd' or 'even' strings... i love the part where code prints the "bad" code... thats really genious.
@rangedfighter
@rangedfighter 4 ай бұрын
I wonder what the performance would be if you made a binary search with nested ifs.
@DaxSudo
@DaxSudo 4 ай бұрын
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 4 ай бұрын
Yup!
@Andoxico
@Andoxico 4 ай бұрын
You don't need to go to assembly level to do that, C has bit manipulation bool is_odd = x & 1;
@DaxSudo
@DaxSudo 4 ай бұрын
@@Andoxico Fair enough i was just saying if we are gonna go to that extreme might as well do it the most effective way
@randomgeocacher
@randomgeocacher 4 ай бұрын
File sizes? I once bricked NTFS by file numbers. I iterated enigma cipher for all code and ring combination and stored each potential plaintext in each own file. Transformed an Intel Pentium to an Intel 4004 by that SNAFU. Took hours to delete all the files and eventually performance got back. On the next iteration I just dumped all to one big file and life was good.
@jean-michelgilbert8136
@jean-michelgilbert8136 4 ай бұрын
This exactly this. NTFS (and Windows) has shit performance when dealing with lots of small files. Bigfiles/Virtual file systems are the way to go for performance on Windows.
} } } } else { { { {
8:11
Theo - t3․gg
Рет қаралды 128 М.
Low Code Scares Me
7:24
Theo - t3․gg
Рет қаралды 91 М.
Маленькая и средняя фанта
00:56
Multi DO Smile Russian
Рет қаралды 5 МЛН
100❤️
00:19
Nonomen ノノメン
Рет қаралды 37 МЛН
The most impenetrable game in the world🐶?
00:13
LOL
Рет қаралды 30 МЛН
I Created a Game Engine Just to Optimise This
4:50
Vercidium
Рет қаралды 902 М.
Cool Tools I’ve Been Using Lately
23:11
Theo - t3․gg
Рет қаралды 51 М.
XState: How to make actions reusable with parameters
1:34
Baptiste Devessier
Рет қаралды 41
Oh no, I think I like this
6:58
Theo - t3․gg
Рет қаралды 127 М.
I Made a Graph of Wikipedia... This Is What I Found
19:44
adumb
Рет қаралды 2,2 МЛН
I Made a 32-bit Computer Inside Terraria
15:26
From Scratch
Рет қаралды 3,2 МЛН
When Your Game Is Bad But Your Optimisation Is Genius
8:52
Vercidium
Рет қаралды 1,3 МЛН
The purest coding style, where bugs are near impossible
10:25
Coderized
Рет қаралды 853 М.
Reverse Engineering Game Code from the Neutral Zone
40:59
Retro Game Mechanics Explained
Рет қаралды 502 М.
Обзор игрового компьютера Макса 2в1
23:34
⌨️ Сколько всего у меня клавиатур? #обзор
0:41
Гранатка — про VR и девайсы
Рет қаралды 651 М.
ПРОБЛЕМА МЕХАНИЧЕСКИХ КЛАВИАТУР!🤬
0:59
Корнеич
Рет қаралды 3,3 МЛН
wyłącznik
0:50
Panele Fotowoltaiczne
Рет қаралды 22 МЛН
How Neuralink Works 🧠
0:28
Zack D. Films
Рет қаралды 32 МЛН
как спасти усилитель?
0:35
KS Customs
Рет қаралды 424 М.