Lua's Arrays are Wrong and YOU KNOW IT. (Coding in a Random Language Every Day)

  Рет қаралды 60,003

Low Level Learning

Low Level Learning

5 ай бұрын

Advent of Code 2023 is UPON US! What better way to spend the holiday season, learn to program, and test your skills against your friends. This year, I've decided to try something kind of insane. I'll be choosing a language off the wheel every day.... let's see what happens.
🏫 COURSES 🏫 Learn to code in C at lowlevel.academy
📰 NEWSLETTER 📰 Sign up for our newsletter at mailchi.mp/lowlevel/the-low-down
🙌 SUPPORT THE CHANNEL 🙌 Become a Low Level Associate and support the channel at / lowlevellearning
🔥🔥🔥 SOCIALS 🔥🔥🔥
Low Level Merch!: lowlevel.store/
Follow me on Twitter: / lowleveltweets
Follow me on Twitch: / lowlevellearning
Join me on Discord!: / discord

Пікірлер: 405
@rafaelbordoni516
@rafaelbordoni516 5 ай бұрын
Lua is the C of the interpreted languages, extremely simple and small. Probably the easiest language to teach kids programming.
@torarinvik4920
@torarinvik4920 5 ай бұрын
I agree 100%, it's simplicity is masterful. It looks and feels nice too just like Ruby and Python.
@LowLevelLearning
@LowLevelLearning 5 ай бұрын
love that
@revengerwizard
@revengerwizard 5 ай бұрын
Comparing Lua to C is kind of unfair
@FaZekiller-qe3uf
@FaZekiller-qe3uf 5 ай бұрын
@@torarinvik4920Python does not feel nice
@charlieking7600
@charlieking7600 5 ай бұрын
​​@@FaZekiller-qe3ufbecause it feels awesome. Many built-in functions, structures, powerful slices, lambdas and iterators.
@AntonioZL
@AntonioZL 5 ай бұрын
The magic of Lua is that writing code in it just feels good. The syntax is so simple, there are super useful operators (# for length, .. for concat) and tables can represent a wide range of data structures and can even be used for OOP with meta tables.
@RoboArc
@RoboArc 5 ай бұрын
Lua is pretty powerful, the issue comes down to how well you know it. As someone who has a personal copy of the lua syntax manuel. Lua tables are amazing ❤❤❤
@edomeindertsma6669
@edomeindertsma6669 2 ай бұрын
# is unintuitive for tables with discontinuous indices. It will give the length up to the first nil value.
@onrir
@onrir 5 ай бұрын
lua-jit is faster than python by a large margin and pretty light on resource consumption aswell.
@fhudufin
@fhudufin 5 ай бұрын
normal lua is faster than python iirc
@onrir
@onrir 5 ай бұрын
@@fhudufin to be fully honest, python is not a very hard benchmark to pull off lmfao
@skaruts
@skaruts 5 ай бұрын
If it exists, it's faster than python.
@kuhluhOG
@kuhluhOG 5 ай бұрын
well, the default Python implementation (CPython) there are some which are A LOT faster
@onrir
@onrir 5 ай бұрын
@@kuhluhOG mojo is closed source and extremely unstable, the python to c compiler is also very unstable. Apart from that I do not know of any other implementations that are faster than cpython especially now that it is JIT bit default.
@Yoolayn
@Yoolayn 5 ай бұрын
I will not stand for this slander of neovim's config language
@NostraDavid2
@NostraDavid2 5 ай бұрын
Also world of warcraft addons
@murat.h
@murat.h 5 ай бұрын
@@NostraDavid2 Also scripting language for roblox
@callyral
@callyral 5 ай бұрын
Also Wezterm config language and AwesomeWM's config language Lua seems really popular for configuring stuff huh
@universaltoons
@universaltoons 5 ай бұрын
​@@murat.hroblox uses Luau
@josephbrandenburg4373
@josephbrandenburg4373 8 күн бұрын
OpenMW scripting!
@xavxavierm
@xavxavierm 5 ай бұрын
Cool video, lua is surprisingly integrated into many applications though. its good to know
@LowLevelLearning
@LowLevelLearning 5 ай бұрын
Indeed!
@no_name4796
@no_name4796 5 ай бұрын
neovim itself uses lua, btw
@romanstingler435
@romanstingler435 5 ай бұрын
@@LowLevelLearningDon't tell @teej_dv the title of your video
@user-cy1rm5vb7i
@user-cy1rm5vb7i 5 ай бұрын
it's cuz Lua is technically a C-library that can be embedded into (and augmented with) C code. Lots of game engines and user-configurable apps use Lua as a scripting lang for that reason
@terdik36
@terdik36 5 ай бұрын
roblox and fivem developers are shaking rn
@glennedgar5057
@glennedgar5057 5 ай бұрын
I am an embeded programer. I used lua since 2005. For me lua has three advantages. 1. Low memory foot print. Around 100k. 2. Lua is a language that is embedded language. This allows it to be easily embedded into an environment, unlike python which is very hard to do. 3. Lua is easy to interface with c code and c code interfacd with lua. Amoung the things that I have done. 1 setup command shells inside low resource processors to for test and debug subsystems while the system is running. 2. Field lua on processors like esp32. Several lua tasks could be created using FreeRtos, which canot be done with micropython. Also, Lua can very easily integrate with Arduino c routines. Lua loses its advantage when system get above 500 m where python and associated library come in to play. As a closing not there is a lua engine written in go which shopify used at one time.
@MavikBow
@MavikBow 5 ай бұрын
What are the 100k and 500m that you speak of?
@orbyfied
@orbyfied 5 ай бұрын
@@MavikBow bytes of memory i assume
@kuhluhOG
@kuhluhOG 5 ай бұрын
I hate the fact that KZbin is bugged on my end so that I can't see the "See More".
@cocbuilds
@cocbuilds 5 ай бұрын
@@kuhluhOG try different account? if on PC try in guest mode maybe, probably an extension or your account
@kuhluhOG
@kuhluhOG 5 ай бұрын
@@cocbuilds tried it already, doesn't matter
@The_RoboDoc
@The_RoboDoc 5 ай бұрын
The bruteforce approach is doable, especially if you multithreaded it. How do I know? Because I did that, like a complete cave man
@yjlom
@yjlom 5 ай бұрын
ah, I didn't do part 2 because I saw the problem, found the smart solution to be too annoying to write for fun, and thought there's no way the bruteforce way finishes today will do it then (although I chose to use js for today's problem which will slow it down even more)
@SharpBritannia
@SharpBritannia 5 ай бұрын
Same. It's currently running
@yjlom
@yjlom 5 ай бұрын
after about 40 minutes of running, I didn't manage to compute it, but I did manage to lock up firefox and to crash my mouse driver for some reason (this last part is why this is a reply and not an edit)
@The_RoboDoc
@The_RoboDoc 5 ай бұрын
@@yjlom Did mine in Python. In a nutshell I created a worker for every seed range, and ran it using PyPy instead of standard Python interpreter. CPU usage hit hard 100%, went to grab a snack, came back and it was done. Looked at CPU usage history and it was interesting to see each CPU core usage gradually going down over time, as each worker was getting done
@The_RoboDoc
@The_RoboDoc 5 ай бұрын
@@yjlom That's... that's kinda impressive ngl :DDD
@pseudonymity0000
@pseudonymity0000 5 ай бұрын
Hot take... Lua should of been used for the web instead of JS
@CEOofGameDev
@CEOofGameDev 5 ай бұрын
Funny you should mention it, since Emilua (basically lua's node.js) dropped a new version literally yesterday.
@jumpsplat120
@jumpsplat120 5 ай бұрын
Based take.
@torphedo6286
@torphedo6286 5 ай бұрын
true!
@caerphoto
@caerphoto 5 ай бұрын
JS probably would have been fine if the creator was given more than 10 days to make it, and not forced to "make it look like Java".
@ivanjermakov
@ivanjermakov 5 ай бұрын
@@thetukars Brendan Eich (JS creator) said that if he was not forced by business, JS would be functional with Scheme syntax.
@flamendless
@flamendless 5 ай бұрын
Lua is slow, but LuaJIT is the blackest magic there is
@FireDragon91245
@FireDragon91245 5 ай бұрын
Lua is amazing its as simple as C and can get as complex as C++ if you start with Metatables and fenv (function evoirements) you can do amazing stuff for example in lua tables there is no such thing as private members but with metatables and fenv you can get total support for private members but also in reverse its usefull you can do what feals like reverse reflection
@OneMilian
@OneMilian 5 ай бұрын
The complexity doesn't really depend that much on a language more like on the project itself.
@armincal9834
@armincal9834 5 ай бұрын
@OneMilian it DOES depend on the language. For example take the C programming book,written by the creators of C and compare it with the book written by the creator of C++. You will see that there is a MASSIVE difference in their volumes. C is an extremely simple language which puts all the hard tasks on the programmers shoulders. Python on the other hand is an extremely complicated language because it can do almost everything with little to no external libraries. C++ is the hardest language there is IMO since it was designed to let the programmer program everything from super complicated operating systems all the way up to simple shell programs that are meant to execute a few simple shell commands
@FireDragon91245
@FireDragon91245 5 ай бұрын
@@OneMilian i get what you mean and i agree most complexity comes from the project but i meant what @armincal9834 describes that the language has some parts that are just more complex in nature and if you use thes parts the project would also become more complex by default
@hudsonator7259
@hudsonator7259 5 ай бұрын
You CAN start tables (i think you refer to them as areays) from any number(even negatives that dont wrap around to the end i dont think) but all the standard linraries only use whats in indexes 1 and up. You can also use strings
@nerdycatgamer
@nerdycatgamer 5 ай бұрын
Can you please make a video on macro/preprocessor in C? I like to look into the .h files in my /usr/include (habit taught to me by my prof), and there is some crazy wizardry with macros I just don't understand. It seems like a whole other language with its own syntax. I've even see stuff on SO about using macros for function overloading. So, even just a basic video on the foundation of the preprocessor and how to use it (effectively) would be sweet :)
@pedrovidal5634
@pedrovidal5634 5 ай бұрын
I'm doing all the challenges in C, which is my comfort language and the one I have to use the most at university (so it also allows me to practice a little bit with more difficult problems than I encounter in class). With multithreading and a fast language, part 2 is completely brute-forceable (took about 90s in my computer)
@williamthompson5988
@williamthompson5988 4 ай бұрын
Doing my AoC in Rust to help familiarize myself with the language. Brute forcing with no optimizations took 71s for me. I wonder how much of that was due to my hardware vs how much was because of the program structure I was using.
@jaycebrannon1520
@jaycebrannon1520 5 ай бұрын
The idx starting at 1 wasn't the worst, I just changed my thinking that it's all Tables and your can use index 0 it's just screws with the built-in metamethods like length, but you can write your own length method, which you need to anyway of you are using non-integer keys. What caught me up was that when Lua says local it means LOCAL. Had I bug that i just didn't understand and it's because I accidentally declared a local inside of an IF statement instead of before. Other than that, charming, small, easy to abstract language and I do love the logic passing values, and only nil and false being falsy has it's own advantages
@josephdvorak9241
@josephdvorak9241 5 ай бұрын
I was able to figure out an alternative to the brute force approach for part 2! I modified my solution so that it processes ranges of seeds as start and end values, then splits those ranges into processed and unprocessable ranges. It then feeds the unprocessable range into the next line, and finally returns all of the processed and remaining unprocessed ranges together as destination ranges. It repeats this process for each mapping and then finally sorts the resultant list of ranges by their starting range and returns Start value of the first item in the sorted list of ranges :)
@GordanCable
@GordanCable 5 ай бұрын
Very cool! I had the exact same idea and stumbled on the implementation. I finally got it to stop throwing negative numbers after a refactor, but ultimately failed to get a solution. I was up very late trying to debug it. Boy I wanted that star bad, but I had to give it up for bed. I will scratch it out eventually. Way to go!
@josephdvorak9241
@josephdvorak9241 5 ай бұрын
@GordanCable Thank you! And I know the feeling! Good luck!!
@colin_actually
@colin_actually 5 ай бұрын
I absolutely love lua
@villehietala9677
@villehietala9677 5 ай бұрын
Excel (without macros) should be on the wheel.
@user-vf8on4xv3j
@user-vf8on4xv3j 3 ай бұрын
Once you realize that a Lua array is not an array, but is in fact a hashmap, the choice of indexing based on 1 no longer seems so strange.
@dorianprill8190
@dorianprill8190 5 ай бұрын
love the series - you should put ocaml/f# on the board. rust FP skills should transition really well. i always wonder if one might use them as a scripting buddy language to rust (same language family after all)
@DarkblooM_IO
@DarkblooM_IO 5 ай бұрын
I'm doing the whole AoC in Lua, did not expect to pop up here
@t3dotgg
@t3dotgg 5 ай бұрын
I was so excited to watch you do part 2 in Lua 😭😭
@LowLevelLearning
@LowLevelLearning 5 ай бұрын
Would have suuuuuuucked with 1 indexed arrays lol
@kaitlynethylia
@kaitlynethylia 5 ай бұрын
@@LowLevelLearning if it's really that bad for you, you can make arrays 0 indexed just by doing { [0] = , , etc }
@LeonAlkoholik67
@LeonAlkoholik67 5 ай бұрын
Next year please choose random languages that viewers suggests, including non-mainstream languages that may have to be learned from scratch
@CrazyLuke11
@CrazyLuke11 5 ай бұрын
Do you want him to die?
@chuck0842
@chuck0842 5 ай бұрын
​@@CrazyLuke11 yes
@TheVertical92
@TheVertical92 5 ай бұрын
🤣great user name btw
@AlvinYap510
@AlvinYap510 5 ай бұрын
Add some esoteric languages perhaps? 👀
@ferdynandkiepski5026
@ferdynandkiepski5026 5 ай бұрын
For added content make sure to include assembly. LLVM-IR is close enough and would be more fun to watch. You could call external functions to make it easier. Besides he already knows assembly so it would be too easy.
@DocBolle
@DocBolle 5 ай бұрын
I solved it in Random Python:-). For part 2 I gave up on brute force and tried range mappings instead. It caused some headache to calculate all these range intersections - but it finally worked.
@hukasu
@hukasu 5 ай бұрын
my code using divide and conquer on part 2 takes 17ms on Rust (1ms on --release), I'm quite proud of how it turned out. I summed the amount of seeds it would need to process if you were to do brute force and it is over 1 billion.
@chinobijman3571
@chinobijman3571 5 ай бұрын
I started advent of code aswell, but it gets pretty tough when you do it all in C
@cookie_of_nine
@cookie_of_nine 5 ай бұрын
I found the better way to brute force part 2 is to work backwards through the mappings. You count up from 0 as locations, and work each backwards through the mappings to the seed-level to see if it was a valid seed. This is nicer because you can stop as soon as you find a result (the first location to work), since it by definition has to be the smallest, instead of having to process every input seed when going forward to prove that none are better than the latest minimum you found. My go solution was under 5s that way, without any form of threading, compared to > 5 minutes going forward. Note: I still tried the likely "intented" solution of processing each set of seeds as an interval, and have those pass through the mappings going forward. It took a lot of time to make sure my hand rolled ranges, and the interval splitting was working as expected so overall despite being 10x faster to solve (
@versacebroccoli7238
@versacebroccoli7238 5 ай бұрын
Thank you. I've been reading tips for a long time now and this was the first time I understood the backwards approach. I'm gonna see if I can make this work!
@mikkelens
@mikkelens 5 ай бұрын
ohhhh I saw someone say that they “did it in reverse” but this makes it a lot clearer how. I brute forced it in rust with basic non-parrelized iterators in rust (did some optimizations to my maps, parser types and iterator folding) and that ran on my PC around 1 mapping each 5-15 seconds for a total of like 1 minute and a bit. I wonder how much faster a “brute forced” version with this approach (same types) would be, parallelized
@lbgstzockt8493
@lbgstzockt8493 5 ай бұрын
Finally someone with a sane solution! I got done with part one but had to go to bed before I could implement that algorithm, though I did sketch it out on paper first to avoid getting lost.
@Stdvwr
@Stdvwr 5 ай бұрын
I did the second part the optimal way, but by the time I've fixed all the bugs the brute force would've finished long ago
@DeuxisWasTaken
@DeuxisWasTaken 5 ай бұрын
I'm happy that I encountered 1-indexed languages before I got too used to 0-indexing, so now it's not only not a problem, but I even prefer it that way. I'm somewhat convinced a noticeable percentage of off-by-one errors are caused by 0-indexing. Also, it's basically a C implementation detail, the way some people treat it as the One True Way to index arrays in programming is kinda dumb ngl.
@mxruben81
@mxruben81 2 ай бұрын
A lot of the time, 1-indexing doesn't matter. It's mostly personal preference. However, it can be pretty annoying if you're doing a lot of math involving arrays. I was making a 3D grid data structure in Lua and I had to add some -1s to get it to work, which isn't great if you need high performance.
@DeuxisWasTaken
@DeuxisWasTaken 2 ай бұрын
@@mxruben81 that's interesting. No way to change the way that structure works to be 1-indexing native? I'm genuinely curious about the details.
@skaruts
@skaruts 2 ай бұрын
I'll have to correct you here, because there are actually legit good reasons why people don't like 1-indexing. First, 0-indexing is not a c implementation detail. People keep spreading that around and it's wrong. 0-indexing has to do with pointer arithmetic, which isn't exclusive to C. In any compiled language, under the hood, a fixed array is (mostly) just a pointer to a memory address. A pointer is basically an integer, and you add a value to it in order to access the next array slots. By default it naturally points to the first slot in the array, and if you add 0 to it, it keeps pointing to that slot. If you add 1, it points to the 2nd slot, and so on. The array operator [ ] is syntactic sugar for the pointer arithmetic which would otherwise take a few lines of code to get done. 0-indexing is entirely preferable, because the indexing math only ever works with 0-indexing. In discussions about this topic, a lot of people confuse counting with indexing, but they're not the same thing and shouldn't be confused. With 0-indexing you can convert x, y coordinates into an array index using "x+y*grid_width", and from an index to x,y coords with "x = index % width" and "y = floor(index / width)". If you try to 1-index that grid, this won't work, and there's no way to adjust the math to make it work. Moreover, when a language is "1-indexed", that means the language itself expects you to 1-index your arrays. This is why in Lua, for loops include the upper limit: they expect you to loop from 1 to the limit inclusive (for i=1, 10 do ...), and whenever you want to loop from 0, then you must never forget to subtract 1 from the limit, which is a bit annoying and error prone. And you can't use ipairs on 0-indexed arrays, or the # operator. And then your programs will be inconsistent. You'll have arrays that are 1-indexed, others that are 0-indexed, and you either avoid ipairs entirely or you have to be paying attention where you can and can't use it, and sometimes you have to also pay close attention to code that interacts with both at the same time and requires indexing corrections. It's also a PITA to create utility functions that work with arrays, because you can't predict what users will throw at them, so you have to waste more time and effort making the functions support both index bases and making sure they both work properly. Or even other utilities. I've written an Enum library a few years ago, and to this day I still haven't decided if it should assume 0 or 1 indexing by default... It's also a PITA to port algorithms to and from other languages, as you have to keep attentively converting things to 1-indexing and making sure the algorithm doesn't break, or keeping 0-indexing and making sure you apply corrections to loops, or deciding which one to use... And then if the algorithm isn't working you have to double check the code, as well as all your array indexing conversions. I've been coding in lua for about 5 years and I absolutely love it like no other. But 1-indexing has been like a rock in the shoe: you can learn to live with it, but it never, ever stops being annoying af.
@mxruben81
@mxruben81 2 ай бұрын
@@skaruts Not to mention the fact that unless you are using luajit, if you 0-index, that data is in the hash part of the table instead of the array part, which hurts the performance of your code a bit. Not sure how much. I do agree, I would much rather just have 0-indexed arrays, but I've learned to adapt.
@skaruts
@skaruts 2 ай бұрын
@@mxruben81 that's true, according to the 5.1 manual, at least. But tbh I've never noticed any performance hit from it, so I always just use what makes more practical sense. I made a game of life in TIC-80, which doesn't use luaJIT and I tried both ways, and didn't see any difference. I was hunting for any micro-optimizations I could find.
@AWIRE_onpc
@AWIRE_onpc 5 ай бұрын
lua is an awesome language. Considering you have alot of C experience, you could modify the interpreter to your liking.
@capncoolio
@capncoolio 5 ай бұрын
So I first learned LUA back in the day writing scripts for WireMOD for GMod, and then totally forgot about it until a few months ago, when I took over maintenance of a popular Cyberpunk 2077 mod which is written in LUA (it runs on the LUA sandbox someone else made that sits over the game) At first I really hated it, but honestly now I find it refreshingly small, and frankly doing everything with tables is an interesting enough constraint that it lends itself to creative programming (though lot of this is made easier by the fact that the only "quality" I need to worry about is "does my code at least not explode other people's computers?")
@ozmer
@ozmer 5 ай бұрын
Lua should release two versions of their interpreter, one that starts index at 0 and the other at 1. That way everyone is happy and all problems are solved.
@pmoohkt
@pmoohkt 5 ай бұрын
Did the brute force solution using Scala: took 5 minutes to compute, so it's definitively possible. But there's a faster solution based clever use of intervals, instead of individual seed numbers, too clever for me 😁
@PoProstuLatanie
@PoProstuLatanie 5 ай бұрын
I coded my solution in C, and the bright side of this is that it's fast by nature, so I bruteforced it, and it took less than half a minute to complete
@aaronchamberlain4698
@aaronchamberlain4698 5 ай бұрын
TBH I like Lua. I learned it to help with the open source video game “Journey to the Center of Hawkthorne” which is an actual build of the game from the TV show community.
@newsofthenerd
@newsofthenerd 5 ай бұрын
I did day 5 in C and the second part took my laptop more than 6 minutes to spit out a number and thank god it happened to be correct.
@9remi
@9remi 5 ай бұрын
where are the last few days?
@joachimhorshauge
@joachimhorshauge 5 ай бұрын
He tweeted this: no advent of code for a few days, traveling for work. its not because haskell is still on the board this isnt a cry for help.
@9remi
@9remi 5 ай бұрын
@@joachimhorshauge oh lmfao
@danielsharp2402
@danielsharp2402 5 ай бұрын
It's actually feasible to just generate the range around 20-30 minutes to get the answer but it gets it. I had to do that due to having a bug in the "nice" implementation I would not have been able to find wtihout the solution.
@mapelsiroup5604
@mapelsiroup5604 5 ай бұрын
you should add eiffel if its not on the wheel yet, it would be pretty interesting because of its very restricting void safety standards. good OOP language
@ericbwertz
@ericbwertz 5 ай бұрын
This challenge is really the off-by-one challenge.
@monad_tcp
@monad_tcp 5 ай бұрын
as all array access is with anything that's not APL
@monad_tcp
@monad_tcp 5 ай бұрын
Its impossible to make off-by-one errors in APL
@ericbwertz
@ericbwertz 5 ай бұрын
@@monad_tcp There are two types of programmers -- those that start counting from 0 and those from 1. And they never line up on anything.
@ericbwertz
@ericbwertz 5 ай бұрын
@@monad_tcp Sure, and there's nothing preventing one from restricting oneself to using a matrix class that hides the zero vs one-based addressing. But unless that abstraction is near zero-cost, people using big data get pretty finicky when it comes to performance and may want/need to perform array dentistry themselves.
@monad_tcp
@monad_tcp 5 ай бұрын
@@ericbwertz maybe that's why basic had `set base 0/1` or something. I though about Lua metatables, there's a way to do arbitrary indexing, but that would be definitively no a zero-cost abstraction. In the end you're right, when you need performance, you have to accept less optimal code.
@ThrowTop
@ThrowTop 5 ай бұрын
luaJIT also has ffi. which allows for manual memory managment. and is extremly fast
@VivekYadav-ds8oz
@VivekYadav-ds8oz 5 ай бұрын
I did it in Rust, and I parsed out each map in a Map struct, which is basically just a sorted vector, where each element is a tuple of a range to a range (i.e Vec ). This vector is basically just a poor man's table mapping src range to destination range. The vector is sorted based on the start of the first range i.e start of the src range. This gives us sorted intervals, within which you can just binary_search your seed. When you have parsed all the maps into a Vec, now you can just .fold over this vector and get out the final location. (maps.iter().fold(seed_i, |curr_seed, map| map.get(curr_seed)) ). Do this for all seed_i and get their minimum. For the second part, I simply ran the new parsed out ranges of seeds (there were 10 ranges ig?) into their own threads. This was kinda hacky since some ranges were really large and some small, so not all threads got the same load. In fact, most of the threads finished within 4-5 seconds, except the last two which ran for a good 10 seconds more. Ultimately, the program terminated in 20-21 seconds, and I had the solution in my hands. I feel this solution would be unfair to poor people with old computers. I have a mid-range laptop with 6 cores, so it wasn't that bad. So I think there might be some other solution that I'm not seeing.
@iamnotgoodwithcomputer
@iamnotgoodwithcomputer 5 ай бұрын
what kicked me in the balls about lua a few times is the fact that anything that could be a variable is basically initialized to nil. you can use a variable that was never declared and/or initialized. so if you do something like if (varialbe == value) then ... end ... but you have a typo in variable and write varialbe like the dyslexic idiot that i am, that condition will simply never fire. good debugging times ahead! but otherwise it's a great language for simple interoperability and parametrization of large C and C++ programs :)
@ThrowTop
@ThrowTop 5 ай бұрын
in a repeat untill loop the break statement is actually a continue, and to actually break u need to use goto.
@georgerogers1166
@georgerogers1166 5 ай бұрын
Lua is as fast as JS. LuaJIT is insane, similar to modern JS Jits.
@Pillboxing
@Pillboxing 5 ай бұрын
It's not even close anymore sadly. JS is a minimum of 10x faster than luaJIT now
@skaruts
@skaruts 2 ай бұрын
@@Pillboxing source?
@AlvinYap510
@AlvinYap510 5 ай бұрын
Hahahaha... Rookie here. I just solved this question with JS. Part2 almost fried my cpu with 1 billion+ seeds until I reimplement it reversely 🤣
@KvapuJanjalia
@KvapuJanjalia 5 ай бұрын
I wrote two simple World of Warcraft add-ons in Lua. ... and after the recent game patch both stopped working and I have no clue how to debug them.
@ilikecats5396
@ilikecats5396 5 ай бұрын
really cool that my teacher in discrete structutes this semester was one of the creators of Lua!
@spacelem
@spacelem 2 ай бұрын
I've never coded in Lua before, but as a mathematician, most other languages I've used are 1-based (R, Julia, Matlab, Octave, Maple, Maxima, and Mathematica). I haven't used Fortran, but I believe that's 1-based too. I find 1-based a lot more intuitive, and most of these languages come with ways of handing arrays such that the odd occasions when 0-based makes life easier never really appear.
@EricaCalman
@EricaCalman 5 ай бұрын
I only even know it exist because unknown worlds decided to write large parts of Natural Selection 2 in Lua.
@willzin-da-esfiha
@willzin-da-esfiha 5 ай бұрын
Use ranges (store only start and end) and do some set theory calculations (i.e.: intersections) That's it
@vihashah5975
@vihashah5975 5 ай бұрын
i’m doing that but dealing with off by one errors 😭rip
@FZs1
@FZs1 5 ай бұрын
I did it in Rust and I didn't have enough time either to implement Part 2 properly (i.e. not brute-force), although I have an idea how to. I let it run and it got the answer in about a minute.
@torarinvik4920
@torarinvik4920 5 ай бұрын
Add Smalltalk to the board! Both Pharo and Squeak are good.
@woofcaptain8212
@woofcaptain8212 5 ай бұрын
I still want to see you try lisp
@plugadapter2411
@plugadapter2411 5 ай бұрын
Part 2 was such a pain. I just ended up using a brute force solution which took 8 minutes to run in python.
@kizigamer6895
@kizigamer6895 5 ай бұрын
what? me here stuck on day 3 and it seems i just peaked to day 5 and day 5 is just on another level of dificulty jump
@TheSmallzfry
@TheSmallzfry 5 ай бұрын
@@kizigamer6895 That tends to be how Advent of Code goes. I don't think I've ever actually made it past day 5, as I start taking longer and longer to get working solutions. Luckily the puzzles stay up year-round so you can work on them slowly if you want.
@wolodiam9013
@wolodiam9013 5 ай бұрын
My code for part 2 (in c++, brute force - check each seed number, and find the minimum result) took about 20 minutes ;)
@ferdynandkiepski5026
@ferdynandkiepski5026 5 ай бұрын
​@@wolodiam9013how did you make it slower than python? I'm genuinely curious.
@peytondaley4991
@peytondaley4991 5 ай бұрын
What I did for part two was changing the representation of the seeds to be a tuple (min, max), so that you don't have to save every number in the range. Then you just check what part of that range is in the range given. You have to then create the ranges that weren't contained and also check those, but even in python the part 2 input takes a second.
@Intrebute
@Intrebute 5 ай бұрын
I've been doing these in Rust and the brute-force solution took me 20 minutes of runtime. I can't imagine how long it'd have taken in your setup.
@frolvanya
@frolvanya 5 ай бұрын
Wow, you have used rayon and you still waited for 20 mins?
@xtieburn
@xtieburn 5 ай бұрын
Yesterdays puzzle was so easy, then bam! this jerk of a problem. So many instructions I completed part 1 faster than it took to read and understand what it was asking. Then I screwed up my range handling for part 2 in such a way that it worked for the test data but not the real thing. I actually did brute force then used that to debug it. That said, reducing the time from 15 minutes or so to 5 thousandths of a second* was veeery satisfying. *In JavaScript cause its the easiest way I can take and do these puzzles wherever I go or whatever system Im on.
@AdamMaryniuk
@AdamMaryniuk 5 ай бұрын
Are you ever going to do the final conclusion video for the baby monitor?
@LowLevelLearning
@LowLevelLearning 5 ай бұрын
When I catch some free time to actually do the RF capture yes. Hopefully early next year :)
@EximiusDux
@EximiusDux 5 ай бұрын
Lua was used to script the very first Farcry (2004) game. It's old but does have a long and decent history.
@bhavyakukkar
@bhavyakukkar 5 ай бұрын
im learning lua right now fingers crossed this video helps
@reed6514
@reed6514 5 ай бұрын
I brute forced in php, but had to essentially stream the seed numbers, after putting them all in an array at the start failed 😂. Then i had to optimize AND run 9 different processes and ... i still failed lol
@sudospective
@sudospective 5 ай бұрын
i find it fascinating that reading 1-index could be considered difficult after being affixed to 0-index, thats a neat way to solve the readability problem
@SPDM_Riky47
@SPDM_Riky47 26 күн бұрын
Roblox Developer here, lua/luau tables are probably the best thing i ever seen in my life, it can be anything, arrays, dicts, "objects", ...awesome.
@spicywe1ner
@spicywe1ner 5 ай бұрын
incredible how fast you were able to pick up lua. what a champ
@trentondickey9061
@trentondickey9061 5 ай бұрын
Good ole Lua. I only remember this because it is what computercraft used in Minecraft years ago and I think it was my real first programming language lol
@mementomori8856
@mementomori8856 5 ай бұрын
I had to restart my PC TWICE trying to solve the part 2, still struggling. I've come up with a better solution that brute force but implementing it will be PAINFUL!
@mxruben81
@mxruben81 2 ай бұрын
I like Luau (it's derived from lua) because it fixes a lot of the ugly parts of lua while staying simple giving you optional type annotations. It still has the 1 indexed arrays, but once you get used to it, it really isn't as huge of a deal as many make it out to be.
@m1geo
@m1geo 5 ай бұрын
3:50 "We're going to do '0+1' and you're going to be okay!" lol
@godDIEmanLIVE
@godDIEmanLIVE 5 ай бұрын
This series is really cool.
@EliasOjeda-mv6cg
@EliasOjeda-mv6cg 5 ай бұрын
what distro do you use ?
@bckends_
@bckends_ 5 ай бұрын
that title single-handedly reduced Primegean's lifespan by 5 years
@Maxjoker98
@Maxjoker98 2 ай бұрын
Lua's strength is it's simplicity. Lua tables are the most elegant aggregate type in any programming language I've every seen. Yes, "indices" start from 1 in Lua, which is perfectly reasonable when used consistently, just as indices starting at 0. Languages choose 0 as a starting index because it's convenient for pointers, which Lua doesn't have. Also you can just use 0-indexed tables in Lua. Again, tables are so elegant, and Lua is so simple and flexible, the only way in which Lua is truely 1-indexed is table initialization(`t={11,22,33}`), which puts the first value at index a(but this is just "syntactic sugar"; The first index(or any key to a table) is in no way special, and you can just assign a value to the 0-index as well: `t={[0]=0, 11,22,33 }`). EDIT: Bruv, he just called Lua more cursed than C++. WHAT ARE YOU EVEN ON MY DUDE?!?!? Stop huffing that paint thinner...
@jamesmorrison9893
@jamesmorrison9893 5 ай бұрын
I allocated 9 GB of memory and brute forced the hell out of part 2 in my C implementation. ~5 minutes to complete 😄
@whamer100
@whamer100 5 ай бұрын
this stream was really funny
@nyvyme
@nyvyme 9 күн бұрын
and now imagine that all mods for tboi and addons for gmod are written in lua
@norndev
@norndev 5 ай бұрын
Should add the "pawn" language by compuphase, like lua it's been used for game scripting
@turanamo
@turanamo 5 ай бұрын
Lua was my first crush before I hitched on to C
@magneto133
@magneto133 5 ай бұрын
I only use lua for my neovim config 😂
@afterschool2594
@afterschool2594 5 ай бұрын
Man day 5 part 2 took me 8 hours to get it working in 1 minute++ in Rust Release Mode
@WeirdDuck781
@WeirdDuck781 5 ай бұрын
Lua is literally where I learned coding... Think I would've had a better start in C# tbh
@kez963
@kez963 5 ай бұрын
Do you have Pascal on your list? :D
@user-kp6ir4ih9s
@user-kp6ir4ih9s 5 ай бұрын
I am kinda disapointed about skipping part 2. I was waiting exactly for it :/ Bruteforce is a correct, but dummy solution :C
@LowLevelLearning
@LowLevelLearning 5 ай бұрын
I know I really wanted to finish it, but unfortunately I had to go to my J O B XD
@jackjack9196
@jackjack9196 5 ай бұрын
I did it in php. No brute force. I lost my mental sanity, but it was worth it in the end
@kinositajona
@kinositajona 5 ай бұрын
Someone did brute force in Rust using release mode and it took 2 minutes to complete...... so yeah.... maybe leave it on overnight? lol
@heylookitsnoah
@heylookitsnoah 5 ай бұрын
bro had to change the title because of the backfire, love to see it
@prawnydagrate
@prawnydagrate 5 ай бұрын
lmao my rust solution just barely worked, taking 5 minutes and 31 seconds for part two
@TimothyChapman
@TimothyChapman 5 ай бұрын
TIL: Lua has goto statements! That would have been good to know a long time ago.
@bitwise4996
@bitwise4996 5 ай бұрын
I use Lua to do everything in my life. Honestly, I can't replace it with anything else. It should replace slow/heavy JS.
@goblinjedly9528
@goblinjedly9528 5 ай бұрын
lua is WAY faster then most interpreted progrmaming languages
@monad_tcp
@monad_tcp 5 ай бұрын
3:55 lol, my seeds.
@TableTopFinder
@TableTopFinder 5 ай бұрын
For part two, I brute forced all seed calculations in Go. Script took 3.5minutes 😅
@TableTopFinder
@TableTopFinder 5 ай бұрын
Got it down to 15 seconds using optimizations and Go routines. 🥳
@BaldiReycaster
@BaldiReycaster 5 ай бұрын
YOU WILL NOT BE FORGIVEN FOR YOUR HEINOUS ACTIONS.
@jared_per
@jared_per 5 ай бұрын
Goto in lua works differently than goto in some other languages. Goto gets a bad reputation to my knowledge because some languages it can push you to unexpected places. In lua it has to be in the same scope. You can't goto a different function.
@jared_per
@jared_per 5 ай бұрын
I do wish it had += and continue though
@arandomguythatdoesntpost
@arandomguythatdoesntpost 5 ай бұрын
LuaU has both :)
@jared_per
@jared_per 5 ай бұрын
@@arandomguythatdoesntpost I've been meaning to try luau. I shall do it soon
@alexanderkimmel7019
@alexanderkimmel7019 5 ай бұрын
lua just seems like pseudo code with the indenting from 1 and the if ... then
@user-cy1rm5vb7i
@user-cy1rm5vb7i 5 ай бұрын
you haven't seen COBOL, it's nothing BUT pseudo code and it's horrific 😱@@thetukars
@mkass420
@mkass420 5 ай бұрын
I haven't ever typed a single line of lua, but i swear, this looks like pascal and python has a child
@youcefmoulla1828
@youcefmoulla1828 5 ай бұрын
Lua is just a new version of Fortran
@giuseppesec
@giuseppesec 5 ай бұрын
lua is the fastest interpreted language though. its basically a wrapper around c. plus if you're doing game mods; gmod and WoW have lua scripting engines. and if you're doing cybersecurity; nmap and wireshark have lua scripting engines. goated lang
@TagetesAlkesta
@TagetesAlkesta 5 ай бұрын
Dudes forget Haskell, we need to get HolyC onto this wheel
@costelinha1867
@costelinha1867 4 ай бұрын
Me when I see people tell me Lua is a Brazilian language as a selling point (I'm Brazillian): "Yeah, Lua is Brazilian, AND THEY MESSED UP THE BASIC FUNDAMENTAL OF ARRAYS STARTING AT 0!"
@donwinston
@donwinston 5 ай бұрын
I think Redis is implemented in Lua.
PHP is Wack. (Coding in a Random Language Every Day)
14:41
Low Level Learning
Рет қаралды 53 М.
why does inheritance suck?
8:05
Low Level Learning
Рет қаралды 201 М.
[柴犬ASMR]曼玉Manyu&小白Bai 毛发护理Spa asmr
01:00
是曼玉不是鳗鱼
Рет қаралды 44 МЛН
Кәріс тіріма өзі ?  | Synyptas 3 | 8 серия
24:47
kak budto
Рет қаралды 1,7 МЛН
WHY DOES SHE HAVE A REWARD? #youtubecreatorawards
00:41
Levsob
Рет қаралды 29 МЛН
Why Is Lua So Popular?
8:03
Awesome
Рет қаралды 82 М.
How Many ERRORS Can You Fit in a Video?!
20:40
ElectroBOOM
Рет қаралды 713 М.
Rust Finally Betrayed Me (Coding in a Random Language Every Day)
14:49
Low Level Learning
Рет қаралды 85 М.
The purest coding style, where bugs are near impossible
10:25
Coderized
Рет қаралды 851 М.
Where Lua Is Actually Used
9:25
Tortellini Soup
Рет қаралды 13 М.
everyone codes faster when they stop using their mouse
10:32
Low Level Learning
Рет қаралды 189 М.
Don't Write Comments
5:55
CodeAesthetic
Рет қаралды 762 М.
This is Why Programming Is Hard For you
10:48
The Coding Sloth
Рет қаралды 537 М.
AMD больше не конкурент для Intel
0:57
ITMania - Сборка ПК
Рет қаралды 474 М.
What’s your charging level??
0:14
Татьяна Дука
Рет қаралды 7 МЛН
3D printed Nintendo Switch Game Carousel
0:14
Bambu Lab
Рет қаралды 4,6 МЛН
The power button can never be pressed!!
0:57
Maker Y
Рет қаралды 52 МЛН
What percentage of charge is on your phone now? #entertainment
0:14