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

  Рет қаралды 69,458

Low Level

Low Level

Күн бұрын

Пікірлер: 416
@rafaelbordoni516
@rafaelbordoni516 Жыл бұрын
Lua is the C of the interpreted languages, extremely simple and small. Probably the easiest language to teach kids programming.
@torarinvik4920
@torarinvik4920 Жыл бұрын
I agree 100%, it's simplicity is masterful. It looks and feels nice too just like Ruby and Python.
@LowLevelTV
@LowLevelTV Жыл бұрын
love that
@revengerwizard
@revengerwizard Жыл бұрын
Comparing Lua to C is kind of unfair
@FaZekiller-qe3uf
@FaZekiller-qe3uf Жыл бұрын
@@torarinvik4920Python does not feel nice
@charlieking7600
@charlieking7600 Жыл бұрын
​​@@FaZekiller-qe3ufbecause it feels awesome. Many built-in functions, structures, powerful slices, lambdas and iterators.
@AntonioZL
@AntonioZL Жыл бұрын
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 Жыл бұрын
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 ❤❤❤
@yodo9000
@yodo9000 9 ай бұрын
# is unintuitive for tables with discontinuous indices. It will give the length up to the first nil value.
@realEchoz
@realEchoz 3 ай бұрын
@@yodo9000 to make things worse that's only sometimes true and depends on the internal memory layout
@onrir
@onrir Жыл бұрын
lua-jit is faster than python by a large margin and pretty light on resource consumption aswell.
@fhudufin
@fhudufin Жыл бұрын
normal lua is faster than python iirc
@onrir
@onrir Жыл бұрын
@@fhudufin to be fully honest, python is not a very hard benchmark to pull off lmfao
@skaruts
@skaruts Жыл бұрын
If it exists, it's faster than python.
@kuhluhOG
@kuhluhOG Жыл бұрын
well, the default Python implementation (CPython) there are some which are A LOT faster
@onrir
@onrir Жыл бұрын
@@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.
@glennedgar5057
@glennedgar5057 Жыл бұрын
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 Жыл бұрын
What are the 100k and 500m that you speak of?
@orbyfied
@orbyfied Жыл бұрын
@@MavikBow bytes of memory i assume
@kuhluhOG
@kuhluhOG Жыл бұрын
I hate the fact that KZbin is bugged on my end so that I can't see the "See More".
@cocbuilds
@cocbuilds Жыл бұрын
@@kuhluhOG try different account? if on PC try in guest mode maybe, probably an extension or your account
@kuhluhOG
@kuhluhOG Жыл бұрын
@@cocbuilds tried it already, doesn't matter
@xavxavierm
@xavxavierm Жыл бұрын
Cool video, lua is surprisingly integrated into many applications though. its good to know
@LowLevelTV
@LowLevelTV Жыл бұрын
Indeed!
@no_name4796
@no_name4796 Жыл бұрын
neovim itself uses lua, btw
@romanstingler435
@romanstingler435 Жыл бұрын
@@LowLevelTVDon't tell @teej_dv the title of your video
@Raspredval1337
@Raspredval1337 Жыл бұрын
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
@Cathyprime
@Cathyprime Жыл бұрын
I will not stand for this slander of neovim's config language
@NostraDavid2
@NostraDavid2 Жыл бұрын
Also world of warcraft addons
@murat.h
@murat.h Жыл бұрын
@@NostraDavid2 Also scripting language for roblox
@callyral
@callyral Жыл бұрын
Also Wezterm config language and AwesomeWM's config language Lua seems really popular for configuring stuff huh
@universaltoons
@universaltoons Жыл бұрын
​@@murat.hroblox uses Luau
@josephbrandenburg4373
@josephbrandenburg4373 7 ай бұрын
OpenMW scripting!
@CadenParajuli
@CadenParajuli 10 ай бұрын
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.
@terdik36
@terdik36 Жыл бұрын
roblox and fivem developers are shaking rn
@flamendless
@flamendless Жыл бұрын
Lua is slow, but LuaJIT is the blackest magic there is
@The_RoboDoc
@The_RoboDoc Жыл бұрын
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 Жыл бұрын
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)
@AlLiberali
@AlLiberali Жыл бұрын
Same. It's currently running
@yjlom
@yjlom Жыл бұрын
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 Жыл бұрын
@@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 Жыл бұрын
@@yjlom That's... that's kinda impressive ngl :DDD
@FireDragon91245
@FireDragon91245 Жыл бұрын
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 Жыл бұрын
The complexity doesn't really depend that much on a language more like on the project itself.
@armincal9834
@armincal9834 Жыл бұрын
@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 Жыл бұрын
@@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
@RedHair651
@RedHair651 6 ай бұрын
C is not simple
@shalokshalom
@shalokshalom 4 ай бұрын
thanks for making me aware about function environments
@pseudonymity0000
@pseudonymity0000 Жыл бұрын
Hot take... Lua should of been used for the web instead of JS
@CEOofGameDev
@CEOofGameDev Жыл бұрын
Funny you should mention it, since Emilua (basically lua's node.js) dropped a new version literally yesterday.
@jumpsplat120
@jumpsplat120 Жыл бұрын
Based take.
@torphedo6286
@torphedo6286 Жыл бұрын
true!
@caerphoto
@caerphoto Жыл бұрын
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 Жыл бұрын
@thetukars Brendan Eich (JS creator) said that if he was not forced by business, JS would be functional with Scheme syntax.
@bckends_
@bckends_ Жыл бұрын
that title single-handedly reduced Primegean's lifespan by 5 years
@hudsonator7259
@hudsonator7259 Жыл бұрын
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
@joaopedrorocha5693
@joaopedrorocha5693 3 ай бұрын
I think that the goto stuff for doing a continue in a loop is quite intentional ... the Lua architect is a fan of functional languages (that's why to comment is "--" just like in haskell), probably he left the loops as simple as possible so people would be more prone to use recursion instead of loops in these situations.
@josephdvorak9241
@josephdvorak9241 Жыл бұрын
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 Жыл бұрын
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 Жыл бұрын
@GordanCable Thank you! And I know the feeling! Good luck!!
@AlkoholOgerLeonElektronik67
@AlkoholOgerLeonElektronik67 Жыл бұрын
Next year please choose random languages that viewers suggests, including non-mainstream languages that may have to be learned from scratch
@CrazyLuke11
@CrazyLuke11 Жыл бұрын
Do you want him to die?
@chuck0842
@chuck0842 Жыл бұрын
​@@CrazyLuke11 yes
@TheVertical92
@TheVertical92 Жыл бұрын
🤣great user name btw
@AlvinYap510
@AlvinYap510 Жыл бұрын
Add some esoteric languages perhaps? 👀
@ferdynandkiepski5026
@ferdynandkiepski5026 Жыл бұрын
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.
@villehietala9677
@villehietala9677 Жыл бұрын
Excel (without macros) should be on the wheel.
@m1geo
@m1geo Жыл бұрын
3:50 "We're going to do '0+1' and you're going to be okay!" lol
@pedrovidal5634
@pedrovidal5634 Жыл бұрын
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 Жыл бұрын
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.
@iamnotgoodwithcomputer
@iamnotgoodwithcomputer Жыл бұрын
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 :)
@AWIRE_onpc
@AWIRE_onpc Жыл бұрын
lua is an awesome language. Considering you have alot of C experience, you could modify the interpreter to your liking.
@t3dotgg
@t3dotgg Жыл бұрын
I was so excited to watch you do part 2 in Lua 😭😭
@LowLevelTV
@LowLevelTV Жыл бұрын
Would have suuuuuuucked with 1 indexed arrays lol
@kaitlynethylia
@kaitlynethylia Жыл бұрын
@@LowLevelTV if it's really that bad for you, you can make arrays 0 indexed just by doing { [0] = , , etc }
@jaycebrannon1520
@jaycebrannon1520 Жыл бұрын
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
@Stdvwr
@Stdvwr Жыл бұрын
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
@DarkblooM_IO
@DarkblooM_IO Жыл бұрын
I'm doing the whole AoC in Lua, did not expect to pop up here
@nerdycatgamer
@nerdycatgamer Жыл бұрын
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 :)
@cookie_of_nine
@cookie_of_nine Жыл бұрын
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 Жыл бұрын
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 Жыл бұрын
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 Жыл бұрын
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.
@colin_actually
@colin_actually Жыл бұрын
I absolutely love lua
@PoProstuLatanie
@PoProstuLatanie Жыл бұрын
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
@newsofthenerd
@newsofthenerd Жыл бұрын
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.
@ozmer
@ozmer Жыл бұрын
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.
@yante7
@yante7 Жыл бұрын
where are the last few days?
@joachimhorshauge
@joachimhorshauge Жыл бұрын
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.
@yante7
@yante7 Жыл бұрын
@@joachimhorshauge oh lmfao
@hukasu
@hukasu Жыл бұрын
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.
@ericbwertz
@ericbwertz Жыл бұрын
This challenge is really the off-by-one challenge.
@monad_tcp
@monad_tcp Жыл бұрын
as all array access is with anything that's not APL
@monad_tcp
@monad_tcp Жыл бұрын
Its impossible to make off-by-one errors in APL
@ericbwertz
@ericbwertz Жыл бұрын
@@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 Жыл бұрын
@@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 Жыл бұрын
@@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.
@georgerogers1166
@georgerogers1166 Жыл бұрын
Lua is as fast as JS. LuaJIT is insane, similar to modern JS Jits.
@Pillboxing
@Pillboxing Жыл бұрын
It's not even close anymore sadly. JS is a minimum of 10x faster than luaJIT now
@skaruts
@skaruts 9 ай бұрын
@@Pillboxing source?
@heylookitsnoah
@heylookitsnoah Жыл бұрын
bro had to change the title because of the backfire, love to see it
@youcefmoulla1828
@youcefmoulla1828 Жыл бұрын
Lua is just a new version of Fortran
@DocBolle
@DocBolle Жыл бұрын
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.
@spacelem
@spacelem 9 ай бұрын
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.
@dorian2718
@dorian2718 Жыл бұрын
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)
@plugadapter2411
@plugadapter2411 Жыл бұрын
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 Жыл бұрын
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 Жыл бұрын
@@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 Жыл бұрын
My code for part 2 (in c++, brute force - check each seed number, and find the minimum result) took about 20 minutes ;)
@ferdynandkiepski5026
@ferdynandkiepski5026 Жыл бұрын
​@@wolodiam9013how did you make it slower than python? I'm genuinely curious.
@peytondaley4991
@peytondaley4991 Жыл бұрын
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.
@chinobijman3571
@chinobijman3571 Жыл бұрын
I started advent of code aswell, but it gets pretty tough when you do it all in C
@giuseppesec
@giuseppesec Жыл бұрын
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
@mxruben81
@mxruben81 10 ай бұрын
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.
@TagetesAlkesta
@TagetesAlkesta Жыл бұрын
Dudes forget Haskell, we need to get HolyC onto this wheel
@AlvinYap510
@AlvinYap510 Жыл бұрын
Hahahaha... Rookie here. I just solved this question with JS. Part2 almost fried my cpu with 1 billion+ seeds until I reimplement it reversely 🤣
@woofcaptain8212
@woofcaptain8212 Жыл бұрын
I still want to see you try lisp
@BaldiReycaster
@BaldiReycaster Жыл бұрын
YOU WILL NOT BE FORGIVEN FOR YOUR HEINOUS ACTIONS.
@DeuxisWasTaken
@DeuxisWasTaken Жыл бұрын
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 10 ай бұрын
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 10 ай бұрын
@@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 9 ай бұрын
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 9 ай бұрын
@@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 9 ай бұрын
@@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.
@torarinvik4920
@torarinvik4920 Жыл бұрын
Add Smalltalk to the board! Both Pharo and Squeak are good.
@sudospective
@sudospective Жыл бұрын
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 8 ай бұрын
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.
@ilikecats5396
@ilikecats5396 Жыл бұрын
really cool that my teacher in discrete structutes this semester was one of the creators of Lua!
@capncoolio
@capncoolio Жыл бұрын
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?")
@ThrowTop
@ThrowTop Жыл бұрын
luaJIT also has ffi. which allows for manual memory managment. and is extremly fast
@EricaCalman
@EricaCalman Жыл бұрын
I only even know it exist because unknown worlds decided to write large parts of Natural Selection 2 in Lua.
@aaronchamberlain4698
@aaronchamberlain4698 Жыл бұрын
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.
@goblinjedly9528
@goblinjedly9528 Жыл бұрын
lua is WAY faster then most interpreted progrmaming languages
@nyvyme
@nyvyme 7 ай бұрын
and now imagine that all mods for tboi and addons for gmod are written in lua
@mapelsiroup5604
@mapelsiroup5604 Жыл бұрын
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
@Intrebute
@Intrebute Жыл бұрын
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 Жыл бұрын
Wow, you have used rayon and you still waited for 20 mins?
@turanamo
@turanamo Жыл бұрын
Lua was my first crush before I hitched on to C
@bhavyakukkar
@bhavyakukkar Жыл бұрын
im learning lua right now fingers crossed this video helps
@jared_per
@jared_per Жыл бұрын
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 Жыл бұрын
I do wish it had += and continue though
@arandomguythatdoesntpost
@arandomguythatdoesntpost Жыл бұрын
LuaU has both :)
@jared_per
@jared_per Жыл бұрын
@@arandomguythatdoesntpost I've been meaning to try luau. I shall do it soon
@comradepeter87
@comradepeter87 Жыл бұрын
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.
@mkass420
@mkass420 Жыл бұрын
I haven't ever typed a single line of lua, but i swear, this looks like pascal and python has a child
@spicywe1ner
@spicywe1ner Жыл бұрын
incredible how fast you were able to pick up lua. what a champ
@danielsharp2402
@danielsharp2402 Жыл бұрын
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.
@ЯрославСвиридов-в7б
@ЯрославСвиридов-в7б Жыл бұрын
I am kinda disapointed about skipping part 2. I was waiting exactly for it :/ Bruteforce is a correct, but dummy solution :C
@LowLevelTV
@LowLevelTV Жыл бұрын
I know I really wanted to finish it, but unfortunately I had to go to my J O B XD
@EximiusDux
@EximiusDux Жыл бұрын
Lua was used to script the very first Farcry (2004) game. It's old but does have a long and decent history.
@willzin-da-esfiha
@willzin-da-esfiha Жыл бұрын
Use ranges (store only start and end) and do some set theory calculations (i.e.: intersections) That's it
@vihashah5975
@vihashah5975 Жыл бұрын
i’m doing that but dealing with off by one errors 😭rip
@KvapuJanjalia
@KvapuJanjalia Жыл бұрын
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.
@pmoohkt
@pmoohkt Жыл бұрын
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 😁
@alexanderkimmel7019
@alexanderkimmel7019 Жыл бұрын
lua just seems like pseudo code with the indenting from 1 and the if ... then
@Raspredval1337
@Raspredval1337 Жыл бұрын
you haven't seen COBOL, it's nothing BUT pseudo code and it's horrific 😱@thetukars
@FZs1
@FZs1 Жыл бұрын
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.
@EdKolis
@EdKolis Жыл бұрын
Urist picks up the +masterwork+ =diamond= ::continue:: label. The voidpointer is confused!
@4ngelf
@4ngelf 2 ай бұрын
A whole year of programming in lua, and I didn't know it has a goto syntax :v
@costelinha1867
@costelinha1867 Жыл бұрын
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!"
@NKCSS
@NKCSS Жыл бұрын
7:50 spotting the off-by-ones and know it’s a VOD not being able to help, just hoping he catches it quick 😅
@NKCSS
@NKCSS Жыл бұрын
Thanks chat at 8:23 😂
@ChungusTheLarge
@ChungusTheLarge Жыл бұрын
Neovim users are in shambles
@trentondickey9061
@trentondickey9061 Жыл бұрын
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
@caerphoto
@caerphoto Жыл бұрын
I dare you to put some form of Pascal on the wheel.
@rawadventures9597
@rawadventures9597 Жыл бұрын
Fun fact: "Lua" actually means Winter Hat in my language and you're wearing one :)
@alstin112
@alstin112 Жыл бұрын
What is your language ?
@iatheman
@iatheman Жыл бұрын
And it means moon in Portuguese :) Maybe now its logo will make more sense. It was created in Brazil too.
@rawadventures9597
@rawadventures9597 Жыл бұрын
@@alstin112 Norwegian
@WeirdDuck781
@WeirdDuck781 Жыл бұрын
Lua is literally where I learned coding... Think I would've had a better start in C# tbh
@monad_tcp
@monad_tcp Жыл бұрын
3:55 lol, my seeds.
@randy7894
@randy7894 7 ай бұрын
Programming in Lua is reliving my childhood all over again programming in basic. Easy and pretty cool for making 2d games that does not require optimazation and enourmous computations. Löve this shit.
@ThrowTop
@ThrowTop Жыл бұрын
in a repeat untill loop the break statement is actually a continue, and to actually break u need to use goto.
@jerodev2
@jerodev2 Жыл бұрын
For part two, I brute forced all seed calculations in Go. Script took 3.5minutes 😅
@jerodev2
@jerodev2 Жыл бұрын
Got it down to 15 seconds using optimizations and Go routines. 🥳
@mementomori8856
@mementomori8856 Жыл бұрын
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!
@urbanaugust2240
@urbanaugust2240 Жыл бұрын
Roblox Lua is disgustingly slow. Jump on it and play a "Destroy the X" game and blow something up, the physics is actually insane. Can take multiple minutes for an explosion to blow something away, with the debris just slowly moving.
@neversinkmakes
@neversinkmakes Жыл бұрын
Let’s add Scheme to the wheel!
@cas97553
@cas97553 Жыл бұрын
Part 2 sucked and it filled my entire day.
@oshalaby-tt
@oshalaby-tt Жыл бұрын
Lua is not bad. The syntax isn't bad either. It's super easy to learn (literally learned it in 3 hours). It's pretty fast (faster than Python and Ruby). The only 'negative' aspect of it is that it's one-base indexed.
@teefus1
@teefus1 Жыл бұрын
whats wrong with index starting at 1? can you explain
@calengo454
@calengo454 Жыл бұрын
​@@teefus1lmao as someone who started with lua, for me it's the contrary, 0-based indexes are much more confusing to me, specially because of the fact that the index of the last element in an array != the number of elements in the array.
@natnial1
@natnial1 Жыл бұрын
@@calengo454 0-based arrays make a lot of sense when compared to the pointer notation arr[offset] vs *(arr + offset)
@oshalaby-tt
@oshalaby-tt Жыл бұрын
@@teefus1 It's confusing
@oshalaby-tt
@oshalaby-tt Жыл бұрын
@@teefus1 + many people, including me, use other languages which make's lua more confusing. I love lua (and wrote code with it) and mentioning one disadvantage of it doesn't mean that I'm some kind of lua hater troll
@coomlord5360
@coomlord5360 Ай бұрын
Honestly would of been goated if u did lua on computer craft mod for minecraft. Basically u can make farming/building bots to do the tedious stuff for u
@jamesmorrison9893
@jamesmorrison9893 Жыл бұрын
I allocated 9 GB of memory and brute forced the hell out of part 2 in my C implementation. ~5 minutes to complete 😄
@magneto133
@magneto133 Жыл бұрын
I only use lua for my neovim config 😂
@orizach01
@orizach01 Жыл бұрын
part 2 is so evil today
@xtieburn
@xtieburn Жыл бұрын
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.
@glowiak3430
@glowiak3430 Жыл бұрын
Please add FreeBASIC to the wheel please!
using numbers in your code is bad
14:33
Low Level
Рет қаралды 149 М.
Cheerleader Transformation That Left Everyone Speechless! #shorts
00:27
Fabiosa Best Lifehacks
Рет қаралды 16 МЛН
Quilt Challenge, No Skills, Just Luck#Funnyfamily #Partygames #Funny
00:32
Family Games Media
Рет қаралды 55 МЛН
黑天使只对C罗有感觉#short #angel #clown
00:39
Super Beauty team
Рет қаралды 36 МЛН
researchers find unfixable bug in apple computers
8:32
Low Level
Рет қаралды 719 М.
Why Is Lua So Popular?
8:03
Awesome
Рет қаралды 104 М.
Where Lua Is Actually Used
9:25
Tortellini Soup
Рет қаралды 24 М.
Programming an entire game from scratch | Prime Reacts
15:31
ThePrimeTime
Рет қаралды 236 М.
Making a Game in Lua with No Experience
5:52
Goodgis
Рет қаралды 378 М.
Stop using std::vector wrong
23:14
The Cherno
Рет қаралды 163 М.
new linux exploit is absolutely insane
8:29
Low Level
Рет қаралды 432 М.
The Ultimate Tier Programming Tier List | Prime Reacts
26:57
ThePrimeTime
Рет қаралды 523 М.
Cheerleader Transformation That Left Everyone Speechless! #shorts
00:27
Fabiosa Best Lifehacks
Рет қаралды 16 МЛН