in reply to Lottery combinations golf

This problem is covered in elementary statistics first year university. The number of combinations can be calculated with the following formula:
X N = C Y
Which stands for give me the number of combinations by picking Y items from a total of X number of items. The mathematical expansion of the above formula becomes:
X X(x) * X(x-1) * ... * X(y+1) N = C = ---------------------------- Y 1 * 2 * ... (x - y)
To pick 6 numbers from 7 numbers = 7C6 = 7/1 = 7 possible ways.

To pick 6 numbers from 8 numbers = 8C6 = 8*7/1*2 = 28.

To pick 6 numbers from 9 numbers = 9C6 = 9*8*7/1*2*3 = 84.

The perl for calculating the number of combinations is thus:
use strict; sub xCy() { my ($x, $y) = @_; return(0) if $x < $y; # can not pick more number than given return(1) if $x == $y; # 1 combination if X = Y my $diff = $x - $y; my $n = 1; for (0 .. $diff-1) { $n *= $x - $_ } my $m = 1; for (1 .. $diff) { $m *= $_ } return $n / $m; } printf "%d\n", &xCy($_, 6) for 7 .. 10; __END__ 7 28 84 210