Can someone briefly or clearly explain the logic in this code
if I want this function interlaceDigits(1357, 2468) prints 12345678
the code would be
|
return 100 * interlaceDigits(x / 10, y / 10) + 10 * (x % 10) + y % 10;
|
here is the part I want to know. If you can draw me a picture. That is even better.
as same as
1 2
|
gce(1357, 13657) prints 57
return 10 * gce(x / 10, y / 10) + x % 10;
|
I can't draw a picture to see what is being returned.
Thank you.
Last edited on
You have recursive functions.
You do show only one line of the functions. That cannot be the entire function.
We cannot "draw" without full code. We can only guess:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
|
gce( 1357, 13657 )
=
10 * gce( 1357 / 10, 13657 / 10 ) + 1357 % 10
=
10 * gce( 135, 1365 ) + 7
gce( 135, 1365 )
=
10 * gce( 135 / 10, 1365 / 10 ) + 135 % 10
=
10 * gce( 13, 136 ) + 5
gce( 1357, 13657 )
=
10 * (10 * gce( 13, 136 ) + 5) + 7
=
100 * gce( 13, 136 ) + 10 * 5 + 7
=
...
|
Topic archived. No new replies allowed.