6 kyu
Mutual Recursion
4,341 of 8,705dnolan
Description:
Mutual Recursion allows us to take the fun of regular recursion (where a function calls itself until a terminating condition) and apply it to multiple functions calling each other!
Let's use the Hofstadter Female and Male sequences to demonstrate this technique. You'll want to create two functions F
and M
such that the following equations are true:
F(0) = 1
M(0) = 0
F(n) = n - M(F(n - 1))
M(n) = n - F(M(n - 1))
Don't worry about negative numbers, n
will always be greater than or equal to zero.
Hofstadter Wikipedia Reference http://en.wikipedia.org/wiki/Hofstadter_sequence#Hofstadter_Female_and_Male_sequences
Mathematics
Algorithms
Recursion
Similar Kata:
Stats:
Created | Jun 18, 2014 |
Published | Jun 18, 2014 |
Warriors Trained | 14432 |
Total Skips | 744 |
Total Code Submissions | 18838 |
Total Times Completed | 8705 |
JavaScript Completions | 4341 |
TypeScript Completions | 214 |
C# Completions | 154 |
C++ Completions | 848 |
C Completions | 517 |
PHP Completions | 31 |
Python Completions | 2240 |
R Completions | 58 |
Ruby Completions | 140 |
NASM Completions | 39 |
Kotlin Completions | 213 |
Clojure Completions | 43 |
Haskell Completions | 57 |
Julia Completions | 48 |
CoffeeScript Completions | 18 |
Crystal Completions | 11 |
COBOL Completions | 4 |
λ Calculus Completions | 14 |
Go Completions | 85 |
Rust Completions | 80 |
OCaml Completions | 31 |
Prolog Completions | 10 |
Java Completions | 86 |
Total Stars | 164 |
% of votes with a positive feedback rating | 79% of 877 |
Total "Very Satisfied" Votes | 595 |
Total "Somewhat Satisfied" Votes | 201 |
Total "Not Satisfied" Votes | 81 |