107
u/7Silver7Aero7 Oct 21 '25
Make three lists, randomly switch the first entries around until one list has, in this case 10, entries, done. No?
27
u/master-o-stall Oct 21 '25
like this?
math.randomseed(os.time()) local list1 = {1, 2, 3, 4, 5} local list2 = {6, 7, 8} local list3 = {9, 10} while #list1 ~= 10 and #list2 ~= 10 and #list3 ~= 10 do local lists = {list1, list2, list3} local from = math.random(1, 3) local to = math.random(1, 3) while to == from do to = math.random(1, 3) end if #lists[from] > 0 then table.insert(lists[to], 1, table.remove(lists[from], 1)) end end print("List 1:", table.concat(list1, ", ")) print("List 2:", table.concat(list2, ", ")) print("List 3:", table.concat(list3, ", "))21
u/7Silver7Aero7 Oct 21 '25 edited Oct 21 '25
I pictured it more like:
void sortByRng(){Random rng = new Random();List<int> L_A = new List<int>();List<int> L_B = new List<int>();List<int> L_C = new List<int>();
L_A.Add(1);L_A.Add(2);
L_B.Add(3);L_B.Add(4);L_B.Add(5);
L_C.Add(6);L_C.Add(7);L_C.Add(8);L_C.Add(9);L_C.Add(10);
for (int i = 0; i == 1;)
{int j = rng.Next(1,7);int k = rng.Next(1,7);
if (j == k) continue;
else
{if (j == 1) { L_B.Add(L_A[1]); L_A.Remove(1); }else if (j == 2) { L_C.Add(L_A[1]); L_A.Remove(1); }else if (j == 3) { L_C.Add(L_B[1]); L_B.Remove(1); }else if (j == 4) { L_A.Add(L_B[1]); L_B.Remove(1); }else if (j == 5) { L_A.Add(L_C[1]); L_C.Remove(1); }else if (j == 6) { L_B.Add(L_C[1]); L_C.Remove(1); }}if (L_A.Count == 10) { i++; }else if (L_B.Count == 10) { i++; }else if (L_C.Count == 10) { i++; }}
}Edit: I just realized that i completely forgot what i wanted to to with the 'k' variable and that there is no check for the order - so that may have something to do with that - but I'm not going to fix that because lol.
8
u/JakeyF_ Oct 21 '25
I love you for the language of choice
3
u/Striking_Action_9927 Oct 21 '25
What language is that?
9
u/JakeyF_ Oct 21 '25
Lua! A very lovely language (in my opinion)
4
2
u/Striking_Action_9927 Oct 21 '25
I’ve never heard of it. Is it similar to another language?
5
u/master-o-stall Oct 21 '25
very lightweight interpreted language, i made a static build of the interpreter at half a megabyte!
1
1
u/AwwnieLovesGirlcock Oct 24 '25
i usually use rust but of the more script-y languages i think lua is suuper cute :3 i use it allthe time for scripty things
3
u/meeps_for_days Oct 21 '25
There are 4 colors.
3
u/7Silver7Aero7 Oct 21 '25
Isn't it about getting all the rings stacked into a single column, with the catch being that they just fall though each other if the order is incorrect?
2
u/barr520 Oct 23 '25
No, it is about starting from 1 stack and needing to move it to another pole.
The catch is that you're not allowed to put a larger ring on a smaller ring.
This commonly reposted meme is making it sound harder than it really is.
There is nothing random, just a recursive algorithm.2
u/cryonicwatcher Oct 21 '25
They have to be ordered correctly, and a ring with another ring above it cannot be moved. Only the top ones can be moved from one place to another.
1
1
50
u/Time-Strawberry-7692 Oct 21 '25
Solving Towers of Hanoi was an assignment in one of my first programming classes.
16
u/Father_Wolfgang Oct 21 '25
For me it was an assignment in math class, part of my IT Bachelor.
3
Oct 22 '25
I did it in school. Like in 8 grade... Ganz, am I autistic?
2
1
Oct 23 '25
I didn’t see this until my college classes. The closest we got to algorithms in high school was simple Python toys.
1
Oct 23 '25
Wow, it's cool you had python in school. I'm glad people can have relatively easy beginning in programming. Where and how long ago it was? I'm just curious, sorry for question. Also sorry for bad English
1
Oct 23 '25
Oh I didn’t have it, my family was too poor for the private school that had it, but it was offered here on the east coast US in roughly 2010s. My school only had HTML at best, but I took college classes in high school so I got a bit of a leg up.
4
u/thepunkposerr Oct 21 '25
It was also an assignment for one of my first few programming classes (but it was at least a level 200 class tho)
2
1
u/According_to_all_kn Oct 22 '25
Not to be arrogant, but I remember figuring this out with stacked frogs in a videogame when I was like 8
Is it really worth making an assignment out of?
1
u/Time-Strawberry-7692 Oct 22 '25
The point wasn’t solving it, the point was programming to solve it. After all, you have to understand how to do it before you can write the code. Well, at least in the days before AI.
1
u/According_to_all_kn Oct 22 '25
Right, that makes sense. It's a pretty good programming exercise to cut your teeth on, like the old fizzbuzz
1
u/08Dreaj08 Oct 24 '25
This and Sudoku were assignments during my coding course on the topic of algorithms. First time I learnt Sudoku, but I don't remember the algorithm I came up with for it anymore lol. It felt pretty good being able to solve them, and I guess it's been really helpful to me since I take IT as a subject.
1
u/MrWhippyT Oct 24 '25
I'm pretty sure I had this as an assignment several times, at least once in C functional, once in C++ object oriented, and once in Ada inter process communication. Sadly I saw the picture and got a little bit excited.
1
u/Interesting_Celery74 Oct 25 '25
For me it was Othello. I don't think I could think of a better solution even now, tbh.
26
17
u/GhostingProtocol Oct 21 '25
I remember this!! I’ve been thinking for years I need to make an algorithm to solve these! Are they that difficult, what are they called? Think my record was 12 rings or something
9
6
u/qwertyjgly Oct 21 '25
def moveTower(height,fromPole, toPole, withPole): if height >= 1: moveTower(height-1,fromPole,withPole,toPole) moveDisk(fromPole,toPole) moveTower(height-1,withPole,toPole,fromPole)
def moveDisk(fp,tp): print("moving disk from",fp,"to",tp)
moveTower(3,"A","B","C")
3
u/GhostingProtocol Oct 21 '25
Oof so not that hard lol
12
u/qwertyjgly Oct 21 '25
it's just a simple recursive algorithm
the basic idea is, if you have a stack of size n, you need to move the bottom disk to the destination so you need to move a stack of size n-1 to the intermediary so you need to move a stack of size n-2 to the destination to make room etc. and you just build up a sequence of transformations with those rules
5
u/Zac-live Oct 21 '25
nope not at all. which is why a lot of courses use this as the go to example for recursion when first explaining it.
the meme makes sense not because the problem us hard but because learning the concept of recusion is confusing for some people and thats what it gets associated with
2
3
u/BandicootGood5246 Oct 22 '25
They algorithm isn't too hard. I nerded out on it for a bit to try figure out the algorithm. If you start from the most simple scenarios and find the fastest way to solve it I think you'll find the pattern
It's a very simple algorithm that will solve it for any number of rings
2
6
4
4
u/thirdjaruda Oct 22 '25
This was the problem my professor asked us to solve after teaching us recursion. I can easily do it with While but took me a couple of days to figure it out with recursion since recursion is very new to me at that time.
3
3
3
u/FancyPotatOS Oct 21 '25
So prominent that I can still remember the name of the puzzle 7 years later
3
u/mxldevs Oct 21 '25
Hit the streets offering $10000 to any random passerby that can write a program to solve an arbitrary number of rings. I'd watch that content
3
u/Mr_Master501 Oct 21 '25
Someone has to expain this to me please. Still a newbie
3
u/Wu-the-ordinary Oct 21 '25
This problem is used to introduce students about recursion. I still remember my 9th grade me hitting against the wall to solve the case.
3
3
u/DuePotential6602 Oct 21 '25
If
Else if
Else if
Else if
Else if
Else
Someone added a number, it nuked your code
2
2
u/ferriematthew Oct 21 '25
One of the most intuitive solutions for towers of Hanoi that I've heard of is basically just count in binary with the rings.
2
2
2
2
2
2
2
2
2
2
u/Outrageous_Flight822 Oct 22 '25
Mom said it's my turn to repost le epic funny hanoi towers recursion problem :(((((((
2
2
2
u/Wild_Instance_1323 Oct 22 '25
Every programmer dad who bought their kids this... hoping to see a miracle
2
u/Repulsive_Mistake382 Oct 22 '25
Question: What is the best algorithm for solving the Tower of Hanoi? Like, do we know that recursion is the best approach? Or could there be better ones?
2
2
2
2
3
u/GlowstickConsumption Oct 21 '25
Are you guys silly? This is simplest coding ever.
2
2
Oct 21 '25
Okay, it may be simple when you have experience but this is an exercice some people have to face after 3/4 months they discover x=1.
1
1
1
u/anonymous_3125 Oct 23 '25
Move the whole tower except the bottom plate onto another bar recursively. Move the bottom plate to the other bar. Move the rest of the tower back onto the bottom plate recursively. This is very basic…
1
1
1
1
u/Brilliant-Software-4 Oct 24 '25
Reminds me of when a class mate of mine wanted to do a calculator in C++ for our last assignment for the first semester before the teacher showed how it's far more complicated then one releases a specially when you go beyond making a calculator with just + and -
1
u/Odd_Protection7738 Oct 24 '25
Move 3 to 6, 1 to 4, 2 to 3, 1 to 2, 4 to the left, 1 to 4, 2 to 5, 1 to 2, 3 to 4, 1 to 6, 2 to 3, 1 to 2, 5 to 6, 1 to the middle, 2 to 5, 1 to 2, 3 to the middle, 1 to 4, 2 to 3, 1 to 2, 4 to 5, 1 to 4, 2 to the left, 1 to 2, 3 to 4, 1 to the middle, 2 to 3, 1 to 2.
1
1
u/FartacularTheThird Oct 25 '25
10 year old me in korriban being much more powerful than bioware programmers
1
u/Technical-Ad-7008 Oct 25 '25
Haha, as a mathematician this was one of the first proofs I did with induction. The amount of switches needed for a tower of n disks
1
0
Oct 21 '25
[deleted]
160
u/exophades Oct 21 '25 edited Oct 21 '25
It's for kids in the sense that kids can just cluelessly move around the pieces and solve the game by being lucky. Then they'll be happy about how lucky and precious they are, in pure blissful ignorance.
17
u/Weekly_Goose_4810 Oct 21 '25
It’s a very simple algorithm when you’re not programming it. I specifically remember playing this game in elementary school. You just have to start from 3 pieces and move up from there and the algorithm becomes really clear in person
10
u/_Alpha-Delta_ Oct 21 '25
Nah, a 10YO kid can definitely find and understand the solving logic.
It's just that most of them have better things to do and probably won't give it enough time to understand it.
2
u/Scrawlericious Oct 21 '25
TF that is not remotely luck. XD that's like saying that solving a rubix cube is luck.
53
Oct 21 '25
[removed] — view removed comment
12
u/QL100100 Oct 22 '25
Give one monkey enough time with a typewriter and the same think could be achieved
12
u/holy-moly-ravioly Oct 22 '25
Give one Shakespear enough monkeys, and eventually they can typewrite.
8
u/Sophiiebabes Oct 22 '25
Give enough typewriters a Shakespeare and eventually they will monkey
5
3
2
9
u/Charming-Cod-4799 Oct 21 '25
Isn't it like fine 8th grade programming problem? 9th max. (If you actually teach kids some algorithms)
13
u/SuperBuffCherry Oct 21 '25 edited Feb 27 '26
This post was removed by its author using Redact. Possible reasons include privacy, preventing this content from being scraped, or security and opsec considerations.
distinct wakeful rob lock market fearless arrest wrench work employ
8
u/Firered_Productions Oct 21 '25
I learned the algo for this in 6th grade, I learned how to write a for loop in python in 8th grade. You do not need programming at all to solve Towers of Hanoi.
5
u/Charming-Cod-4799 Oct 21 '25
I meant "it's fine 8th grade programming problem for majority of kids if they have adequate school curriculum", not "I learned it in 8th grade, look how smart I am" :)
I don't think I myself ever actually solved towers of Hanoi, I think I first encountered it as an example.
6
u/Firered_Productions Oct 21 '25
OK I went to math camp and they covered it there, I did not invent recursion in middle school. But I was able to follow the reasoning they gave and tested it (manually) for small n.
2
u/neneaRedLIKE Oct 21 '25
In python is nothing try to do it in c in 6th grade then we are talking
0
u/Firered_Productions Oct 21 '25
blud I inplemennted that shit in C++ in 3 minutes but not when I was in middle school
3
2
u/TimGreller Oct 22 '25
I first encountered it in the second semester of the bachelor, when I took an "algorithms and data structures" lecture.
1
Oct 23 '25
Where I lived, kids only got HTML “programming” classes or in the fancy private school they got Python in high school. Had to go to college to get the algorithms. This is pretty common.
180
u/[deleted] Oct 21 '25
I still remember this game, I wrote in ASM for x86 CPU with visual animation to it. All in ASSEMBLER.
I was ambitious back then, and made my own IDE for ASSEMBLER when I found nothing suitable.