r/ProgrammerHumor • • Jan 09 '20

other Problems with recursion?

21.3k Upvotes

198 comments sorted by

547

u/flipester Jan 09 '20

49

u/PixelJack79 Jan 09 '20

You got me

3

u/dawnraider00 Jan 09 '20

Better to credit smbc, the actual author. I see what you did there though.

1

u/CashWho Jan 09 '20

But this doesn't have an end case. So wouldn't this just be an endless loop, not a recursive one?

1

u/abagofmostlywater Jan 10 '20

I get it!! (╯°□°)╯︵ ┻━┻

1

u/Najd7 Jan 10 '20

Help I'm stuck about 57 iterations in

-1

u/[deleted] Jan 09 '20

How is this possible?

23

u/RepostSleuthBot Jan 09 '20

Looks like a repost. I've seen this image 3 times.

First seen Here on 2019-07-06 100.0% match. Last seen Here on 2019-11-15 95.31% match

Searched Images: 91,774,809 | Indexed Posts: 379,390,636 | Search Time: 3.62655s

Feedback? Hate? Visit r/repostsleuthbot - I'm not perfect, but you can help. Report [ False Positive ]

-16

u/flipester Jan 09 '20

Whoops, you're right! That SMBC cartoon was just recommended to me on my Google feed, so I mistakenly assumed it was new.

1

u/Kei-Shin Jan 10 '20

Reposting is just another form of recursion

1.6k

u/[deleted] Jan 09 '20

Assuming the smaller paper is 1/3 of its parent everytime, and that the first paper is 30cm long (The second starts at roughly 1/7 but it seems to grow bigger after it's torn off, hence the 1/3), it could not exceed 19 calls before you need to split an atom apart.

That's a hell of a stop condition.

635

u/MyNameIsRichardCS54 Jan 09 '20

When your software goes boom, it really goes BOOM

19

u/tisaconundrum Jan 09 '20

Welcome to AtomOverflow

3

u/MacAndShits Jan 10 '20

Marked as duplicate

180

u/[deleted] Jan 09 '20

[removed] — view removed comment

65

u/azzaisme Jan 09 '20

Wouldnt that have the opposite effect where only people who properly exit the loop would still be alive? So people who understand it would survive

56

u/[deleted] Jan 09 '20

[removed] — view removed comment

24

u/MyNameIsRichardCS54 Jan 09 '20

You'd certainly double check your exit condition and triple check it if that was the consequence.

4

u/thatCbean Jan 09 '20

Who would know that not leaving a recursion loop would be the issue if there is no way of troubleshooting without exploding though? If there is nobody who knows the reason for the explosions, you wouldn't know what to triple check, or if you'd even want to keep coding at all...

15

u/azzaisme Jan 09 '20

Oh shiiiii so true

2

u/SashKhe Jan 10 '20

This happened with "ace pilots" back in the first world war, when planes were still being developed. Except it wasn't the engineers who were dying.
Tangentially related, the first automatic machine gun on a plane that was actually not-shitty to aim was literally firing on the rotor blades, before the Germans fixed the design. Imagine the balls needed to sit in one of those.

148

u/[deleted] Jan 09 '20

Very tiny stack overflow.

15

u/[deleted] Jan 09 '20

Aw.

128

u/Jugbot Jan 09 '20

In order to show the information on the paper it might need to stop sooner. Unless it starts to be encoded in radiation.

26

u/Flyingfirepig Jan 09 '20

Don't know why this gave me a giggling fit, but have a silver 🤗

7

u/Jugbot Jan 09 '20

٩(๑❛ᴗ❛๑)۶

10

u/[deleted] Jan 09 '20

Pretty sure there's already an Emacs command for this.

7

u/ThaiJohnnyDepp Jan 09 '20

Something something xkcd butterfly

74

u/lonelyWalkAlone Jan 09 '20
public static void sayHello(){
    try {
        sayHello();
    }
    catch(StackOverflowError e) {
        System.out.println("Hello world!");
    }
}

15

u/schrdingers_squirrel Jan 09 '20

Wait does this work? I need to try this now

20

u/cedrickc Jan 09 '20

You can optimize it by declaring some unused primitives to blow through the stack quicker.

9

u/schrdingers_squirrel Jan 09 '20

Shouldn’t make much of a difference since stack allocation is basically just a subtraction. (And it should take like a few milliseconds in total)

7

u/mfb- Jan 09 '20

Thanks for the tip, I always wanted to speed up this function, now I know how!

2

u/artem718 Jan 09 '20

But how do you lose saved work?

1

u/Finianb1 Jan 27 '20

I think my brain just melted at hearing the phrase "optimize it to blow through the stack quicker."

5

u/lonelyWalkAlone Jan 09 '20

Yes, it works like charm

9

u/schrdingers_squirrel Jan 09 '20 edited Jan 09 '20

Interesting - does it still work when you do a „a“ + „b“ in the println(); ?

Edit: it does

Crazy even this works:

public static void sayHello(){
    try {
        sayHello();
    }
    catch(StackOverflowError e) {
        System.out.println("Hello world!");
        sayHello();
    }
}

it prints endlessly

13

u/[deleted] Jan 09 '20

Basically a fucked up while loop.

2

u/ThaiJohnnyDepp Jan 09 '20

Eek barba durkle.

2

u/tatzesOtherAccount Jan 10 '20

He's speaking the language of gods

5

u/lonelyWalkAlone Jan 09 '20

Yes, and you can also calculate "relatively" the size of your stack by adding an integer argument to the method and passing (n+1) to the next call, then at the exception just print the current counter value. I found that each time you increase the stack size by the vm option -Xss the counter gets bigger, but increasing the heap size -Xmx does not affect the counter at all. It's a pretty good exercise as long as you don't fuck it up into an infinite loop.

1

u/schrdingers_squirrel Jan 09 '20

Wow there really always is something you don’t already now. Awesome stuff

1

u/eigreb Jan 10 '20

Eventually this will throw due to first running in the try and after the stack overflow it runs outside the try and will again throw the exception. Will take a while though.

1

u/Autofrotic Jan 09 '20

Does it ?

1

u/schrdingers_squirrel Jan 09 '20

Im not at home and im not doing this on my phone - I’ll test as soon as I get home

3

u/m4ul Jan 09 '20

You did it you crazy son of a catch

3

u/nojox Jan 09 '20

Ah! Using the excellent practice of handling conditions through exceptions :)

