• brophy@lemmy.world
    link
    fedilink
    arrow-up
    137
    ·
    edit-2
    1 year ago

    Kids get infinite registers and no restrictions on stack ordering. Programmers are constrained to solving it with one register and restrictions on stack put operations.

    ./insert we-are-not-the-same-meme

      • LetterboxPancake@sh.itjust.works
        link
        fedilink
        Deutsch
        arrow-up
        20
        arrow-down
        1
        ·
        1 year ago

        I had enough colleagues unable to type exactly what they asked me into whatever search engine they preferred to accept your statement. If you don’t know how to use a search engine go ask for another job.

        “Hey pancake, how do I run all tests via gradle?”

        Open your browser, head to Google and type “run all tests in gradle”

        “Oh, nice. Thank you for your help!”

        And the next day the game starts all over again.

    • Anonymousllama@lemmy.world
      link
      fedilink
      arrow-up
      23
      arrow-down
      4
      ·
      1 year ago

      As it should be, there’s way too much reengineering of the wheel. Let the big brains of the past do the heavy lifting

  • PapstJL4U@lemmy.world
    link
    fedilink
    English
    arrow-up
    34
    arrow-down
    2
    ·
    1 year ago

    Before studying CS, I recognized it as ‘the bioware puzzle’. They were probably copying their own scribbles fron back then.

    Haskell was the hardest, but it looked the most beautiful.

    • lugal@sopuli.xyz
      link
      fedilink
      arrow-up
      35
      arrow-down
      1
      ·
      1 year ago

      Haskell was the hardest, but it looked the most beautiful.

      That pretty much sums that language up

        • Knusper@feddit.de
          link
          fedilink
          arrow-up
          5
          ·
          1 year ago

          Welp, imma try myself at an explanation. Mostly cause I haven’t written Haskell in a while either.

          So, that first line:

          hanoi :: Integer -> a -> a -> a -> [(a, a)]
          

          …actually only declares the function’s type.

          In this case, it’s a function that takes an Integer and three values of a generic type a and then returns a list of tuples of those same as.
          So, those as are just any types representing the towers. Could be strings, integers, custom data types, whatever. The returned tuples represent movements between towers.

          Following that are actually two definitions of the function.

          The first definition:

          hanoi 0 _ _ _ = []
          

          …is the recursion base case. Function definitions are applied, whenever they match, being evaluated top-to-bottom.

          This line specifies that it only matches, if that first Integer is 0. It does not care what the remaining parameters are, so matches them with a wildcard _.
          Well, and to the right side of the equals sign, you’ve got the return value for the base case, an empty list.

          Then comes the more interesting line, the recursion step:

          hanoi n a b c = hanoi (n-1) a c b ++ [(a, b)] ++ hanoi (n-1) c b a
          

          This line matches for any remaining case. Those small letter names are again wildcards, but the matched value is placed into a variable with the provided name.

          And then, well, it recursively calls itself, and those ++ are list concations. This line’s only real complexity is the usual Tower Of Hanoi algorithm.

  • Aathi
    link
    fedilink
    English
    arrow-up
    4
    arrow-down
    1
    ·
    edit-2
    1 year ago

    Example for stack

  • stingpie@lemmy.world
    link
    fedilink
    arrow-up
    2
    arrow-down
    4
    ·
    1 year ago

    Did you guys find this hard? There are only four possible ways to move a ring, two of which are disallowed by the rules. Out of the remaining two, one of them is simply undoing what you just did.