823
That Nim Flashbacks (sh.itjust.works)
you are viewing a single comment's thread
view the rest of the comments
[-] victorz@lemmy.world 19 points 6 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 50 points 6 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.

[-] victorz@lemmy.world 11 points 6 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 14 points 6 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 11 points 6 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 4 points 6 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.

[-] victorz@lemmy.world 2 points 6 months ago

Ah right. ๐Ÿ˜

[-] Schadrach@lemmy.sdf.org 2 points 6 months ago* (last edited 6 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.

[-] victorz@lemmy.world 1 points 6 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 2 points 6 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.

[-] victorz@lemmy.world 1 points 6 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 2 points 6 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 ๐Ÿ˜

[-] tastysnacks@programming.dev 4 points 6 months ago

You can easily tell if you did something wrong with Towers of Hanoi.

[-] RamblingPanda@lemmynsfw.com 4 points 6 months ago

You can with a bitchy customer as well ๐Ÿ’–

load more comments (11 replies)
this post was submitted on 05 May 2024
823 points (99.0% liked)

Programmer Humor

19564 readers
840 users here now

Welcome to Programmer Humor!

This is a place where you can post jokes, memes, humor, etc. related to programming!

For sharing awful code theres also Programming Horror.

Rules

founded 1 year ago
MODERATORS