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

Поделиться
HTML-код
  • Опубликовано: 29 сен 2024
  • 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/low...
    🙌 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

Комментарии • 411

  • @rafaelbordoni516
    @rafaelbordoni516 9 месяцев назад +623

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

    • @torarinvik4920
      @torarinvik4920 9 месяцев назад +85

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

    • @LowLevel-TV
      @LowLevel-TV  9 месяцев назад +94

      love that

    • @revengerwizard
      @revengerwizard 9 месяцев назад +19

      Comparing Lua to C is kind of unfair

    • @FaZekiller-qe3uf
      @FaZekiller-qe3uf 9 месяцев назад +58

      @@torarinvik4920Python does not feel nice

    • @charlieking7600
      @charlieking7600 9 месяцев назад +34

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

  • @pedrovidal5634
    @pedrovidal5634 9 месяцев назад +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 8 месяцев назад +1

      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.

  • @Stdvwr
    @Stdvwr 9 месяцев назад +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

  • @DocBolle
    @DocBolle 9 месяцев назад +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.

  • @alexanderkimmel7019
    @alexanderkimmel7019 9 месяцев назад +2

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

    • @Raspredval1337
      @Raspredval1337 9 месяцев назад

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

  • @EdKolis
    @EdKolis 9 месяцев назад

    Urist picks up the +masterwork+ =diamond= ::continue:: label. The voidpointer is confused!

  • @afterschool2594
    @afterschool2594 9 месяцев назад

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

  • @informagico6331
    @informagico6331 9 месяцев назад

    If just Lua didn't start arrays at 1...

  • @bjoerkengard
    @bjoerkengard 9 месяцев назад

    Somebody in chat gotta suggest he add LabView VI to the wheel

  • @xavxavierm
    @xavxavierm 9 месяцев назад +119

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

    • @LowLevel-TV
      @LowLevel-TV  9 месяцев назад +18

      Indeed!

    • @no_name4796
      @no_name4796 9 месяцев назад +11

      neovim itself uses lua, btw

    • @romanstingler435
      @romanstingler435 9 месяцев назад +5

      @@LowLevel-TVDon't tell @teej_dv the title of your video

    • @Raspredval1337
      @Raspredval1337 9 месяцев назад +9

      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 9 месяцев назад +186

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

    • @NostraDavid2
      @NostraDavid2 9 месяцев назад +7

      Also world of warcraft addons

    • @murat.h
      @murat.h 9 месяцев назад +1

      @@NostraDavid2 Also scripting language for roblox

    • @callyral
      @callyral 9 месяцев назад +3

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

    • @叵
      @叵 9 месяцев назад

      ​@@murat.hroblox uses Luau

    • @josephbrandenburg4373
      @josephbrandenburg4373 4 месяца назад

      OpenMW scripting!

  • @onrir
    @onrir 9 месяцев назад +273

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

    • @fhudufin
      @fhudufin 9 месяцев назад +32

      normal lua is faster than python iirc

    • @onrir
      @onrir 9 месяцев назад +92

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

    • @skaruts
      @skaruts 9 месяцев назад +60

      If it exists, it's faster than python.

    • @kuhluhOG
      @kuhluhOG 9 месяцев назад +2

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

    • @onrir
      @onrir 9 месяцев назад +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.

  • @terdik36
    @terdik36 9 месяцев назад +32

    roblox and fivem developers are shaking rn

  • @AntonioZL
    @AntonioZL 9 месяцев назад +58

    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 9 месяцев назад +8

      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 6 месяцев назад

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

  • @The_RoboDoc
    @The_RoboDoc 9 месяцев назад +40

    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 9 месяцев назад

      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 9 месяцев назад

      Same. It's currently running

    • @yjlom
      @yjlom 9 месяцев назад +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 9 месяцев назад +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 9 месяцев назад +1

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

  • @pseudonymity0000
    @pseudonymity0000 9 месяцев назад +115

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

    • @CEOofGameDev
      @CEOofGameDev 9 месяцев назад

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

    • @jumpsplat120
      @jumpsplat120 9 месяцев назад +20

      Based take.

    • @torphedo6286
      @torphedo6286 9 месяцев назад +9

      true!

    • @caerphoto
      @caerphoto 9 месяцев назад +30

      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 9 месяцев назад +9

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

  • @Luca-gb1og
    @Luca-gb1og 9 месяцев назад +3

    Your first videos about advent of code were very good. Now you cut to much. I can’t even read the instructions because you cut to much.

  • @glennedgar5057
    @glennedgar5057 9 месяцев назад +162

    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 9 месяцев назад +1

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

    • @orbyfied
      @orbyfied 9 месяцев назад +6

      @@MavikBow bytes of memory i assume

    • @kuhluhOG
      @kuhluhOG 9 месяцев назад +2

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

    • @cocbuilds
      @cocbuilds 9 месяцев назад

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

    • @kuhluhOG
      @kuhluhOG 9 месяцев назад

      @@cocbuilds tried it already, doesn't matter

  • @LeonAlkoholik67
    @LeonAlkoholik67 9 месяцев назад +78

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

    • @CrazyLuke11
      @CrazyLuke11 9 месяцев назад +14

      Do you want him to die?

    • @chuck0842
      @chuck0842 9 месяцев назад +24

      ​@@CrazyLuke11 yes

    • @TheVertical92
      @TheVertical92 9 месяцев назад +3

      🤣great user name btw

    • @AlvinYap510
      @AlvinYap510 9 месяцев назад

      Add some esoteric languages perhaps? 👀

    • @ferdynandkiepski5026
      @ferdynandkiepski5026 9 месяцев назад +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.

  • @flamendless
    @flamendless 9 месяцев назад +62

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

  • @FireDragon91245
    @FireDragon91245 9 месяцев назад +18

    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 9 месяцев назад +2

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

    • @armincal9834
      @armincal9834 9 месяцев назад +3

      @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 9 месяцев назад

      @@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 2 месяца назад +1

      C is not simple

    • @matthiasschuster9505
      @matthiasschuster9505 Месяц назад +1

      thanks for making me aware about function environments

  • @AWIRE_onpc
    @AWIRE_onpc 9 месяцев назад +10

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

  • @villehietala9677
    @villehietala9677 9 месяцев назад +9

    Excel (without macros) should be on the wheel.

  • @colin_actually
    @colin_actually 9 месяцев назад +10

    I absolutely love lua

  • @georgerogers1166
    @georgerogers1166 9 месяцев назад +15

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

    • @Pillboxing
      @Pillboxing 9 месяцев назад

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

    • @skaruts
      @skaruts 6 месяцев назад

      @@Pillboxing source?

  • @yante7
    @yante7 9 месяцев назад +5

    where are the last few days?

    • @joachimhorshauge
      @joachimhorshauge 9 месяцев назад +3

      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 9 месяцев назад +1

      @@joachimhorshauge oh lmfao

  • @iamnotgoodwithcomputer
    @iamnotgoodwithcomputer 9 месяцев назад +2

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

  • @hudsonator7259
    @hudsonator7259 9 месяцев назад +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

  • @bckends_
    @bckends_ 9 месяцев назад +2

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

  • @josephdvorak9241
    @josephdvorak9241 9 месяцев назад +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 9 месяцев назад +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 9 месяцев назад

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

  • @plugadapter2411
    @plugadapter2411 9 месяцев назад +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 9 месяцев назад

      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 9 месяцев назад

      @@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 9 месяцев назад

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

    • @ferdynandkiepski5026
      @ferdynandkiepski5026 9 месяцев назад +1

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

    • @peytondaley4991
      @peytondaley4991 9 месяцев назад +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.

  • @AlvinYap510
    @AlvinYap510 9 месяцев назад +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 🤣

  • @t3dotgg
    @t3dotgg 9 месяцев назад +3

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

    • @LowLevel-TV
      @LowLevel-TV  9 месяцев назад +1

      Would have suuuuuuucked with 1 indexed arrays lol

    • @kaitlynethylia
      @kaitlynethylia 9 месяцев назад

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

  • @nerdycatgamer
    @nerdycatgamer 9 месяцев назад +3

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

  • @torarinvik4920
    @torarinvik4920 9 месяцев назад +5

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

  • @magneto133
    @magneto133 9 месяцев назад +3

    I only use lua for my neovim config 😂

  • @woofcaptain8212
    @woofcaptain8212 9 месяцев назад +3

    I still want to see you try lisp

  • @CadenParajuli
    @CadenParajuli 7 месяцев назад +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.

  • @DeuxisWasTaken
    @DeuxisWasTaken 9 месяцев назад +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 6 месяцев назад

      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 6 месяцев назад

      @@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 6 месяцев назад +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 6 месяцев назад

      @@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 6 месяцев назад

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

  • @orbyfied
    @orbyfied 9 месяцев назад +2

    lua is faster than python

  • @ericbwertz
    @ericbwertz 9 месяцев назад +8

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

    • @monad_tcp
      @monad_tcp 9 месяцев назад

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

    • @monad_tcp
      @monad_tcp 9 месяцев назад

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

    • @ericbwertz
      @ericbwertz 9 месяцев назад +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 9 месяцев назад +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 9 месяцев назад +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.

  • @newsofthenerd
    @newsofthenerd 9 месяцев назад +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.

  • @BaldiReycaster
    @BaldiReycaster 9 месяцев назад +2

    YOU WILL NOT BE FORGIVEN FOR YOUR HEINOUS ACTIONS.

  • @mikopiko
    @mikopiko 9 месяцев назад +3

    How dare you calling LuaJIT slow?

  • @jaycebrannon1520
    @jaycebrannon1520 9 месяцев назад +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

  • @DarkblooM_IO
    @DarkblooM_IO 9 месяцев назад +3

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

  • @ozmer
    @ozmer 9 месяцев назад +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.

  • @ChungusTheLarge
    @ChungusTheLarge 9 месяцев назад +3

    Neovim users are in shambles

  • @glowiak3430
    @glowiak3430 9 месяцев назад +2

    Please add FreeBASIC to the wheel please!

  • @MattieBW
    @MattieBW 9 месяцев назад +4

    title is wrong btw, its day 5 :)

  • @giuseppesec
    @giuseppesec 9 месяцев назад +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

  • @ЯрославСвиридов-в7б
    @ЯрославСвиридов-в7б 9 месяцев назад +2

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

    • @LowLevel-TV
      @LowLevel-TV  9 месяцев назад +4

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

  • @thisdyingsoul666
    @thisdyingsoul666 9 месяцев назад +3

    luajit can generate code that is as fast as c

  • @dorian2718
    @dorian2718 9 месяцев назад +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)

  • @goblinjedly9528
    @goblinjedly9528 9 месяцев назад +2

    lua is WAY faster then most interpreted progrmaming languages

  • @m1geo
    @m1geo 9 месяцев назад +1

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

  • @heylookitsnoah
    @heylookitsnoah 9 месяцев назад +1

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

  • @TableTopFinder
    @TableTopFinder 9 месяцев назад +11

    For part two, I brute forced all seed calculations in Go. Script took 3.5minutes 😅

    • @TableTopFinder
      @TableTopFinder 9 месяцев назад

      Got it down to 15 seconds using optimizations and Go routines. 🥳

  • @hukasu
    @hukasu 9 месяцев назад +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.

  • @turanamo
    @turanamo 9 месяцев назад +1

    Lua was my first crush before I hitched on to C

  • @PoProstuLatanie
    @PoProstuLatanie 9 месяцев назад +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

  • @cookie_of_nine
    @cookie_of_nine 9 месяцев назад +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 9 месяцев назад +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 9 месяцев назад

      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 9 месяцев назад

      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.

  • @rawadventures9597
    @rawadventures9597 9 месяцев назад +2

    Fun fact: "Lua" actually means Winter Hat in my language and you're wearing one :)

    • @alstin112
      @alstin112 9 месяцев назад

      What is your language ?

    • @iatheman
      @iatheman 9 месяцев назад +1

      And it means moon in Portuguese :) Maybe now its logo will make more sense. It was created in Brazil too.

    • @rawadventures9597
      @rawadventures9597 9 месяцев назад +1

      @@alstin112 Norwegian

  • @jared_per
    @jared_per 9 месяцев назад +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 9 месяцев назад +1

      I do wish it had += and continue though

    • @arandomguythatdoesntpost
      @arandomguythatdoesntpost 9 месяцев назад +2

      LuaU has both :)

    • @jared_per
      @jared_per 9 месяцев назад +1

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

  • @cas97553
    @cas97553 9 месяцев назад +1

    Part 2 sucked and it filled my entire day.

  • @willzin-da-esfiha
    @willzin-da-esfiha 9 месяцев назад +2

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

    • @vihashah5975
      @vihashah5975 9 месяцев назад +1

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

  • @coolian258
    @coolian258 9 месяцев назад +4

    dont call lua slow its actually pretty fast and at 8 years after c++ its not exactly ancient either

  • @spacelem
    @spacelem 6 месяцев назад

    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.

  • @costelinha1867
    @costelinha1867 8 месяцев назад

    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!"

  • @Scudmaster11
    @Scudmaster11 3 месяца назад

    Lua arrays arnt arrays... they are tables... also base 1 is infact liked alot... in CS like areas... base 1 indexing is infact better then base 0 as the results line up along with traditional counting... but any time you try and criticize, lua you will get alot of correction as you arnt allowed to say anything bad about it... 1 based indexing really isnt a problem.... that and lua is like the leading interprered language in gamedev and Lua is infact a vary nice language .... Lua's syntax is more clean then python (dont care... indenting only for nesting and nonsense isnt how code should be written)

  • @randy7894
    @randy7894 4 месяца назад

    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.

  • @SPDM_Riky47
    @SPDM_Riky47 4 месяца назад

    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.

  • @sillysquirrel9979
    @sillysquirrel9979 9 месяцев назад +1

    lua is language for fliping tables🤣

  • @VivekYadav-ds8oz
    @VivekYadav-ds8oz 9 месяцев назад +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.

  • @youcefmoulla1828
    @youcefmoulla1828 9 месяцев назад +1

    Lua is just a new version of Fortran

  • @NiallBoggins
    @NiallBoggins 17 дней назад

    Why doesn't someone just make a 0 indexed Lua? It's tiny and MIT licensed...

  • @mxruben81
    @mxruben81 6 месяцев назад

    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.

  • @ssmith5048
    @ssmith5048 9 месяцев назад +2

    on the other hand Fortran is ancient and fast!

  • @chinobijman3571
    @chinobijman3571 9 месяцев назад +1

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

  • @yusfcag
    @yusfcag 9 месяцев назад +1

    Who else want to see real C

  • @ThrowTop
    @ThrowTop 9 месяцев назад +1

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

  • @michaelhart8928
    @michaelhart8928 9 месяцев назад

    I ended up brute forcing it in Rust which took about a min or so. Spent like 3hrs trying to think of some complex set theory crap to map one range to another. Don't recommend lol

  • @morphles
    @morphles 9 месяцев назад +1

    I just love living and learning. That people you were looking at as some sort of authority, do absolutely ridiculous nonsensical takes. And title was enough to se that. Makes you start think about all the shit you read on net.
    Lua is great, and I'm not sure how slow could it be when it's used _extensiviely_ by video games, possibly one of most demanding fields of programming, one great example is spring rts game engine, game that regularly has thousands of units simulated real time, is using lua for defining and processing lots of those units, in real time game.

    • @VaughanMcAlley
      @VaughanMcAlley 9 месяцев назад +1

      When I was playing WoW back in the day and learning Lua coding add-ons, my creaky old computer was running ridiculous amounts of Lua every frame.

  • @br3nto
    @br3nto 9 месяцев назад

    Is Lua just Ruby? Or Ruby just Lua? They look quite same same on the surface.

  • @hobbit125
    @hobbit125 4 месяца назад

    You think that Lua's arrays are bad because you mistakenly think that Lua has arrays. It does not.

  • @neversinkmakes
    @neversinkmakes 9 месяцев назад +1

    Let’s add Scheme to the wheel!

  • @loek8638
    @loek8638 9 месяцев назад +1

    :(

  • @realdotty5356
    @realdotty5356 9 месяцев назад +1

    Why does everyone call lua slow? Lua isn’t a slow language

  • @larrysal8866
    @larrysal8866 9 месяцев назад

    I don't understand why hr used go to statements, there is break for loops...

  • @93davve93
    @93davve93 9 месяцев назад +1

    Lua is awesome

  • @whamer100
    @whamer100 9 месяцев назад +1

    this stream was really funny

  • @stefanalecu9532
    @stefanalecu9532 9 месяцев назад

    You have no right to complain about old languages since you still use C 😂

  • @Xenthera
    @Xenthera 7 месяцев назад

    Can someone just maintain a fork of lua that indexes arrays at 0. Thanks

  • @trisimix
    @trisimix 9 месяцев назад

    me on my 5th nested for loop "this language is tomed bruh"

  • @nyvyme
    @nyvyme 4 месяца назад

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

  • @bhavyakukkar
    @bhavyakukkar 9 месяцев назад

    im learning lua right now fingers crossed this video helps

  • @HelloThere-xs8ss
    @HelloThere-xs8ss 9 месяцев назад

    lua is that language that im just confused as to why it exists.

  • @chillidog8726
    @chillidog8726 9 месяцев назад +1

    Part tow took me 43 min to compute in Rust unoptimized beginner level
    edit: with release mode it ran in 2min 12 sec
    Stupid me waiting for 40 minutes

    • @xObscureDarkness
      @xObscureDarkness 9 месяцев назад +2

      Did you use release mode?

    • @chillidog8726
      @chillidog8726 9 месяцев назад

      @@xObscureDarkness nope I'm a rust noob or I just started learning rust starting with this advent of code so I am probably doing very inefficient stuff

    • @chillidog8726
      @chillidog8726 9 месяцев назад

      @@xObscureDarkness ok I ran it again and with release optimisations it took only 2min 12 seconds 😱
      I wish I had known earlier
      (I'm running it in wsl) idk how much of a difference that makes

    • @lukaskiss7857
      @lukaskiss7857 9 месяцев назад

      I used parallel rust (rayon) implementation on 32 core machine and get result in 7.67 sec.

    • @lukaskiss7857
      @lukaskiss7857 9 месяцев назад

      @@chillidog8726 In nutshell, rayon helps you to make your loop parallel. If you apply one function to all numbers in Vec one by one without any state, that is the best way to do it.
      Tokio on the other hand uses async, which allows you to do IO (like waiting for packet) and doing something else at the same time, like computing something. It helps you to run your code concurrently on one core. But it also supports multiple core compare to python asyncio and GIL. So, IO operation will not block you core and during that time it can do something else.

  • @anon-fz2bo
    @anon-fz2bo 9 месяцев назад

    enum DX {
    Good(bool)
    }
    struct Language {
    dx: DX
    }
    fn main() {
    let lua = Language{
    dx: DX::Good(false)
    };
    match lua.dx {
    DX::Good(false) => assert!(true),
    };
    println!("saying lua is less cursed than cpp is straight blasphemy");
    }

  • @capncoolio
    @capncoolio 9 месяцев назад

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