As noted in the 2009 A MC explanations, this problem is more appropriately solved using the technique presented in recursive methods with print statements. The trace below is presented as a demonstration of tracing. It is not a suggestion that this problem should be traced.

This trace uses the technique demonstrated in tracing recursive methods. Familiarity with that material is assumed.

Step 1: initial call

Initial call stack

m(123456)

Step 2: mystery(123456)

Resulting call stack

m(12345)
m(123456)

Step 3: mystery(12345)

Resulting call stack

m(1234)
m(12345)
m(123456)

Step 4: mystery(1234)

Resulting call stack

m(123)
m(1234)
m(12345)
m(123456)

Step 5: mystery(123)

Resulting call stack

m(12)
m(123)
m(1234)
m(12345)
m(123456)

Step 6: mystery(12)

Resulting call stack

m(1)
m(12)
m(123)
m(1234)
m(12345)
m(123456)

Step 7: mystery(1)

Resulting call stack

m(1)  returns
m(12)
m(123)
m(1234)
m(12345)
m(123456)

Printed

1

Step 8: Back in mystery(12)

Resulting call stack

m(1)  returns
m(12)  returns
m(123)
m(1234)
m(12345)
m(123456)

Printed

12

Step 9: Back in mystery(123)

Resulting call stack

m(1)  returns
m(12)  returns
m(123)  returns
m(1234)
m(12345)
m(123456)

Printed

123

Step 10: Back in mystery(1234)

Resulting call stack

m(1)  returns
m(12)  returns
m(123)  returns
m(1234)  returns
m(12345)
m(123456)

Printed

1234

Step 11: Back in mystery(12345)

Resulting call stack

m(1)  returns
m(12)  returns
m(123)  returns
m(1234)  returns
m(12345)  returns
m(123456)

Printed

12345

Step 12: Back in mystery(123456)

Resulting call stack

m(1)  returns
m(12)  returns
m(123)  returns
m(1234)  returns
m(12345)  returns
m(123456)  returns

Printed

123456