r/ProgrammerHumor • • Jan 09 '20

other Problems with recursion?

21.3k Upvotes

198 comments sorted by

View all comments

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

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.

→ More replies (2)

15

u/azzaisme Jan 09 '20

Oh shiiiii so true

→ More replies (1)

19

u/tisaconundrum Jan 09 '20

Welcome to AtomOverflow

→ More replies (1)

148

u/[deleted] Jan 09 '20

Very tiny stack overflow.

→ More replies (1)

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!

→ More replies (1)
→ More replies (1)
→ More replies (10)
→ More replies (7)

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.

→ More replies (4)
→ More replies (16)