That Nim Flashbacks - eviltoast
      • xmunk@sh.itjust.works
        link
        fedilink
        arrow-up
        12
        ·
        8 months ago

        I have a production bug… it only happens on Saturdays ever our ops folks have no idea - this can be replicated on a test server that gets no traffic.

        Saturday why!

        • lad@programming.dev
          link
          fedilink
          arrow-up
          5
          ·
          8 months ago

          If we reject the theory that it could be someone’s elaborate revenge, Saturday may be the first day of the week that may become workday or non-workday because of incorrect assumption about the first day of the week. If everywhere but one place in your software the day numeration is correct it would be a hard bug to spot.

          Also, if it is in Java, I vaguely remember there being a lot of ways to express weekday, so a lot of ways to shoot off your foot (solely on Saturday)

          • xmunk@sh.itjust.works
            link
            fedilink
            arrow-up
            4
            ·
            8 months ago

            For bonus points, this failure is in a cron job that sends out recently queued messages. It runs once every ten minutes - last weekend we had 12 failures: four were in a cluster on their own, one was in a run of two, and six were in a single continuous run.

            Please note that this server is unused by our business so no messages ever get naturally queued. Every day we sync the live production server to this server at about 9 PM - assuming an employee was queuing up a message before the snapshot is taken there might be a number of unsent messages in the snapshot - those messages will all be sent by the first cron job after the sync.

            It is a wonderfully awful problem that has me wanting to pull out my luscious locks.

              • xmunk@sh.itjust.works
                link
                fedilink
                arrow-up
                4
                ·
                8 months ago

                Yup, luck is appreciated and I’m trying to get more eyes but unfortunately I’m a senior dev that has the second highest seniority at the company so I feel guilty dragging others into it.

        • CanadaPlus@lemmy.sdf.org
          link
          fedilink
          arrow-up
          3
          ·
          edit-2
          8 months ago

          Please tell me it doesn’t still happen when you emulate a different day of the week. Or is that non-trivial to even do because of technical debt? Either way, RIP weekends.

    • Blue_Morpho@lemmy.world
      link
      fedilink
      arrow-up
      1
      arrow-down
      2
      ·
      8 months ago

      I’ve always hated recursion. It’s always seemed like a cutesy programming trick that’s not reliable in all conditions.

      You could blow the stack in an edge case that you didn’t think of. So it should never be a standard pattern. It’s only good if you need to rewrite something for optimization and recursion is appropriate. But in many cases recursion is slower.

      “Look at what I can do in 5 lines of code!” is for programming contests, not for anything important.

  • harrys_balzac@lemmy.dbzer0.com
    link
    fedilink
    arrow-up
    31
    ·
    8 months ago

    I didn’t have to program this, thankfully. The code was used as an example of recursion but the explanation was lacking so I ended up writing out each frame by end until I understood it. Took a few pages and a couple of hours.

    I am grateful that I learned what I did going through it but I’d rather not do it again.

  • Victor@lemmy.world
    link
    fedilink
    arrow-up
    19
    ·
    8 months ago

    Is this a hard problem to solve? I’ve not attempted it yet myself.

    I seem to remember this was a problem in Advent of Code one year?

    I’m imagining there are plenty of algorithms to solve this already, right? With varying numbers of towers and plates? A general solution for solvable amounts of each? Maybe?

    • Akrenion@programming.dev
      link
      fedilink
      arrow-up
      50
      ·
      8 months ago

      This is not a hard problem once you wrap your head around it. It is the earliest that some programmers learn about recursion which has a lot of pitfalls and can be frustrating at times.

      • Victor@lemmy.world
        link
        fedilink
        arrow-up
        11
        ·
        8 months ago

        Ah okay, that’s where the trauma comes from then, perhaps? 😅 Just being new to a concept and perhaps starting out with a problem that is a little too big while at the same time learning the concept?

        • Ephera@lemmy.ml
          link
          fedilink
          arrow-up
          14
          ·
          8 months ago

          I feel like it’s maybe a bit too much to say that it’s a trauma. The Vietnam-flashback picture is just very fitting, because the puzzle is called “Towers of Hanoi” (Hanoi is the capital of Vietnam).

          • CanadaPlus@lemmy.sdf.org
            link
            fedilink
            arrow-up
            11
            ·
            8 months ago

            A lot of programmer memes seem to be about first-year compsci students that just want to build video games, and don’t really like math. For those people, sure, algorithms could be a bit of a rude awakening.

            • skulblaka@startrek.website
              link
              fedilink
              arrow-up
              4
              ·
              8 months ago

              I was once that first year compsci student. Hanoi kicked my ass, I had to go recruit help from my smarter friends. Though to be fair the teacher didn’t explain it that well and just sort of threw it at us to see which of us would sink or swim. After we all complained about it he gave us a proper lesson on recursion and it was a little easier after that but I still struggled a lot on that project. We also implemented Conway’s Game of Life that semester and I preferred that project by a lot.

        • Schadrach@lemmy.sdf.org
          link
          fedilink
          arrow-up
          2
          ·
          edit-2
          8 months ago

          See, when I was a comp sci undergrad 20-odd years ago our department wanted to do a programming competition for the local high schools. We set some ground rules that were similar to ACS programming competition rules, but a bit more lax - the big ones were that it had to run in command line, it had to take the problem dataset filename as the first parameter and it had to be able to solve all datasets attempted by the judges in less that 2 minutes per dataset, noting that the judgement datasets would be larger than example ones.

          Some of the students were asked to come up with problem ideas. I was told mine was unfair, but mine was entirely about choosing the right algorithm for the job.

          It went like this - the file would contain a pyramid of numbers. You were supposed to think of each number as connecting to the two numbers diagonally below it and all paths could only proceed down. The goal was to calculate the largest sum of any possible path down.

          • Victor@lemmy.world
            link
            fedilink
            arrow-up
            1
            ·
            8 months ago

            Sounds like a fun problem. Wonder why they thought it wasn’t fair. Sounds no harder than any mid-range Advent of Code problem.

            • Schadrach@lemmy.sdf.org
              link
              fedilink
              English
              arrow-up
              2
              ·
              8 months ago

              As the size of the pyramid increases the obvious algorithm (walking all the routes down the tree) is going to fall afoul of the time limit pretty quickly, as are several alternative algorithms you might try. So a pyramid 100 or 1000 levels deep very rapidly falls out of the time limit unless you choose the right algorithm because there are 2^(n-1) paths for a n-level pyramid. I’d suggested a…much bigger dataset as one of the judgement datasets One that took my reference implementation about 15 seconds.

              This was a contest for high school kids c. 2001 and was going to involve 4 problems across 6 hours. The prof making the decision thought it was a bit much for them to figure out why the algorithm they were likely to try wasn’t working in time (noting that the only feedback they were going to get was along the lines of “failed for time on judgement dataset 3 with 10000 layers”, that it was because it was a poor choice of algorithm rather than some issue in their implementation, and then to devise a faster algorithm and implement and debug that all ideally within 1.5 hours.

              For example, the algorithm I used for my reference solution started one layer above the bottom of the pyramid, checked the current number against either child it could be summed with, replaced the current number with the larger sum and continued in that fashion up the pyramid layer by layer. So, comparison, add, store for each number in the pyramid above the bottom layer. When you process the number at the top of the pyramid, that’s the final result. It’s simple and it’s fast. But it requires looking at the problem upside down, which is admittedly a useful skill.

              • Victor@lemmy.world
                link
                fedilink
                arrow-up
                1
                ·
                8 months ago

                I mean it’s basically solving one of those labyrinth puzzles in a puzzle book by starting at the finish and working your way to the start, avoiding all the wrong turns. 😄 It’s the smart solution. 😉 But yeah, maybe they had a point with the “no feedback” issue. In Advent of Code, at least you get to see your final input data.

      • RamblingPanda@lemmynsfw.com
        link
        fedilink
        arrow-up
        4
        arrow-down
        2
        ·
        8 months ago

        Thank god my first time was building a dynamic tree with loads of metadata and sorting from database records and not some strange game 😐

    • xmunk@sh.itjust.works
      link
      fedilink
      arrow-up
      13
      ·
      8 months ago

      It’s an easy problem to solve… eventually - it’s more annoying to solve optimally and that’s what programmers usually get handed as a play problem within a year or two of starting to tinker.

  • akash_rawal@lemmy.world
    link
    fedilink
    arrow-up
    19
    ·
    8 months ago

    Replacing “Programmers:” with “Program:” is more accurate.

    spoiler

    Tower of Hanoi is actually easy to write program for. Executing it on the other hand…

    • CanadaPlus@lemmy.sdf.org
      link
      fedilink
      arrow-up
      10
      ·
      8 months ago

      It’d be a trick if you didn’t already know the answer. Or at least, it would be for me. It’s also hard to actually visualise.

      • akash_rawal@lemmy.world
        link
        fedilink
        arrow-up
        7
        ·
        8 months ago

        I didn’t know the answer either, but usually you can compose solution from solutions of smaller problems.

        solution(0): There are no disks. Nothing to do. solution(n): Let’s see if I can use solution(n-1) here. I’ll use solution(n-1) to move all but last disk A->B, just need to rename the pins. Then move the largest disk A->C. Then use solution(n-1) to move disks B->C by renaming the pins. There we go, we have a stack based solution running in exponential time.

        It’s one of the easiest problem in algorithm design, but running the solution by hand would give you a PTSD.

        • CanadaPlus@lemmy.sdf.org
          link
          fedilink
          arrow-up
          2
          arrow-down
          1
          ·
          edit-2
          8 months ago

          Good for you. I think I’d figure it out eventually, but it would certainly take me a while.

          I’d probably be trying a number of approaches, including the recursive one. Renaming pegs is a critical piece that you’d have to realise you can do, and you can’t be sure you have a correct inductive solution unless you actually walk through the first few solutions from the base instance.

    • sv1sjp@lemmy.world
      link
      fedilink
      English
      arrow-up
      4
      ·
      8 months ago

      In myuniversity, we used to play with these to find the fastest path in AI (A*, first depth etc)

  • pmk@lemmy.sdf.org
    link
    fedilink
    arrow-up
    6
    ·
    8 months ago

    “You mean I just made a very complicated array-manipulating way of calculating (2^n)-1?”

  • JATtho@sopuli.xyz
    link
    fedilink
    arrow-up
    5
    ·
    8 months ago

    Lettme introduce you to ackermann’s function:

    int ack(int m, int n) {
        if (m == 0) {
            return n+1;
        } else if((m > 0) && (n == 0)){
            return ack(m-1, 1);
        } else if((m > 0) && (n > 0)) {
            return ack(m-1, ack(m, n-1));
        }
    }
    

    You won’t run out of stackoverflows any time soon.