Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- C++:
- #include <iostream>
- using namespace std;
- int combs(int rem, int open = 0) {
- // Base case
- if (rem + open == 0) {
- return 1;
- }
- // Recursive part
- int count = 0;
- if (rem > 0) {
- count += combs(rem-1, open+1);
- }
- if (open > 0) {
- count += combs(rem, open-1);
- }
- return count;
- }
- int main(int argc, char** argv) {
- cout << combs(13) << endl;
- }
- Haskell:
- combs :: Int -> Int -> Int
- combs rem open
- | rem + open == 0 = 1
- | rem > 0 && open > 0 = (combs (rem-1) (open+1)) + (combs rem (open-1))
- | rem > 0 = combs (rem-1) (open+1)
- | open > 0 = combs rem (open-1)
- main = do
- putStrLn $ show $ combs 13 0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement