866
top 33 comments
sorted by: hot top controversial new old
[-] brophy@lemmy.world 137 points 11 months ago* (last edited 11 months 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

[-] odium@programming.dev 102 points 11 months ago

It's even called tower of Hanoi because of the Vietnam war flashbacks.

[-] expatriado@lemmy.world 85 points 11 months ago

oh, i solved that assignment in school... by finding the algorithm online

[-] Karfkengrumble@lemmings.world 64 points 11 months ago

You’re hired, welcome to the team!

[-] LetterboxPancake@sh.itjust.works 19 points 11 months 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.

[-] ChlorineAddict@lemmy.world 7 points 11 months ago

Bonus points for leveraging the work of others contributing to their success

[-] Anonymousllama@lemmy.world 19 points 11 months 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

[-] DragonTypeWyvern@literature.cafe 29 points 11 months ago

screams in that's not the point

[-] fsxylo@sh.itjust.works 16 points 11 months ago

Pfft, writing a program that collects user input and displays it is just trite. I'm going to skip straight to building an MMO.

[-] frickineh@lemmy.world 18 points 11 months ago

Science-based, 100% dragon MMO or gtfo.

[-] CurlyChopz@programming.dev 4 points 11 months ago

I need 100k in my kick starter by tomorrow, sharp

[-] Rodeo@lemmy.ca 3 points 11 months ago

You're right. The learning is the point. So rather than flail in the dark, why not learn the optimal solution?

[-] PapstJL4U@lemmy.world 32 points 11 months 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 33 points 11 months ago

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

That pretty much sums that language up

[-] TheBananaKing@lemmy.world 10 points 11 months ago

In order to write a haskell program, you must first write the corresponding haskell program.

[-] lugal@sopuli.xyz 3 points 11 months ago

And in order to do that, you have to imagine sisyphus happy

[-] DarkenLM@artemis.camp 8 points 11 months ago

Strange. I find the language hideous, most likely because it resembles math, or maybe because I'm already used to the C-like syntax.

[-] lugal@sopuli.xyz 15 points 11 months ago

Haskell is beautiful because it resembles math

[-] xigoi@lemmy.sdf.org 14 points 11 months ago

It's also beautiful because it doesn't have C-like syntax.

[-] mindbleach@sh.itjust.works 4 points 11 months ago

Functional programming flips your brain around backwards, but shader programming will turn it inside-out.

[-] manpacket@lemmyrs.org 4 points 11 months ago

For more brain flipping try looking into hardware description languages (Verilog) or proof assistants (Coq).

[-] Knusper@feddit.de 10 points 11 months ago
hanoi :: Integer -> a -> a -> a -> [(a, a)]
hanoi 0 _ _ _ = []
hanoi n a b c = hanoi (n-1) a c b ++ [(a, b)] ++ hanoi (n-1) c b a

From here: https://www.rosettacode.org/wiki/Towers_of_Hanoi#Haskell

[-] DumbAceDragon@sh.itjust.works 12 points 11 months ago* (last edited 11 months ago)

Edit: I understand it now. That first line is just a really weird way to define a function.

[-] Knusper@feddit.de 5 points 11 months 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.

[-] nothacking@discuss.tchncs.de 21 points 11 months ago

Oh but we don't play it, we put lighting into rocks and trick them into doing it.

[-] ArmokGoB@lemmy.dbzer0.com 5 points 11 months ago

Towers of Hanoi? I don't think so.

[-] neonblade@lemmus.org 3 points 11 months ago* (last edited 11 months ago)

Example for stack

[-] CannotSleep420@lemmygrad.ml 3 points 11 months ago

I took a test once where one of the questions was to solve the tower of hanoi with 2 pegs and 3 disks.

[-] jackie_jormp_jomp@lemm.ee 2 points 11 months ago
[-] CannotSleep420@lemmygrad.ml 2 points 11 months ago

I was lucky enough to figure out that it was a trick question, but I second guessed every answer I put on tests and homework for that professor ever since.

[-] learningduck@programming.dev 1 points 11 months ago

How is that possible? is it has a different rule?

[-] CannotSleep420@lemmygrad.ml 1 points 11 months ago

No, it was a trick question. The test taker was supposed to pick up on that.

[-] stingpie@lemmy.world -2 points 11 months 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.

this post was submitted on 02 Oct 2023
866 points (98.7% liked)

Programmer Humor

19190 readers
1850 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