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

asked in Algorithms by Veteran (96.1k points) | 68 views

1 Answer

0 votes
g(3,7)=3

g(345,1)=5341

g(345,4)=5341

g(345,0)=345
answered by Veteran (111k 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,541 questions
54,083 answers
187,206 comments
70,992 users