combinations & permutation : how to generate a list of numbers

--0-659218252-1304608813=:93886
Content-Type: text/plain; charset=iso-8859-1
Content-Transfer-Encoding: quoted-printable

Hi, Concerning the game Lotto, how do I generate a list of 6 numbers out of=
12 =0Anumbers,=A0 eg =0A=0Agiven the 12 numbers as 1,2,3,4,5,6,7,8,9,10,11=
,12=0Athe list of 6 numbers goes like this :-=0A1,2,3,4,5,6=0A1,2,3,4,5,7=
=0A1,2,3,4,5,8=0A1,2,3,4,5,9=0A1,2,3,4,5,10 ......... etc etc....=0AThanks
--0-659218252-1304608813=:93886--
eventual [ Do, 05 Mai 2011 17:20 ] [ ID #2059158 ]

Re: combinations & permutation : how to generate a list of numbers

On Thu, May 05, 2011 at 08:20:13AM -0700, eventual wrote:
> Hi, Concerning the game Lotto, how do I generate a list of 6 numbers ou=
t of 12
> numbers,=A0 eg
>
> given the 12 numbers as 1,2,3,4,5,6,7,8,9,10,11,12
> the list of 6 numbers goes like this :-
> 1,2,3,4,5,6
> 1,2,3,4,5,7
> 1,2,3,4,5,8
> 1,2,3,4,5,9
> 1,2,3,4,5,10 ......... etc etc....
> Thanks

There appears to be a couple of modules on CPAN which can help you:

http://search.cpan.org/perldoc?Math::Combinatorics
http://search.cpan.org/perldoc?Algorithm::Combinatorics

And here's a little fun which uses the regexp engine to do the work for u=
s:

#!/usr/bin/perl
use 5.12.0;
use re "eval";
my $r =3D join ".*?", map qr/(?<a$_>\b\d+\b)/, 1..shift;
my $s =3D join " ", 1..shift;
my [at] c;
$s =3D~ /$r(?{push [at] c, [values %+]})(?!)/;
say join ",", sort { $a <=3D> $b } [at] $_ for [at] c;

Use it as:

$ perl comb 6 12

--
Paul Johnson - paul [at] pjcj.net
http://www.pjcj.net

--
To unsubscribe, e-mail: beginners-unsubscribe [at] perl.org
For additional commands, e-mail: beginners-help [at] perl.org
http://learn.perl.org/
Paul Johnson [ Do, 05 Mai 2011 18:43 ] [ ID #2059162 ]

Re: combinations & permutation : how to generate a list of numbers

--nextPart14048514.JSys1UyVga
Content-Type: text/plain;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
Content-Disposition: inline

Le jeudi 5 mai 2011 18:43, Paul Johnson a =E9crit=A0:
> On Thu, May 05, 2011 at 08:20:13AM -0700, eventual wrote:
> > Hi, Concerning the game Lotto, how do I generate a list of 6 numbers out
> > of 12 numbers,=A0 eg
> >
> > given the 12 numbers as 1,2,3,4,5,6,7,8,9,10,11,12
> > the list of 6 numbers goes like this :-
> > 1,2,3,4,5,6
> > 1,2,3,4,5,7
> > 1,2,3,4,5,8
> > 1,2,3,4,5,9
> > 1,2,3,4,5,10 ......... etc etc....
> > Thanks
>
> There appears to be a couple of modules on CPAN which can help you:
>
> http://search.cpan.org/perldoc?Math::Combinatorics
> http://search.cpan.org/perldoc?Algorithm::Combinatorics
>
> And here's a little fun which uses the regexp engine to do the work for u=
s:
>
> #!/usr/bin/perl
> use 5.12.0;
> use re "eval";
> my $r =3D join ".*?", map qr/(?<a$_>\b\d+\b)/, 1..shift;
> my $s =3D join " ", 1..shift;
> my [at] c;
> $s =3D~ /$r(?{push [at] c, [values %+]})(?!)/;
> say join ",", sort { $a <=3D> $b } [at] $_ for [at] c;
>
> Use it as:
>
> $ perl comb 6 12
>
> --
> Paul Johnson - paul [at] pjcj.net
> http://www.pjcj.net


you need a super calculateur or cluster to PS3 as to NASA
I calculated a series of 8 digits on a slice of 1 to 20 on a PS3 in 36 hour=
s
and the result is a series of number in the order of 28Go

=2D-
http://pgp.mit.edu:11371/pks/lookup?op=3Dget&search=3D0x0921 64A7
gpg --keyserver pgp.mit.edu --recv-key 092164A7

--nextPart14048514.JSys1UyVga
Content-Type: application/pgp-signature

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.5 (GNU/Linux)

iD8DBQBNwt4jtXI/OwkhZKcRAqJ2AKCD8rE3DGP0d9oGBjIKTspIsKLXJwCf WWTV
bo3BsjHZphj2YSJfrKGWKUs=
=fUJ9
-----END PGP SIGNATURE-----

--nextPart14048514.JSys1UyVga--
fakessh [ Do, 05 Mai 2011 19:27 ] [ ID #2059164 ]
Perl » gmane.comp.lang.perl.beginners » combinations & permutation : how to generate a list of numbers

Vorheriges Thema: how to redefing the default list seperator
Nächstes Thema: command formatting