in reply to Lottery combinations golf

I've seen some posts about how to calculate the number of games being played, but not to illustrate it graphically, which is I think what you want. This does that. It's a little bit golfed, since that's what you asked for, but not too bad, so it's basically legible. The arguments to place are the number of remaining # characters to place, where to start placing, and then the list. It places a # in each of the remaining places, then calls itself recursively to place the remaining ones.
#!/usr/bin/perl $a = $ARGV[0]; place($a-6,0,(1..$a)); sub place { if ($_[0]) { for my $c ($_[1]+2..$#_) { place($_[0]-1,$c-2,@_[2..$c-1],'#',@_[$c+1..$#_]) unless $_[$c] eq '#'; } } else { print @_[2..$#_],"\n"; } }

Replies are listed 'Best First'.
Re: Re: Lottery combinations golf
by sgifford (Prior) on Oct 12, 2003 at 15:30 UTC
    This is a little golfier.
    #!/usr/bin/perl -l $a=shift;place($a-6,0,(1..$a));sub place{local$_;$_[0]||return print @ +_[2..$#_];$_[$_] ne'#'&&place($_[0]-1,$_-2,@_[2..$_-1],'#',@_[$_+1..$ +#_])for($_[1]+2..$#_)}