68 views

Consider the code below, defining the functions $f$ and $g$:

f(m, n) {
if (m == 0) return n;
else {
q = m div 10;
r = m mod 10;
return f(q, 10*n + r);
}
}
g(m, n) {
if (n == 0) return m;
else {
q = m div 10;
r = m mod 10;
return g(f(f(q, 0), r), n-1);
}
}

Compute $g(3, 7), \: g(345, 1), \: g(345, 4) \text{ and } \: g(345, 0)$.

g(3,7)=3

g(345,1)=5341

g(345,4)=5341

g(345,0)=345
0

@Srestha ... How long it took you to ans this question, I am asking this because form me its at least 10 min.

How to solve this type of question in quick time. Any trick ..? If yes then please let me know.

First I thought of doing it for general case but it is taking very much time.

0
yes

me too

1
2