in Algorithms
504 views
2 votes
2 votes

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)$.

in Algorithms
504 views

2 Answers

0 votes
0 votes
g(3,7)=3

g(345,1)=5341

g(345,4)=5341

g(345,0)=345

2 Comments

@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
0
yes

me too
0
0
0 votes
0 votes

Answer:

Related questions