Since there was just a golf for factorials, I figured that doing one for the number of ways to select M objects from a set of N objects without repetition might be appropriate.

Basically, if I have a set of 4 cards, how many ways can I select a hand of 1 card from the set without repeating myself? The answer is obviously 4. Now if I have a hand size of 2 how many ways are there? The answer is 6, but it is less obvious.

The general solution is defined by the function:

Choose(M, N) = M!
----------------
N! * (M - N)!

Where M is the size of the set and N is the number of cards to select. And M! is the factorial of M. See

Golf: Factorials for more info.

The following are test cases that you can use:

M N Answer Notes
52 5 2598960 Number of 5 card hands in a deck of 52 cards
52 7 133784560 Number of 7 card hands in a deck of 52 cards
52 13 635013559600 Number of 7 card hands in a deck of 52 cards
52 52 1 Number of ways to select a hand size of 1 from a 52 card deck

The interface for the resulting code should be:

print c($m, $n);

If you want to define a factorial subroutine that should be included in the size of the code.

-ben

Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags :
a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
For:
Use:
& &
< <
> >
[ [
] ]

Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.
Log In ^{?}

remember me
What's my password?
Create A New User
Chatterbox ^{?}

and the web crawler heard nothing...
How do I use this? | Other CB clients
Other Users ^{?}
Others about the Monastery: (4)As of 2015-08-30 23:11 GMT
Sections ^{?}
Information ^{?}
Find Nodes ^{?}
Leftovers ^{?}
Voting Booth ^{?}
The oldest computer book still on my shelves (or on my digital media) is ...

A Programming Language, 1962
Programming the 1900 series in COBOL, 1974
Algorithms + Data Structures = Programs, 1976
The C Programming Language, 1978
System V - Interface definition, 1986
Z80 Assembly Language Programming, 1979
TheSOURCE User's Manual, 1979
The C Primer, 1983
Interactive Fortran 77, A Hands on Approach, 1984
Turbo-Pascal, 1989
Perl.1 man page, 1991
Other

Results (351 votes) ,
past polls