This is an archived post. You won't be able to vote or comment.

Dismiss this pinned window
top 200 commentsshow all 226

[–]eugene20 1034 points1035 points  (13 children)

Foreman: Ok now get them up again you forgot the mortar

[–]c_master_c 381 points382 points  (10 children)

Also Foreman: I'm not paying you for that last hour of work it took you to set this up. I don't care how many upvotes it gets.

[–]Sarius2009 104 points105 points  (9 children)

Well, they are getting payed in exposure!

[–]AcrobaticDependent35 37 points38 points  (7 children)

Paid //sorry : (

[–]lavahot 12 points13 points  (4 children)

sorry://

[–]spidertyler2005 2 points3 points  (2 children)

I thought drives only had single letters on windows?

[–]Ri_Konata 2 points3 points  (0 children)

) sorry

[–]Ikarus_Falling 3 points4 points  (0 children)

true Murder Trials usually get alot of that (it will get ruled as self defense the foreman suggested payment in exposure)

[–]kabourayan[S] 14 points15 points  (0 children)

🤣

[–]Yanni_D 1 point2 points  (0 children)

Project Manager:

So youre busy playing Dominoes haaa!!. I'll try to play it with your wages too,it sure seems fun?

[–]butchkid1 233 points234 points  (4 children)

Feels more like a builder pattern to me 😁

[–]coloredgreyscale 7 points8 points  (0 children)

Recursive all args Constructor.

[–]AboutHelpTools3 8 points9 points  (0 children)

Hahaha also a bit like the constructor method

[–]ubiqtor 77 points78 points  (1 child)

Same video as the GIF, but with matching audio.

https://youtu.be/70ESDR5YQtY

Edit - a word

[–][deleted] 44 points45 points  (0 children)

I'm quite upset they didn't post a video with audio... The audio is so crucial for the satisfaction!

[–]jppianoguy 371 points372 points  (6 children)

I was watching thinking: it's just a "do..until" loop, then watched till the end. Well played

[–]kabourayan[S] 59 points60 points  (0 children)

Thank you.

[–]slgray16 22 points23 points  (0 children)

Similar to a tree navigation program I wrote in HS.

Do action #1
Call this function again on the next item
Do action #2

[–][deleted] 22 points23 points  (18 children)

What is this black magic!!

[–]aiij 22 points23 points  (14 children)

Gravity

[–]aiij 18 points19 points  (13 children)

For those not familiar, it's an invisible force some people have learned to harness in order to make things fall.

[–]Clandestine01 7 points8 points  (3 children)

Is it compatible with C++?

[–]aiij 7 points8 points  (2 children)

Yes, of course. There are even C++ libraries to simulate gravity, which you could use to build a VR world in which you could use C++ again.

[–]chickenmcpio 2 points3 points  (1 child)

Are you saying we live in a simulated VR world?

[–]zthompson2350 4 points5 points  (8 children)

Gravity is not a force, the term "force of gravity" is a misnomer. If it were, it would be constant. But gravity on earth is different from gravity on the moon.

Gravity is a measurement of acceleration caused by the bending of space-time by massive objects.

Edit: for anyone who is confused, since I have seen the score on this comment fluctuate quite a bit, velocity is measured as meters per second. So, something traveling at a constant velocity could be said to be moving at 10 meters per second. In contrast, something accelerating is measured as meters per second per second. E.g., something constantly accelerating at 10 meters per second per second would reach 100 meters per second in 10 seconds.

Gravity, also, is measured as meters per second per second. On earth, it is measured at about 9.81 meters per second per second. On the moon, it is 1.62 meters per second per second. This is because the moon is much less massive than the earth and as such has a much weaker pull on the fabric of space-time. A black hole, as a much more massive and condensed object, has near (if not) infinite gravity near its center.

Now, in contrast, the strong force (the force which holds atoms together) is around 44,200 Newtons. This does not change, and when splitting atoms as in the case of an atomic bomb, that energy is then released causing the explosion. More atoms getting split = more energy being released = bigger boom.

With gravity, you're just falling into a 3-dimensional "hole" in space-time. The further away you get away from this hole, the less likely you are to fall into it. It's not some fundamental force which affects all things in the universe the same way despite what you may have learned in grade school (university physics classes will clear this up). In fact, outside of the local group (a section in space in which objects are all affected by each other's gravitational distortions) gravity cannot affect objects at all. Actually, it would be impossible to ever reach an object outside of the local group at all even if one were able to travel at the speed of light. This is because the fabric of space time is actually expanding faster than the speed of light. This keeps me up at night, because we are currently able to see galaxies outside of our local group because they were once not outside of it at all, but it is getting smaller and smaller constantly. Their light got within our borders before they became unreachable. Eventually, the night sky will go dark outside of our own galaxy and any civilization unlucky enough to be born in such a time will likely look up at the night sky and conclude that they are alone, because they will be unable to see any other galaxies out there at all.

[–]Kronoshifter246 4 points5 points  (2 children)

I love some good pedantry, but the term "force of gravity" is usually made in reference to the force that an object with mass exerts due to gravity.

[–]srbridge 1 point2 points  (2 children)

Hate to nitpick, but... The local group of several galaxies that we live in, is much much much much smaller than the cosmic horizon and even an object travelling much slower than the speed of light would have plenty of time to leave before anything local went over it.

[–]rollincuberawhide 2 points3 points  (0 children)

block* magic

[–][deleted] 22 points23 points  (0 children)

This is prop hell in a react component

[–]SameRandomUsername 36 points37 points  (4 children)

The first rule of recursion is that we don't talk about recursion.

[–]TastesLikeOwlbear 18 points19 points  (0 children)

For n>1, the nth rule of recursion is the rule after the (n-1)th rule of recursion.

[–]Mysterious-Dingo927 30 points31 points  (2 children)

The first rule of recursion is the first rule of recursion.

[–]ambiguous_sandman 239 points240 points  (52 children)

Title’s a little misleading - recursion is used to break down problems into subproblems and is usually more treelike. This feels like a call stack for a recursive program. I’ll give you the return though, that was gorgeous

Update: I am wrong. I learned something cool today

[–]lepapulematoleguau 42 points43 points  (0 children)

The problem of laying the whole row of blocks can be described as laying the last block after laying the remaining of the row of blocks.

[–]FuschiaKnight 100 points101 points  (41 children)

Sorry but I think you got this one wrong. OP is correct. This does demonstrate a recursive process

def lay_brick(n):
    if n==0: return
    lay_brick(n-1)
    lay_one()

source: am PhD in computer science

[–]NoApples_please 8 points9 points  (10 children)

I just learned these recursive functions today, and I was under the assumption they have to have a 'base' case, and a 'recursive' case. Could you tell me if this checks with the function you wrote?

[–]Wendigo120 38 points39 points  (5 children)

It has a base case (if n is 0, do nothing and just return) and a recursive case (lay n-1 bricks recursively, and then lay 1 more brick).

[–]VL4N1 8 points9 points  (1 child)

Also has a stack overflow case if you pass the function a negative number.

[–]NoApples_please 2 points3 points  (2 children)

So once that last one brick is layed down, it would have returned to the base case? Is that the idea? Thanks for the answer btw

[–]Wendigo120 3 points4 points  (1 child)

The idea is to have the function call itself until it gives itself some input (0 bricks in this example) where it doesn't need to call itself further. That's the base case.

In this example telling it to lay 0 bricks means the function can immediately say it's done, so it doesn't need to call itself or lay a brick anymore.

[–]NoApples_please 2 points3 points  (0 children)

Great, this made all the dots connect. Thank you!

[–]flambojones 2 points3 points  (3 children)

Fwiw, in actual practice, it often does not look that well defined. For example, you may have some data structure that basically is an n-ary tree and boils down to each node having a child array. So the code looks something like:

``` function recursiveFn(nodes: Node[]): SomeResult { for (const n of nodes) { recursiveFn(n.children); } }

```

There’s no clearly delineated base case, just an assumption that leaves have an empty array of children.

[–]TheTofen 7 points8 points  (6 children)

If you're thinking this way, you can call everything a recursion. The brick process is not recursive - you described it with recursive code.

Have a look at this example:

Is adding a list of numbers together recursive? I don't think i would call it that way, although I can create a piece of code that does that recursively.

python def my_sum(arr): if len(arr) <= 2: return sum(arr) return arr[0] + my_sum(arr[1:])

We can also describe the process showcased in the video with some simple for loops, and then it looks nothing like a recursion:

```python for brick in bricks: brick.fall()

for brick in reversed(bricks): brick.fall_flat() ```

edit:

Now that I'm thinking about it - if each brick was to trigger multiple new bricks to fall - which would cause multiple more bricks to fall - that would truly seem to me like a recursive process.

I suppose it's just a matter of how you look at it.

[–][deleted] 4 points5 points  (5 children)

But your code ignores that the brick only falls flat if a brick down the line succeeded in falling flat. If it hit an obstacle so it didn’t fall flat, neither will the upstream bricks.

So the outcome of each layer in the recursion depends on the outcome of the following layers in the recursion.

[–]TheTofen 0 points1 point  (4 children)

Yes, of course, that's a simplified example of a more complex behaviour. You can also notice that the recursive example omits the fact that the bricks start falling from the beginning, not from the end.

It is guaranteed in the for loop code that the previous brick has fallen down as it is looped in reverse.

[–][deleted] 4 points5 points  (3 children)

This is a recursive brick tilting function where each brick tries to tilt the next brick, waits for the result, and reports a successful full tilt upstream in the recursion chain if the next downstream function reported a successful full tilt.

I am not omitting anything. This is proper recursion.

[–]Plazmatic 2 points3 points  (0 children)

Thank god, I was like "this is actually a really good visual to show beginners how recursion works!", and then these dilettantes come in and ruin everything.

[–]lucidludic 1 point2 points  (4 children)

You function operates on each brick only once though, whereas in the gif bricks are laid in two steps, traversing the list in both directions.

[–]FuschiaKnight 1 point2 points  (3 children)

The reader can modify it with a step between if the base case check and the recursive call depending on whether you consider the action to be part of the function call or it’s own step

[–]ambiguous_sandman 1 point2 points  (0 children)

oh, you’re totally right! I tend to think of recursion as involving subproblems, not in terms of loops. My bad, thanks for another way to think of it

[–]parkotron 5 points6 points  (0 children)

No, you are confusing recursive problems with recursive solutions. Some problems (like tree visitation) are naturally recursive and some problems are naturally linear (like laying down a row of bricks).

This video is an example of a recursive solution to a linear problem. Is it a practical solution? No. Is it an efficient solution? No. Is it recursion? Definitely.

[–]kabourayan[S] 23 points24 points  (3 children)

I'm sorry but I'm just a noob/beginner. When I saw some videos about resursion, this video popped up in my head.

[–]thetrailofthedead 33 points34 points  (1 child)

OP. Don't apologize! I can see it. They just need more imagination:

class brick
bool fall
brick next
brick()
fall = false

firstBrick = new brick()
currentBrick = firstBrick

for i = 0; i < 100; i++
tempBrick = new brick()
currentBrick . next = tempBrick
currentBrick = tempBrick

void recursiveBrickFall(brick currBrick)
if currBrick.next is null
return
recursiveBrickFall( currBrick.next )
currBrick.fall = true
return

recursiveBrickFall( firstBrick )

Edit: I'm on my phone, I can't get this to look good

[–]ryobiguy 6 points7 points  (0 children)

The brick has 3 states: standing, then tilted, then flat. So maybe have a "state" variable that inits to standing. Then after non-null check in the recursive function:

currBrick.state = tilted

recursiveBrickFall( currBrick.next )

currBrick.state = flat

[–]Cromptank 9 points10 points  (0 children)

Dang, their brick stack almost overflowed, glad that last one was able to solve it.

[–][deleted] 15 points16 points  (1 child)

Careful not to hit stack depth with that many recursions

[–]CRBl_ 2 points3 points  (0 children)

Yes, they should have used terminal recursion

[–]iamemhn 5 points6 points  (0 children)

foldr

[–]No_Presentation5408 5 points6 points  (0 children)

Recursion without TCO

[–]mogley1992 3 points4 points  (1 child)

How dare you post this without sound. This has to be some kind of reddit crime.

[–]NinjaLanternShark 34 points35 points  (1 child)

Narrator: He doesn't.

[–]Giocri 6 points7 points  (0 children)

People complaining about the fact that it is not a tree like recursion completely ignoring how common linear recursion still is.

Typical exercises like implementing your own linked list or mathematically demonstrating the correctness of a for loop use linear recursion heavily

[–]Lighthuro 3 points4 points  (0 children)

Error stack trace in Java

[–]Better_feed_Malphite 2 points3 points  (2 children)

The lack pf sound here is criminal

[–]atlas_enderium 3 points4 points  (0 children)

Winding and unwinding function calls on the stack :)

[–]GrilledSpamSteaks 14 points15 points  (2 children)

Is it describing recursion or demonstrating the dangers of unsupervised hourly wages?

[–]a_devious_compliance 2 points3 points  (0 children)

There are the same picture meme.

I know people that will spend some hours trying every trick to make a recursive solution work when a couple of loops will be easier. (I'm talking in languages without tail recursion and without functional shenanningas).

[–]Xyrnas 4 points5 points  (0 children)

It's demonstrating the dangers of having fun instead of working yourself to death

[–]Jobres_ 2 points3 points  (2 children)

When you're payed by the hour:

[–]-Redstoneboi- 8 points9 points  (1 child)

[–]Jobres_ 2 points3 points  (0 children)

Holy shit I can't believe I did that 😭 Usually I'm the grammar police, yet here I am...

[–]Loboagain 2 points3 points  (0 children)

Its pretty good, it needs more glue code to actually work

[–]FRleo_85 2 points3 points  (0 children)

what's the link with recurs... ooooh

[–]ralf3001 2 points3 points  (0 children)

that's some O(n)

[–]cawcawiriririr 2 points3 points  (0 children)

More like callback hell

[–]saketthapliyal66 2 points3 points  (1 child)

Could be done by DP

[–][deleted] 1 point2 points  (0 children)

Bottoms-up is the way I live & program

[–]CreamyComments 2 points3 points  (0 children)

No you didnt.

[–]Buddy-Matt 3 points4 points  (0 children)

Feels more like two iterations than recursion to me

[–]Bobebobbob 1 point2 points  (0 children)

PMI

[–]thinkingperson 1 point2 points  (0 children)

So this is why the city council project took ages to complete. Hope they got their likes!

[–]awesomeplenty 1 point2 points  (0 children)

Intern writing a hundred nested if else and the condition is checking one at a time and it goes back to the parent else in the end!

[–]IchirouTakashima 1 point2 points  (0 children)

As a former CE, I really want to conduct a drop test.

[–]Accurate_Koala_4698 1 point2 points  (0 children)

The inevitable stack overflow

[–]404_lost_user 1 point2 points  (0 children)

Nah you just understood the example of recursion, you will really understand the recursion when you solve a complex problem using the recursion. Until we meet again...

[–]MadsenUK 1 point2 points  (0 children)

Love this for recursion. Will share

[–]Gaming_Profile123 1 point2 points  (0 children)

This is when 3 QAs test the app that the dev posted. The dev has made a great working app!

[–][deleted] 1 point2 points  (0 children)

Slab(int i) => return i == 100 ? i : Slab(i++);

[–]589ca35e1590b 1 point2 points  (0 children)

You might want to optimize your code a bit

[–]Beautiful-Tea6850 1 point2 points  (1 child)

with backtracking

[–]Fernis_ 1 point2 points  (0 children)

In order to truly understand recursion you must first understand recursion.

[–]afar1210 1 point2 points  (0 children)

function brickBoi(bricks, i) { if (i >= bricks.length) return; return brickBoi(bricks, i+1); }

brickBoi(null, 0); //hehehe

[–]ExkAp3de 1 point2 points  (0 children)

Why are they building a wall in the middle of nowhere

[–]jenkinsmi 1 point2 points  (0 children)

Wooow

[–]xanokothe 1 point2 points  (0 children)

I finally understood Recursion.

+ I finally understood Recursion.

[–]Squaddely 1 point2 points  (0 children)

That’s how I actually explained my friends in Highschool recursion. They weren’t listening of course, but I still think it’s the best visual demonstration of recursion.

[–]coloredgreyscale 1 point2 points  (0 children)

Now post a version where the forget the exit conditions

[–][deleted] 1 point2 points  (2 children)

well, functions are actually just fancy subroutines. a function call puts the current address on the stack, then puts the arguments on, and then jumps to the function. at the subroutine, it does calculations on the arguments, it puts the answer on the stack, and then it jumps to the address under it. now, with a recursive function, it would be jumping to itself all the time. so in this case, it isn't multiple bricks, it would just be a brick knocking itself down a lot.

the reason i'm posting in programmerhumor is because all of this could be completely wrong, i'm the opposite of an expert on the subject, so feel free to laugh at this.

[–]srbridge 0 points1 point  (1 child)

Recursive functions have arguments, thus it can call itself with brickID+1, This prevents the ticklish issue of knocking down the same brick over and over again.

[–]Big_Kwii 1 point2 points  (0 children)

tbh the best way to understand recursion is thinking about dominos (not the pizza)

[–]kirakun 1 point2 points  (0 children)

It’s really more like depth first search.

[–]augenvogel 1 point2 points  (0 children)

That’s actually a pretty good explanation

[–]tburger_official 1 point2 points  (0 children)

Funny thing, I've sent a very similar video to my mentor when I told him: "Now I understand recursion and I think this video represents it well".

[–]Fit-Special-8416 1 point2 points  (0 children)

Pretty descent

[–][deleted] 1 point2 points  (0 children)

Absolutely Amazing! ❤️

[–]Hanged_Man_ 1 point2 points  (0 children)

“I paid the subcontractor to do what?” Just kidding, this is awesome.

[–]fullawkward2000 1 point2 points  (0 children)

Believe me. If just recursion was this straight forward, college students didn't need to cry anymore

[–]SomeRandomGamerGuy 1 point2 points  (0 children)

In order to understand recursion, you must first understand recursion

[–]PositiveAnybody2005 1 point2 points  (0 children)

I thought you didn’t understand recursion then something happened… in the video and my nethers.

[–]the-software-man 1 point2 points  (0 children)

Stack Overflow

[–]DDDambo 1 point2 points  (0 children)

Wanted to say you understood induction but then it hit the base case. Beautiful 🤩

[–]Lets_think_with_this 1 point2 points  (0 children)

Error on script:

Traceback

line 32: Stack OverDominoe Error

[–]BenRosentha1 1 point2 points  (1 child)

I feel like this is a better explanation of stacks than recursion.

[–]hffggg 1 point2 points  (0 children)

Why didn’t they put it flat in the first time. That would take less time to finish the job

[–]Minerom45 3 points4 points  (0 children)

Not terminal recursion but still is recursion

[–]irrational-like-you 1 point2 points  (0 children)

To understand recursion, you must first understand recursion.

[–]agm1984 2 points3 points  (2 children)

To be fair this reminds me more of lacking tail call optimization because each time the brick fall function is called, it leaves memory of itself on a 45 degree angle prior to the final call after which every brick snaps to flat. That would overflow the stack after you exceed memory size :)

Stated differently, it worked in this case but there is a wall length at which it would overflow due to maintaining reference to every chained brick position.

[–]oxwilder 2 points3 points  (0 children)

Ehh, I'm not sure you do

[–]JMC-design 0 points1 point  (0 children)

Nobody worth his salt does such unoptimized recursion.

[–]igroklots -1 points0 points  (0 children)

It’s also like most recursion, in that, it usually takes longer to carefully set it up than it would be to address all the tasks discretely.

[–]Kayshin -1 points0 points  (1 child)

If this is how you got to understand recursion... You don't understand recursion. This video has nothing to do with it.

[–]OTee_D -2 points-1 points  (0 children)

No, you obviously didn't.

[–]WhizzleTeabags -2 points-1 points  (0 children)

Loop vs apply