Last active
February 8, 2019 05:53
-
-
Save kedarmhaswade/c9b9b02ea4d93aa6bab9587bbea03092 to your computer and use it in GitHub Desktop.
A simple, but mysterious function
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// This is simply some pseudo code; applicable to any programming language that has support for | |
// basic data types and recursive functions | |
// Two questions: | |
// 1- Solve the "mystery": what does the function do? | |
// 2- Enhance the function to accommodate other integers. | |
function mystery(int a, int b) { | |
if (b == 1) { | |
return a | |
} | |
return mystery(a, b - 1) + a | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
It is a function that shows multiplication by repeated addition.