The Gateway to Computer Science Excellence
First time here? Checkout the FAQ!
x
+2 votes
69 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)$.

in Algorithms by Veteran (98.3k points) | 69 views

1 Answer

0 votes
g(3,7)=3

g(345,1)=5341

g(345,4)=5341

g(345,0)=345
by Veteran (113k points)
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

Related questions

Quick search syntax
tags tag:apple
author user:martin
title title:apple
content content:apple
exclude -tag:apple
force match +apple
views views:100
score score:10
answers answers:2
is accepted isaccepted:true
is closed isclosed:true
49,807 questions
54,712 answers
189,259 comments
79,691 users