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

Sdílet
Vložit
  • čas přidán 4. 12. 2023
  • 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
  • Věda a technologie

Komentáře • 407

  • @rafaelbordoni516
    @rafaelbordoni516 Před 6 měsíci +590

    Lua is the C of the interpreted languages, extremely simple and small. Probably the easiest language to teach kids programming.

    • @torarinvik4920
      @torarinvik4920 Před 6 měsíci +84

      I agree 100%, it's simplicity is masterful. It looks and feels nice too just like Ruby and Python.

    • @LowLevelLearning
      @LowLevelLearning  Před 6 měsíci +93

      love that

    • @revengerwizard
      @revengerwizard Před 6 měsíci +19

      Comparing Lua to C is kind of unfair

    • @FaZekiller-qe3uf
      @FaZekiller-qe3uf Před 6 měsíci +54

      @@torarinvik4920Python does not feel nice

    • @charlieking7600
      @charlieking7600 Před 6 měsíci +33

      ​​@@FaZekiller-qe3ufbecause it feels awesome. Many built-in functions, structures, powerful slices, lambdas and iterators.

  • @AntonioZL
    @AntonioZL Před 5 měsíci +49

    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 Před 5 měsíci +7

      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 Před 2 měsíci

      # is unintuitive for tables with discontinuous indices. It will give the length up to the first nil value.

  • @onrir
    @onrir Před 6 měsíci +262

    lua-jit is faster than python by a large margin and pretty light on resource consumption aswell.

    • @fhudufin
      @fhudufin Před 6 měsíci +32

      normal lua is faster than python iirc

    • @onrir
      @onrir Před 6 měsíci +88

      @@fhudufin to be fully honest, python is not a very hard benchmark to pull off lmfao

    • @skaruts
      @skaruts Před 6 měsíci +56

      If it exists, it's faster than python.

    • @kuhluhOG
      @kuhluhOG Před 6 měsíci +2

      well, the default Python implementation (CPython)
      there are some which are A LOT faster

    • @onrir
      @onrir Před 6 měsíci +4

      @@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 Před 6 měsíci +169

    I will not stand for this slander of neovim's config language

    • @NostraDavid2
      @NostraDavid2 Před 6 měsíci +7

      Also world of warcraft addons

    • @murat.h
      @murat.h Před 5 měsíci +1

      @@NostraDavid2 Also scripting language for roblox

    • @callyral
      @callyral Před 5 měsíci +3

      Also Wezterm config language
      and AwesomeWM's config language
      Lua seems really popular for configuring stuff huh

    • @universaltoons
      @universaltoons Před 5 měsíci

      ​@@murat.hroblox uses Luau

    • @josephbrandenburg4373
      @josephbrandenburg4373 Před 13 dny

      OpenMW scripting!

  • @xavxavierm
    @xavxavierm Před 6 měsíci +113

    Cool video, lua is surprisingly integrated into many applications though. its good to know

    • @LowLevelLearning
      @LowLevelLearning  Před 6 měsíci +14

      Indeed!

    • @no_name4796
      @no_name4796 Před 6 měsíci +10

      neovim itself uses lua, btw

    • @romanstingler435
      @romanstingler435 Před 6 měsíci +4

      @@LowLevelLearningDon't tell @teej_dv the title of your video

    • @user-cy1rm5vb7i
      @user-cy1rm5vb7i Před 6 měsíci +8

      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 Před 6 měsíci +22

    roblox and fivem developers are shaking rn

  • @glennedgar5057
    @glennedgar5057 Před 6 měsíci +153

    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 Před 6 měsíci +1

      What are the 100k and 500m that you speak of?

    • @orbyfied
      @orbyfied Před 6 měsíci +6

      @@MavikBow bytes of memory i assume

    • @kuhluhOG
      @kuhluhOG Před 6 měsíci +2

      I hate the fact that CZcams is bugged on my end so that I can't see the "See More".

    • @cocbuilds
      @cocbuilds Před 6 měsíci

      @@kuhluhOG try different account? if on PC try in guest mode maybe, probably an extension or your account

    • @kuhluhOG
      @kuhluhOG Před 6 měsíci

      @@cocbuilds tried it already, doesn't matter

  • @flamendless
    @flamendless Před 6 měsíci +57

    Lua is slow, but LuaJIT is the blackest magic there is

  • @pseudonymity0000
    @pseudonymity0000 Před 6 měsíci +102

    Hot take... Lua should of been used for the web instead of JS

    • @CEOofGameDev
      @CEOofGameDev Před 6 měsíci

      Funny you should mention it, since Emilua (basically lua's node.js) dropped a new version literally yesterday.

    • @jumpsplat120
      @jumpsplat120 Před 6 měsíci +17

      Based take.

    • @torphedo6286
      @torphedo6286 Před 6 měsíci +9

      true!

    • @caerphoto
      @caerphoto Před 6 měsíci +26

      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 Před 5 měsíci +8

      @@thetukars Brendan Eich (JS creator) said that if he was not forced by business, JS would be functional with Scheme syntax.

  • @The_RoboDoc
    @The_RoboDoc Před 6 měsíci +36

    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 Před 6 měsíci

      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 Před 6 měsíci

      Same. It's currently running

    • @yjlom
      @yjlom Před 6 měsíci +1

      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 Před 6 měsíci +4

      @@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 Před 6 měsíci +1

      @@yjlom That's... that's kinda impressive ngl :DDD

  • @hudsonator7259
    @hudsonator7259 Před 6 měsíci +6

    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

  • @FireDragon91245
    @FireDragon91245 Před 6 měsíci +16

    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 Před 6 měsíci +1

      The complexity doesn't really depend that much on a language more like on the project itself.

    • @armincal9834
      @armincal9834 Před 6 měsíci +2

      @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 Před 6 měsíci

      @@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

  • @pedrovidal5634
    @pedrovidal5634 Před 6 měsíci +6

    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 Před 4 měsíci

      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.

  • @nerdycatgamer
    @nerdycatgamer Před 6 měsíci +2

    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 :)

  • @user-vf8on4xv3j
    @user-vf8on4xv3j Před 3 měsíci +2

    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.

  • @josephdvorak9241
    @josephdvorak9241 Před 6 měsíci +9

    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 Před 5 měsíci +1

      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 Před 5 měsíci

      @GordanCable Thank you! And I know the feeling! Good luck!!

  • @villehietala9677
    @villehietala9677 Před 6 měsíci +8

    Excel (without macros) should be on the wheel.

  • @jaycebrannon1520
    @jaycebrannon1520 Před 5 měsíci +2

    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

  • @hukasu
    @hukasu Před 6 měsíci +1

    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.

  • @dorianprill8190
    @dorianprill8190 Před 6 měsíci +2

    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)

  • @DocBolle
    @DocBolle Před 6 měsíci +1

    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.

  • @t3dotgg
    @t3dotgg Před 6 měsíci +3

    I was so excited to watch you do part 2 in Lua 😭😭

    • @LowLevelLearning
      @LowLevelLearning  Před 6 měsíci +1

      Would have suuuuuuucked with 1 indexed arrays lol

    • @kaitlynethylia
      @kaitlynethylia Před 6 měsíci

      @@LowLevelLearning if it's really that bad for you, you can make arrays 0 indexed just by doing
      { [0] = , , etc }

  • @DarkblooM_IO
    @DarkblooM_IO Před 6 měsíci +3

    I'm doing the whole AoC in Lua, did not expect to pop up here

  • @cookie_of_nine
    @cookie_of_nine Před 6 měsíci +2

    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 Před 6 měsíci +1

      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 Před 6 měsíci

      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 Před 6 měsíci

      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.

  • @LeonAlkoholik67
    @LeonAlkoholik67 Před 6 měsíci +78

    Next year please choose random languages that viewers suggests, including non-mainstream languages that may have to be learned from scratch

    • @CrazyLuke11
      @CrazyLuke11 Před 6 měsíci +14

      Do you want him to die?

    • @chuck0842
      @chuck0842 Před 6 měsíci +24

      ​@@CrazyLuke11 yes

    • @TheVertical92
      @TheVertical92 Před 6 měsíci +3

      🤣great user name btw

    • @AlvinYap510
      @AlvinYap510 Před 6 měsíci

      Add some esoteric languages perhaps? 👀

    • @ferdynandkiepski5026
      @ferdynandkiepski5026 Před 6 měsíci +3

      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.

  • @AWIRE_onpc
    @AWIRE_onpc Před 6 měsíci +9

    lua is an awesome language. Considering you have alot of C experience, you could modify the interpreter to your liking.

  • @colin_actually
    @colin_actually Před 6 měsíci +10

    I absolutely love lua

  • @DeuxisWasTaken
    @DeuxisWasTaken Před 6 měsíci +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 Před 2 měsíci

      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 Před 2 měsíci

      @@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 Před 2 měsíci +1

      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 Před 2 měsíci

      @@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 Před 2 měsíci

      @@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.

  • @pmoohkt
    @pmoohkt Před 6 měsíci

    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 😁

  • @chinobijman3571
    @chinobijman3571 Před 6 měsíci +1

    I started advent of code aswell, but it gets pretty tough when you do it all in C

  • @ozmer
    @ozmer Před 6 měsíci +3

    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.

  • @Stdvwr
    @Stdvwr Před 6 měsíci +4

    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

  • @PoProstuLatanie
    @PoProstuLatanie Před 6 měsíci +1

    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

  • @capncoolio
    @capncoolio Před 6 měsíci

    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?")

  • @aaronchamberlain4698
    @aaronchamberlain4698 Před 5 měsíci

    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.

  • @VivekYadav-ds8oz
    @VivekYadav-ds8oz Před 5 měsíci +1

    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.

  • @newsofthenerd
    @newsofthenerd Před 5 měsíci +3

    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.

  • @mapelsiroup5604
    @mapelsiroup5604 Před 6 měsíci

    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

  • @georgerogers1166
    @georgerogers1166 Před 6 měsíci +15

    Lua is as fast as JS. LuaJIT is insane, similar to modern JS Jits.

    • @Pillboxing
      @Pillboxing Před 5 měsíci

      It's not even close anymore sadly. JS is a minimum of 10x faster than luaJIT now

    • @skaruts
      @skaruts Před 2 měsíci

      @@Pillboxing source?

  • @ilikecats5396
    @ilikecats5396 Před 5 měsíci

    really cool that my teacher in discrete structutes this semester was one of the creators of Lua!

  • @AlvinYap510
    @AlvinYap510 Před 6 měsíci +3

    Hahahaha... Rookie here. I just solved this question with JS. Part2 almost fried my cpu with 1 billion+ seeds until I reimplement it reversely 🤣

  • @ericbwertz
    @ericbwertz Před 6 měsíci +8

    This challenge is really the off-by-one challenge.

    • @monad_tcp
      @monad_tcp Před 5 měsíci

      as all array access is with anything that's not APL

    • @monad_tcp
      @monad_tcp Před 5 měsíci

      Its impossible to make off-by-one errors in APL

    • @ericbwertz
      @ericbwertz Před 5 měsíci +3

      @@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 Před 5 měsíci +1

      @@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 Před 5 měsíci +2

      @@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.

  • @9remi
    @9remi Před 5 měsíci +4

    where are the last few days?

    • @joachimhorshauge
      @joachimhorshauge Před 5 měsíci +2

      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 Před 5 měsíci

      @@joachimhorshauge oh lmfao

  • @danielsharp2402
    @danielsharp2402 Před 6 měsíci

    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.

  • @FZs1
    @FZs1 Před 6 měsíci

    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.

  • @ThrowTop
    @ThrowTop Před 6 měsíci +1

    luaJIT also has ffi. which allows for manual memory managment. and is extremly fast

  • @sudospective
    @sudospective Před 5 měsíci

    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

  • @Intrebute
    @Intrebute Před 6 měsíci

    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 Před 6 měsíci +2

      Wow, you have used rayon and you still waited for 20 mins?

  • @iamnotgoodwithcomputer
    @iamnotgoodwithcomputer Před 5 měsíci +1

    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 :)

  • @torarinvik4920
    @torarinvik4920 Před 6 měsíci +5

    Add Smalltalk to the board! Both Pharo and Squeak are good.

  • @ThrowTop
    @ThrowTop Před 6 měsíci

    in a repeat untill loop the break statement is actually a continue, and to actually break u need to use goto.

  • @EricaCalman
    @EricaCalman Před 6 měsíci

    I only even know it exist because unknown worlds decided to write large parts of Natural Selection 2 in Lua.

  • @bhavyakukkar
    @bhavyakukkar Před 5 měsíci

    im learning lua right now fingers crossed this video helps

  • @willzin-da-esfiha
    @willzin-da-esfiha Před 6 měsíci +2

    Use ranges (store only start and end) and do some set theory calculations (i.e.: intersections)
    That's it

    • @vihashah5975
      @vihashah5975 Před 6 měsíci +1

      i’m doing that but dealing with off by one errors 😭rip

  • @spicywe1ner
    @spicywe1ner Před 6 měsíci

    incredible how fast you were able to pick up lua. what a champ

  • @godDIEmanLIVE
    @godDIEmanLIVE Před 6 měsíci

    This series is really cool.

  • @EximiusDux
    @EximiusDux Před 6 měsíci

    Lua was used to script the very first Farcry (2004) game. It's old but does have a long and decent history.

  • @KvapuJanjalia
    @KvapuJanjalia Před 6 měsíci

    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.

  • @spacelem
    @spacelem Před 2 měsíci

    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.

  • @plugadapter2411
    @plugadapter2411 Před 6 měsíci +16

    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 Před 6 měsíci

      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 Před 6 měsíci

      @@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 Před 6 měsíci

      My code for part 2 (in c++, brute force - check each seed number, and find the minimum result) took about 20 minutes ;)

    • @ferdynandkiepski5026
      @ferdynandkiepski5026 Před 6 měsíci +1

      ​@@wolodiam9013how did you make it slower than python? I'm genuinely curious.

    • @peytondaley4991
      @peytondaley4991 Před 6 měsíci +3

      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.

  • @SPDM_Riky47
    @SPDM_Riky47 Před měsícem

    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.

  • @AdamMaryniuk
    @AdamMaryniuk Před 6 měsíci

    Are you ever going to do the final conclusion video for the baby monitor?

    • @LowLevelLearning
      @LowLevelLearning  Před 6 měsíci +2

      When I catch some free time to actually do the RF capture yes. Hopefully early next year :)

  • @m1geo
    @m1geo Před 6 měsíci

    3:50 "We're going to do '0+1' and you're going to be okay!" lol

  • @xtieburn
    @xtieburn Před 6 měsíci

    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.

  • @bckends_
    @bckends_ Před 5 měsíci

    that title single-handedly reduced Primegean's lifespan by 5 years

  • @mementomori8856
    @mementomori8856 Před 6 měsíci

    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!

  • @woofcaptain8212
    @woofcaptain8212 Před 6 měsíci +3

    I still want to see you try lisp

  • @whamer100
    @whamer100 Před 6 měsíci +1

    this stream was really funny

  • @heylookitsnoah
    @heylookitsnoah Před 5 měsíci +1

    bro had to change the title because of the backfire, love to see it

  • @jamesmorrison9893
    @jamesmorrison9893 Před 5 měsíci

    I allocated 9 GB of memory and brute forced the hell out of part 2 in my C implementation. ~5 minutes to complete 😄

  • @nyvyme
    @nyvyme Před 14 dny

    and now imagine that all mods for tboi and addons for gmod are written in lua

  • @trentondickey9061
    @trentondickey9061 Před 6 měsíci

    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

  • @mxruben81
    @mxruben81 Před 2 měsíci

    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.

  • @reed6514
    @reed6514 Před 6 měsíci

    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

  • @giuseppesec
    @giuseppesec Před 6 měsíci +10

    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

  • @norndev
    @norndev Před 6 měsíci

    Should add the "pawn" language by compuphase, like lua it's been used for game scripting

  • @randy7894
    @randy7894 Před 3 dny

    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.

  • @WeirdDuck781
    @WeirdDuck781 Před 5 měsíci

    Lua is literally where I learned coding... Think I would've had a better start in C# tbh

  • @youcefmoulla1828
    @youcefmoulla1828 Před 5 měsíci +1

    Lua is just a new version of Fortran

  • @Maxjoker98
    @Maxjoker98 Před 3 měsíci

    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...

  • @afterschool2594
    @afterschool2594 Před 6 měsíci

    Man day 5 part 2 took me 8 hours to get it working in 1 minute++ in Rust Release Mode

  • @jackjack9196
    @jackjack9196 Před 6 měsíci

    I did it in php. No brute force. I lost my mental sanity, but it was worth it in the end

  • @user-kp6ir4ih9s
    @user-kp6ir4ih9s Před 6 měsíci +2

    I am kinda disapointed about skipping part 2. I was waiting exactly for it :/ Bruteforce is a correct, but dummy solution :C

    • @LowLevelLearning
      @LowLevelLearning  Před 6 měsíci +4

      I know I really wanted to finish it, but unfortunately I had to go to my J O B XD

  • @bitwise4996
    @bitwise4996 Před 6 měsíci

    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 Před 6 měsíci +2

    lua is WAY faster then most interpreted progrmaming languages

  • @BaldiReycaster
    @BaldiReycaster Před 6 měsíci +2

    YOU WILL NOT BE FORGIVEN FOR YOUR HEINOUS ACTIONS.

  • @jared_per
    @jared_per Před 6 měsíci +2

    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 Před 6 měsíci +1

      I do wish it had += and continue though

    • @arandomguythatdoesntpost
      @arandomguythatdoesntpost Před 6 měsíci +2

      LuaU has both :)

    • @jared_per
      @jared_per Před 6 měsíci +1

      @@arandomguythatdoesntpost I've been meaning to try luau. I shall do it soon

  • @magneto133
    @magneto133 Před 6 měsíci +3

    I only use lua for my neovim config 😂

  • @cas97553
    @cas97553 Před 6 měsíci +1

    Part 2 sucked and it filled my entire day.

  • @turanamo
    @turanamo Před 6 měsíci +1

    Lua was my first crush before I hitched on to C

  • @FinalEnd4
    @FinalEnd4 Před 6 měsíci

    Came here to see if there's a better solution than brute-forcing it since it felt kinda wrong...
    Well, reading the other comments, I can't really complain with my 4.4 seconds 😅 (used Rust with multithreading)

  • @prawnydagrate
    @prawnydagrate Před 6 měsíci

    lmao my rust solution just barely worked, taking 5 minutes and 31 seconds for part two

  • @TimothyChapman
    @TimothyChapman Před 6 měsíci

    TIL: Lua has goto statements! That would have been good to know a long time ago.

  • @kinositajona
    @kinositajona Před 6 měsíci

    Someone did brute force in Rust using release mode and it took 2 minutes to complete...... so yeah.... maybe leave it on overnight? lol

  • @monad_tcp
    @monad_tcp Před 5 měsíci

    3:55 lol, my seeds.

  • @alexanderkimmel7019
    @alexanderkimmel7019 Před 6 měsíci +2

    lua just seems like pseudo code with the indenting from 1 and the if ... then

    • @user-cy1rm5vb7i
      @user-cy1rm5vb7i Před 6 měsíci

      you haven't seen COBOL, it's nothing BUT pseudo code and it's horrific 😱@@thetukars

  • @TagetesAlkesta
    @TagetesAlkesta Před 5 měsíci

    Dudes forget Haskell, we need to get HolyC onto this wheel

  • @caerphoto
    @caerphoto Před 6 měsíci

    I dare you to put some form of Pascal on the wheel.

  • @DeuxisWasTaken
    @DeuxisWasTaken Před 6 měsíci

    ok yeah goto as continue is hella cursed lmao

  • @peq42_
    @peq42_ Před 5 měsíci

    I honestly love lua. It saddens me to see it being kinda dead, outside of game modding