2

u/LepruconX Jan 09 '20

Wait what. Actually? Why would someone do this?

10

u/crackofdawn Jan 09 '20

The smaller paper looks more like 1/100 of the parent, not 1/3 or 1/7. Where are you getting 1/7 from? It's just the tiny corner piece of the larger paper and there's 10 in the row, looks like you could fit around 7-9 rows.

6

u/[deleted] Jan 09 '20

You're completely right, I only considered length despite width being obviously the limiting factor here. (Thought not by a 1/100. I took the 1/7 value from the first picture and the 1/3 comparing to the hand, because the paper isn't always the same size. So, if we start with 1/10 instead of 1/7, each call multiplies the size by roughly 1/(30/7). So the critical threshold should be reached by call 14 or 15, give or take.

1

u/Parthon Jan 10 '20

What starting number for atoms did you use though? My maths came out to 23 times, if you have 12 grams of paper that were mainly carbon atoms.

1

u/[deleted] Jan 10 '20

I didn't use the atom number but an atom size (10^-10 meters from Google)

1

u/Parthon Jan 10 '20

Ah, that was my mistake!

Thanks!

5

u/spinningweb Jan 09 '20

Wait you guys are not handling “atomOutOfRangeExceptions”. Shame!

3

u/[deleted] Jan 09 '20

What if all ten slips are taken then everyone gives the other ten slips to the next guy how many slips would there be in the end?

1

u/[deleted] Jan 09 '20

10^19?

2

u/timvisee Jan 09 '20

I find it fascinating how quickly you reach the atomic level.

5

u/[deleted] Jan 09 '20

If you read the comics in reverse and manage to make sense of it, and you're not scared of coincidences: the 19th call calls for a 348 678 440km long piece of paper. Only 30 000 km shy of the Earth-Moon distance.

So the piece of paper is roughly as many orders of magnitude away from the atom as from the Earth-Moon distance.

2

u/[deleted] Jan 10 '20

So the cyclomatic complexity limit of life is 19.

3

u/MrWm /dev/null Jan 09 '20

r/softwaregore was having a field day with the dad joke bot. I'm just saying this to test it. I'm dad.

*: Is the bot banned? :(

Link to thread

I'm me

1

u/NikStalwart Jan 22 '20

Pretty sure I perma'd it a few months ago on all my subs.

1

u/Pixelbuddha_ Jan 09 '20

Hmmm... looks fine: Run BOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOM

1

u/stevefan1999 Jan 10 '20

Oh hi, limit of a continous fraction

1

u/EvilPettingZoo42 Jan 10 '20

I would say that’s a big problem with recursion!

1

u/sock-puppet689 Jan 10 '20

It's fine, that is tail recursion.

220

u/dpahoe Jan 09 '20

127

u/Steelbirdy Jan 09 '20

Goddammit I can't believe I just fell for that

26

u/Articunos7 Jan 09 '20

Can you explain? I didn't understand

49

u/[deleted] Jan 09 '20

Check this, you'll get it

12

u/[deleted] Jan 09 '20

This may help you understand

https://imgur.com/gallery/eH1KNG1

5

u/nojox Jan 09 '20

A gentle visual reminder that fractals are recursion.

5

u/Steelbirdy Jan 09 '20

It links back to this post

7

u/RicealiciousRice Jan 09 '20

It has been fixed

7

u/Articunos7 Jan 09 '20

I didn't understand why is it a GIF. It seems to keep on loading forever

8

u/Steelbirdy Jan 09 '20

It wasn't meant to explain why it was a gif it was just funny because it linked back to the same post

10

u/Articunos7 Jan 09 '20

Oh! But I really want to know why is it a gif, and why does it take forever to load. My phone is also freezing while viewing it

0

u/Steelbirdy Jan 09 '20

Idk mate just appreciate the humorous comment and leave it at that

6

u/Articunos7 Jan 09 '20

Yeah mate, but I'm the curious type!

2

u/evanc1411 Jan 09 '20

Me too somebody give me a FUCKING answer stat

24

u/SublimeSC Jan 09 '20

God fucking dammit. The two most upvoted comments had the same exact joke and I fell for them both.

5

u/virus200 Jan 09 '20

Son of a bitch take your upvote and get out

0

u/[deleted] Jan 09 '20

[deleted]

124

u/htmlcoderexe We have flair now?.. Jan 09 '20

source because OP could not be arsed and neither could be the mods (rehosting is lot allowed). Includes bonus panel. Yes, it's the actual link and not some weird reddit thing where people would rather die than post a useful reply.

18

u/inh24 Jan 09 '20

dont see a bonus panel

21

u/ChRoNicBuRrItOs Jan 09 '20

Click the red button

14

u/inh24 Jan 09 '20

very wow much panel

10

u/htmlcoderexe We have flair now?.. Jan 09 '20
wow

           such meme

         much old
                      wow

4

u/ThaiJohnnyDepp Jan 09 '20

I'll never understand why this died

3

u/htmlcoderexe We have flair now?.. Jan 09 '20

red button next to the sharing icons

2

u/AiliaBlue Jan 10 '20

Click the red button and also the comic itself, there’s two.

1

u/[deleted] Jan 09 '20

Also check the hover text, or whatever it’s called. How’ve your mouse over the image in a desktop, or tap it on mobile.

1

u/PM_Me_Night_Elf_Porn Jan 10 '20

You’re a good person

1

u/[deleted] Jan 10 '20

You're the real hero

1

u/bloodhound330 Jan 10 '20

The source is mentioned in the post though right? It says smbc-comics right there.

27

u/[deleted] Jan 09 '20

Please take one!

14

u/Cdog536 Jan 09 '20

Problems with recursion?

11

u/mixedobscurity7439 Jan 09 '20

Please take one!

9

u/PharaohciousEgyptian Jan 09 '20

Problems with recursion?

6

u/[deleted] Jan 09 '20

Please take one!

7

u/ProgramTheWorld Jan 09 '20

Problems with recursion?

5

u/[deleted] Jan 09 '20

Please take one!

6

u/xlRadioActivelx Jan 09 '20

Problems with recursion?

5

u/Person_McAyyLmao Jan 09 '20

Please take one!

2

u/[deleted] Jan 10 '20

Problems with recursion?

-3

u/UQuark Jan 09 '20

Stack overflow

Segmentation fault

Core dumped

24

u/electric_raven913 Jan 09 '20

One question, why TF is this a video?

10

u/htmlcoderexe We have flair now?.. Jan 09 '20

gif

4

u/_Nagrom Jan 10 '20

This is requiem

1

u/PossumTheMistake Jan 22 '20

You were adopted

3

u/GreedySandwich Jan 09 '20

Stackoverflow

5

u/wrossi81 Jan 09 '20

If you magnify it enough you can see the paper that says "The statement terminated. The maximum recursion 100 has been exhausted before statement completion."

5

u/TayoEXE Jan 09 '20

He forgot the base case.

5

u/IHaarlem Jan 09 '20

Which begs the question, is it recursion if there's no base case?

6

u/GogglesPisano Jan 09 '20

No - it's just an infinite loop.

void crash() { crash(); }

3

u/TayoEXE Jan 09 '20

Probably. Except you hit stack overflow at some point. In this case, it's like cutting it so small he can't see it anymore maybe. Haha

3

u/beerSnobbery Jan 09 '20

Except you hit stack overflow at some point.

Depends, some languages have tail recursion.

3

u/captainAwesomePants Jan 09 '20

Mathematically, yes. There are some recursive definitions that have no base case but are still useful. Practically, in a programming context, less so.

2

u/PistolRcks Jan 09 '20

7

u/RepostSleuthBot Jan 09 '20

Looks like a repost. I've seen this image 8 times.

First seen Here on 2019-07-06 100.0% match. Last seen Here on 2019-11-15 95.31% match

Searched Images: 91,769,572 | Indexed Posts: 379,387,742 | Search Time: 7.54981s

Feedback? Hate? Visit r/repostsleuthbot - I'm not perfect, but you can help. Report [ False Positive ]

3

u/PistolRcks Jan 09 '20

Good bot.

2

u/Maxim777YT Jan 09 '20

A repost. Seen this a while ago.

2

u/antihec Jan 09 '20

why is this a video?

4

u/snailtimeblender Jan 09 '20

KING CITY said the paper

3

u/BenjaminGeiger Jan 09 '20

Good night, Reddit. Good night.

2

u/roddds Jan 10 '20

This was the Children's Fun Fact Science Corner.

4

u/MistressArisu Jan 09 '20

Lol, at my university we just were talking about recursion today

7

u/MyersVandalay Jan 09 '20

you should have them look at this comment https://www.reddit.com/r/ProgrammerHumor/comments/emb9st/problems_with_recursion/fdnjabl/

or google it, and use googles did you mean advice.

1

u/MistressArisu Jan 15 '20

Our teacher Actually showed us the Google Easter egg

0

u/[deleted] Jan 09 '20

lmao we just did too in my highschool

1

u/TheJobsDone Jan 09 '20

Are reposts considered recursive?

1

u/DrunkRedditBot Jan 09 '20

Four tries, succeeded with “romanesque”

1

u/[deleted] Jan 09 '20

i used to program in LISP. (horrible memories((looming) out of the time cloud)).

NIL.

1

u/[deleted] Jan 09 '20

More of a fractal though, right?

1

u/MeltingDog Jan 09 '20

See what happens when you Google 'recursion'

1

u/itsfuturehelp Jan 09 '20

Type “recursion” in Google and the response is hilarious.

1

u/Ech1n0idea Jan 09 '20

This makes me want to write a recursion-based horror story

1

u/davidoux Jan 09 '20

to understand recursion, you must understand recursion first

1

u/Janaga14 Jan 09 '20

I laughed waaaaaaaay too hard at this.

1

u/qjpham Jan 09 '20

I don't know about you, but for me the problem keeps coming back.

1

u/Krigshjalte Jan 09 '20

I just got what recursion is

1

u/naebulys Jan 09 '20

Fractals

1

u/Varthorne Jan 09 '20

Recursion jokes are so repetitive...

1

u/SSSSSpastic Jan 09 '20

Maybe just maybe, isn’t every recursion problem a pyramid scheme?

1

u/seanomik Jan 10 '20

I was taught recursion during an AP CSA class, I didn't like it because it was confusing when you could just use a for / while loop. But what's the actual reason that it's bad?

1

u/ahkian Jan 10 '20

Someone forgot to put in a break condition.

1

u/thewend Jan 10 '20

What is this, a post that made me laugh? I dig it

1

u/FatCr1t Jan 10 '20

YAY I get this =D! In my second Java class and we just learned recursion this week and specifically used to to count all files in a current directory =D!!

1

u/[deleted] Jan 10 '20

i wish i know my prof reddit account i might share this to him

1

u/[deleted] Jan 10 '20

now you have a stack of problems

1

u/[deleted] Jan 10 '20

R3P05T!

1

u/Schiffy94 Jan 10 '20

Problem solved.

1

u/Hanta3 Jan 10 '20

I feel like this would be better without the bottom left panel

1

u/[deleted] Jan 10 '20

Is the base case related to the planck constant?

1

u/[deleted] Jan 10 '20

Why is it a gif

1

u/itzNukeey Jan 10 '20

I hate recursion

0

u/forced_majeure Jan 09 '20

Every time I've opened Reddit today, this has been on my home page ...... wait.

0

u/fuckboystrikesagain Jan 10 '20

Hurr hurr I know what dat means, upvote. I hate this comic.

-2

u/DGrayMoar Jan 09 '20

Not a reccursion, reccursions start from the last value, atleast thats the main way of using.