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
@RedVio97210 ай бұрын
Programmers in 1960s: We're NAND gating out of Earth with this one
@spicybaguette770610 ай бұрын
@@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)
@user7297410 ай бұрын
Now, now, no need to exaggerate. You're an order magnitude off. The number checking program was 330 GB, not 30 GB.
@Wyld1one10 ай бұрын
Charles Moore (creator of the FORTH programming language) all I need is 1K for the operating system. Maybe 12-14 bytes for the program
@rahulshah140810 ай бұрын
The 72kb moved the slide rule back and forth.
@SandTurtle10 ай бұрын
i love the pure irony of putting "if i % 2 = 0" to generate this
@flameofthephoenix839510 ай бұрын
Yes, he used a lesser thing to make a greater one.
@qsquared883310 ай бұрын
@@flameofthephoenix8395that depends on your definition of lesser and greater
@whohan77910 ай бұрын
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
@fal47709 ай бұрын
@@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; }
@qsquared88339 ай бұрын
@@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.
@pavolkomlos334310 ай бұрын
Might be a good idea to optimize this by doing a binary search to find the correct if statement.
@volodyanarchist10 ай бұрын
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); }
@Avighna10 ай бұрын
Smart!
@igotnoname455710 ай бұрын
Definitely! Then you can offload the work to a cluster to take care of the heavy lifting.
@pacomatic983310 ай бұрын
...or don't use if statements. Ah wait, this is crackhouse, how about we use IF statements to find which statement?
@Guhlius10 ай бұрын
Second function starting at the highest number going down, add wrapper with bool to indicate if number is propably big, half execution time
@nikilk10 ай бұрын
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.
@MrLordLowbob10 ай бұрын
move it to the edge!
@photoniccannon211710 ай бұрын
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. 😂
@rahulshah140810 ай бұрын
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.
@photoniccannon211710 ай бұрын
@@rahulshah1408 That's... amazing. Was it the shop's idea to do this on purpose? Knowing Oracle, they were probably quite pleased.
@davidmartin808910 ай бұрын
more like dev team on crack haha
@xBiggs10 ай бұрын
Can't wait for Yandere dev to install this package
@t3dotgg10 ай бұрын
I hate that I get this reference
@captainplasma101210 ай бұрын
didn't he literally do the exact same thing? with a clock or smth
@Nessie1410 ай бұрын
Don't think I get it~ 😅
@FireSiku10 ай бұрын
@@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
@potatoheadpokemario193110 ай бұрын
@@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
@Eyeclops_10 ай бұрын
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.
@minerscale10 ай бұрын
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.
@rickquackstley10 ай бұрын
@@minerscale8543
@Wyld1one10 ай бұрын
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
@minerscale10 ай бұрын
@@Wyld1one was the recursion for processing brackets? That's like the poster child for recursion is it not!
@heikkiaho660510 ай бұрын
sounds like me XD
@joppekoers399210 ай бұрын
Of course we need 64 bit numbers. For storing the amount of build warings I get for example
@JetJockey8710 ай бұрын
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
@whohan77910 ай бұрын
@@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.
@MelkeyDev10 ай бұрын
Wait.. so im NOT supposed to have 4 billion if statements..?
@t3dotgg10 ай бұрын
No more than 2.5 billion in go :(
@Household-u4b10 ай бұрын
It's actually using a switch statement would improve performance.
@rohit-gupta10 ай бұрын
a hashmap of numberboolean would have been faster but not sure about memory
@maxz99910 ай бұрын
@@rohit-guptaarray of length 4 billion?
@beck471510 ай бұрын
@@t3dotgg3/4 of that would be error handling so closer to 625 million
@theaninova10 ай бұрын
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
@photoniccannon211710 ай бұрын
I’m gonna try this just for the heck of it. 😂
@nextgenstudios33510 ай бұрын
@@photoniccannon2117 post the results 👀I HAVE to know now
@photoniccannon211710 ай бұрын
@@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.
@flameofthephoenix839510 ай бұрын
Should be able to split it into more than one file to avoid having to decompress too much at once.
@decycle291210 ай бұрын
the file size is only a gb without compression!
@otter50210 ай бұрын
8:58 the comedy of using the modulus operator to code a program to replace the modulus operator
@jsonkody10 ай бұрын
world would be much better place if every math function would be implemented in such elegant way
@simono.89910 ай бұрын
A function to add two values with convoluted switch statements to account for all combinations
@VivekYadav-ds8oz10 ай бұрын
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!
@Blast-Forward10 ай бұрын
Clear and concise.
@AnsisPlepis10 ай бұрын
If only pi was a function that computed it with the odd reciprocal formula at runtime
@hungrymusicwolf10 ай бұрын
@@simono.899Now that would be a sight to see.
@astral674910 ай бұрын
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
@fltfathin10 ай бұрын
First time i understand how things actually work it is kinda dumb that toolchains got so scary for me
@volodyanarchist10 ай бұрын
I was expecting him to remove new line characters from the file, this way it was just one line...
@finminder292810 ай бұрын
Would removing beeline characters from the file actually work?
@volodyanarchist10 ай бұрын
@@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.
@Exilum10 ай бұрын
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.
@OMGclueless10 ай бұрын
Binary search is unnecessary. Can just index directly into the right memory location.
@Exilum10 ай бұрын
@@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.
@OMGclueless10 ай бұрын
@@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.
@Exilum10 ай бұрын
@@OMGclueless Hmm, I see your point. I still think think they're far from cheating equally.
@OMGclueless10 ай бұрын
@@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
@moistness48210 ай бұрын
Time to call this as a new process each time I check if a number is even
@keineahnung233910 ай бұрын
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
@williamdrum989910 ай бұрын
That's ridiculous. What's next? Using bit rotates and carry flags? Poppycock!
@Sandromatic7 ай бұрын
That's actually what the assembly version does by the looks of things, so there you go. :P
@cubed.public8 ай бұрын
Idk what people are complaining about, this is an O(1) solution, it’s perfect!
@Remiwi-bp6nw10 ай бұрын
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
@smallfox862310 ай бұрын
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 😊
@BrandonVout10 ай бұрын
I have a lot of nostalgia for PIC assembly. I wouldn't do it again but it was a lot of fun. VHDL too.
@TomNook.10 ай бұрын
"a very thick c file" Thicccc. Missed opportunity
@prozacgod10 ай бұрын
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...
@volodyanarchist10 ай бұрын
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.
@GRBtutorials10 ай бұрын
@@volodyanarchistI’d use an array or at least a switch statement, though…
@volodyanarchist10 ай бұрын
@@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.
@gomi-hako10 ай бұрын
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.
@Xudmud10 ай бұрын
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-hako10 ай бұрын
@@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. 三千三百三十三無量大数三千三百三十三不可思議三千三百三十三那由他三千三百三十三阿僧祇三千三百三十三恒河沙三千三百三十三極三千三百三十三載三千三百三十三正三千三百三十三澗三千三百三十三溝三千三百三十三穰三千三百三十三𥝱三千三百三十三垓三千三百三十三京三千三百三十三兆三千三百三十三億三千三百三十三万三千三百三十三
@Xudmud10 ай бұрын
@@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)
@angelodc16529 ай бұрын
What about Googolplex?
@omkelderman10 ай бұрын
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
@TurtleKwitty10 ай бұрын
the linker would run into the 4gb limit though no?
@omkelderman10 ай бұрын
@@TurtleKwitty uuuh, good point lol, honestly no idea
@photoniccannon211710 ай бұрын
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!
@zaffyr10 ай бұрын
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.
@_scourvinate10 ай бұрын
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.
@Solarbonite9 ай бұрын
That's code generation with self-modifying code. Yeah it's useful sometimes. Beats writing it yourself!
@lukasalt62949 ай бұрын
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
@radspiderjackson10 ай бұрын
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.
@BrocoliMan200210 ай бұрын
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.
@Aim54Delta10 ай бұрын
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.
@radspiderjackson10 ай бұрын
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
@the-answer-is-429 ай бұрын
That final solution is so beautiful. Who needs type safty when we can throw a bunch of bytes from disc into a function?
@steves925010 ай бұрын
Next option would be to code each if statement into its own executable and call it dynamically😂
@NeroDefogger9 ай бұрын
reading that gave me nausea... I love it...
@FM-kl7oc10 ай бұрын
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.
@Mikewee7779 ай бұрын
smart
@TheHappyKamper8 ай бұрын
function isEven(number) { return number % 2 === 0; } function isOdd(number) { return !isEven(number); }
@umbaupause8 ай бұрын
"What's wrong with getting paid by line?"
@dreamecho10010 ай бұрын
Package and ship it to npm
@codetoil10 ай бұрын
npm is a javascript/typescript package manager. The code was written in c(++) and assembly.
@Slashx9210 ай бұрын
@@codetoil package it as a node script that executes the original program
@spicybaguette770610 ай бұрын
@@codetoilwe just need to modify it to produce a 30gb wasm file instead
@minerscale10 ай бұрын
@@codetoil just write an x86 interpreter in javascript and ship the bin as a blob.
@volodyanarchist10 ай бұрын
@@codetoilI volunteer you to write a wrapper for it.
@MaxSharpy10 ай бұрын
This is pure gold. Ty you made my day
@KontarAlt10 ай бұрын
This is the most fun ive had watching a video in *years*
@EddyVinck10 ай бұрын
Looks like an O(1) algorithm Prime would be proud
@Anonymous-u8r8j8 ай бұрын
Wouldn’t it be O(N)?
@polygontower7 ай бұрын
@@Anonymous-u8r8j 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 .........'
@wacpas10 ай бұрын
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!
@gardian06_859 ай бұрын
64-bit numbers I use quite often: 0, 1 what?
@brycemw10 ай бұрын
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
@witchofengineering10 ай бұрын
"There's no need for more than 32 bits, give me an example of a 64-bit value" Astronomers: *burst in laughter*
@LeTtRrZ9 ай бұрын
Cant wait for version 2.0 that performs a sum by adding 1 several times.
@Slashx9210 ай бұрын
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
@HippieInHeart9 ай бұрын
It takes only 10 seconds at most, I'd say that is extremely performant and efficient. He's done a very good job. XD
@lupirite63739 ай бұрын
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_disco_option10 ай бұрын
that was one wild descent into into madness. loved it!
@heinrichagrippa125910 ай бұрын
By the title I thought this is going to be about AI/ML.
@ea_naseer10 ай бұрын
Akshually....
@SoreBrain10 ай бұрын
What is the yarn command to install this?
@n0mad38510 ай бұрын
You should write some code that bruteforces that command
@neoney10 ай бұрын
O(1) memory, O(n) time!
@TimKessler-q3s9 ай бұрын
Interesting video and article
@matt.loupe.10 ай бұрын
Seems like it would end up just being a hashtable and a single comparison with O(1) complexity
@julianemery71810 ай бұрын
Wow, what a glorious trainwreck of an article.
@cagdasucar393210 ай бұрын
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.
@MrWaterraft10 ай бұрын
I like how much you added to the other person’s well written blog post
@serg_sel75269 ай бұрын
Aah, this is why all programs are increasing in space over time... They need to increase amount of if statements)
@eldonad9 ай бұрын
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 ! 😵💫
@AnAnonymousAuditor10 ай бұрын
"fun" is definitely one of the descriptors of all time for this.
@CodecrafterArtemis10 ай бұрын
‼FUN‼
@exoZelia9 ай бұрын
oh we're still doing this joke format. okay
@fgregerfeaxcwfeffece10 ай бұрын
That's why I am excited. Stuff like this will make me look better even more consistently.
@binaryguru10 ай бұрын
I work with multi-terabyte files regularly in windows and I never have a problem with them.
@bren.r10 ай бұрын
Thanks for including the source! You have no idea how often creators never leave sources.
@sxlg_3210 ай бұрын
the saddest thing is you could take that original code and make one change and it would work for any number.
@Milanka9899 ай бұрын
What about: if(number == 0) { print "even"; } else if(number == 2) { print "even"; } else if(number == 4) { print "even"; } ...... else { print "odd"; } ? This way, we can reduce the size ~the half.
@tutacat9 ай бұрын
We need switch case, or use a hash dict, that is way more performant
@immortaldev148910 ай бұрын
the forbidden O(N) time complexity is even method
@muizzsiddique9 ай бұрын
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.
@carneeki10 ай бұрын
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).
@judebreheny39259 ай бұрын
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.
@bebobauomy126510 ай бұрын
I tried inlining 1 million function call instead of using the for loop, and it improved the performance in Go by a lot.
@majidmehmood378010 ай бұрын
i looked this guy up and he is an apple software engineer
@dylanvidal222110 ай бұрын
sat next to 3 maniacs who wrote tic-tac-toe with only if statements in C for a hackathon…
@thezoque_10 ай бұрын
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
@Amonimus8 ай бұрын
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.
@Fiercesoulking10 ай бұрын
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.
@irbaboon197910 ай бұрын
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…
@TurtleKwitty10 ай бұрын
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
@KnightSwordAG9 ай бұрын
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.
@TCR_DND9 ай бұрын
somthing tells me this could be fixed but using an "Nth Last" statment to check only the last number in the strong them checking aginst a List of 0 - 9 setting an Even or odd value for each that the code would check against for example 0 = Even ,1 = odd. 12340 = Even becuase the last number 0 is even. This also works for 12354125.12, becasue 2 is even and the last number in the sequance then its even. I will note that this will work for -X numbers as its only cares about the last number in the Sequance is. Check [1 Nth child last] number and compare against the below; 0 = Even 1 = Odd 2 = Even 3 = Odd 4 = Even 6 = odd 7 = even 8 = odd 9 = even example is 1234.55 odd or even it is odd because the last number in the squance being 5 is odd Piton example``` def check_odd_even(number): last_digit = int(str(number)[-1]) if last_digit in [0, 2, 4, 6, 8]: return "Even" else: return "Odd" # Example usage: sequence = 1234.55 result = check_odd_even(sequence) print(f"The sequence {sequence} is {result}.") ``` I cant for the life of me think of where this would come up as im pretty sure all programing languages know this, but i supose if your building your own lagnauge it could make sence.
@something319410 ай бұрын
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
@Trizzi293110 ай бұрын
I was continuously laughing through the video thank you for this
@proxy10359 ай бұрын
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. :)
@user-le8ul4nr5t10 ай бұрын
chad 4 billion if statements vs virgin !(number&1)
@Mikewee7779 ай бұрын
Proof that string length does not matter as much as high impact brevity .
@TourFaint8 ай бұрын
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
@kristianwichmann999610 ай бұрын
There's gotta be a more effective assembly version. Like rotate right and output carry flag.
@m4rt_10 ай бұрын
I know a 64 bit value. the mmap_length value in the Multiboot 1 header, another one is the mmap_addr value in the Multiboot 1 header. ... also every pointer on a 64-bit system. Sorry, I've been doing some OS Dev recently...
@fruitsbat9 ай бұрын
it's missing multi threading
@gubiithefish10 ай бұрын
This is amazing, thank you for sharing🎉😂
@DimkaTsv9 ай бұрын
Dealt with files over 100GB in Windows from to time (multiple hours of recordings). They open pretty much fine. At least i hadn't crashed explorer because i opened them (at least not yet). I did freeze explorer by opening and close same file multiple times really fast though). Text files are different story though. Editors really don't want to have large text files without using block type load. Because file often sits in RAM when being opened.
@rapzid353610 ай бұрын
Every number in javascript.
@vk3fbab9 ай бұрын
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.
@deathstroyer10 ай бұрын
timestamps use 64 bits even though the world will end in 2038 anyways as prophesied by unix
@Dream.of.Endless10 ай бұрын
Honestly, this is something similar i did, when i was learning intro to Java programming....23 years ago.
@rawallon10 ай бұрын
I only know of one 64 bit value: ya moma's weight
@1Poiuytgfdsa110 ай бұрын
had to do the same exact mips project in my computer architecture course, wanted to cry
@TortoogaThePenguin10 ай бұрын
You can do all of that in 5 comparisons by ignoring all the digits of the number except the least significant digit, if its 0,2,4,6 or 8 then your number is even, otherwise its odd.
@SowbugMori10 ай бұрын
This entire article is a shitshow and I love it for that
@Emp_JP8 ай бұрын
we need an opposite definition of shortcut, i would suggest "longcut" but even that implies we are cutting to get the result faster, i suppose this is taking the scenic route...by crawling
@moncyn110 ай бұрын
I understand your lols with windows as development machine but its getting nicer with things like winget (homebrew my long friend) and WSL and others, not as perfect as pure linux in some cases but much more advanced than it was before with setting up your SDKs
@PeterZaitcev10 ай бұрын
I can suggest optimizing code by using an unconditional jump to an address from 32-bit-key lookup table.
@electrocaruzo-karpada248510 ай бұрын
wait you could seriously make this more efficient: if num == 0 or num == 2 or num == 4 etc., and then simply put an else to return false
@Noritoshi-r8m10 ай бұрын
Sanest Holy C developer
@JulianKingman10 ай бұрын
Performance would be greatly improved by storing a hash table to memoize results when the same number is checked multiple times.
@antonhelsgaun10 ай бұрын
Instead of storing the result, you could store a pointer to the location in memory where the right if statement is, then have that in a binary search tree
@JulianKingman10 ай бұрын
@@antonhelsgaun 🤯
@jacoblockwood403410 ай бұрын
Yeah I saw this article last week, it's incredible
@owenkegg560810 ай бұрын
- 32 bit is the holy grail of computing - lets use x86-64 I wonder if 32 bit mode x86 would overflow its instruction pointer because there are multiple instructions for every 32 bit number. That would be one hell of a segfault
@jorgelenny479 ай бұрын
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
@sebay465410 ай бұрын
I can think of a few ways within a few minutes to to this that dont require each case to have its own if statement(C++ dev with knowledge in C# though not my preferred language) 1. Do a check function on if the result of N/2=INT is true (not how it would be writen in code but explained logically if it doesnt equal an intiger such as it having decimal places in its result then the Evaluation of the Equation us false and we simply Else statement those who fail this simple check as Odd) and if it is we have an even number if not then we have an odd number that since it can't be divided by two. 2 use the modulo operator (C++) which Calculates the Remainder of a division equation which is fundamentally the same concept as the first approach whicb would be what my brain would default to (Validating the result of an Equation as posses to Calculating the Mod of X and N) Specifically my reason for not using a modulus function is because its to me has extra steps since its calculating the remained rather then evaluating the validity of a statement since i can Embed my condition and have it be directly evaluated by an if statement.