Skip to content

Instantly share code, notes, and snippets.

@kedarmhaswade
Last active February 8, 2019 05:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kedarmhaswade/c9b9b02ea4d93aa6bab9587bbea03092 to your computer and use it in GitHub Desktop.
Save kedarmhaswade/c9b9b02ea4d93aa6bab9587bbea03092 to your computer and use it in GitHub Desktop.
A simple, but mysterious function
// 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
}
@vapporwashmade
Copy link

It is a function that shows multiplication by repeated addition.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment