Article View: pl.comp.lang.perl
Article #52582Re: Generowanie wszystkich mozliwosci totolotka
From: Cezary Grądys
Date: Mon, 20 Feb 2017 10:23
Date: Mon, 20 Feb 2017 10:23
35 lines
2035 bytes
2035 bytes
W dniu 20.02.2017 o 10:49, Cezary Grądys pisze:
> Witam.
> Chciałbym wygenerować wszystkie możliwe zestawy liczb w totolotku.
> Pierwsze nieeleganckie podejście to 6 pętli for:
>
> ----------------------------------------------------------
>
> #!/usr/bin/perl
> use strict;
>
> for (my $a=6;$a<50;$a++) {
> for (my $b=5;$b<$a;$b++){
> for (my $c=4;$c<$b;$c++){
> for (my $d=3;$d<$c;$d++){
> for (my $e=2;$e<$d;$e++){
> for (my $f=1;$f<$e;$f++){
> print "$a\t$b\t$c\t$d\t$e\t$f\n";
> }
> }
> }
> }
> }
> }
> print "\n";
>
> -----------------------------------------------------------
>
> Mogło by tak zostać, ale totolotek to tylko przykład tu może się
> zmienić liczba tych pętli. Poszukuję bardziej ogólnego sposobu,
> tak, żeby łatwo wygenerować zestawy 5,6 czy 10 liczb.
>
Już sobie poszukałem, jak kogoś to interesuje multum przykładów w
różnych językach:
https://rosettacode.org/wiki/Combinations
Technical Details
Message-ID:
<58aac399$0$645$65785112@news.neostrada.pl>Path:
mbox-mo1.pugleaf.net!news-archive.icm.edu.pl!news.icm.edu.pl!newsfeed2.atman.pl!newsfeed.atman.pl!goblin2!goblin1!goblin.stu.neva.ru!newsfeed.neostrada.pl!unt-exc-01.news.neostrada.pl!unt-spo-a-02.news.neostrada.pl!news.neostrada.pl.POSTED!not-for-mailReferences:
<58aabbc5$0$5153$65785112@news.neostrada.pl>Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!news-archive.icm.edu.pl!news.icm.edu.pl!newsfeed2.atman.pl!newsfeed.atman.pl!goblin2!goblin1!goblin.stu.neva.ru!newsfeed.neostrada.pl!unt-exc-01.news.neostrada.pl!unt-spo-a-02.news.neostrada.pl!news.neostrada.pl.POSTED!not-for-mail Subject: Re: Generowanie wszystkich mozliwosci totolotka Newsgroups: pl.comp.lang.perl References: <58aabbc5$0$5153$65785112@news.neostrada.pl> From: Cezary Grądys <czarekgr@wa.onet.pl> Date: Mon, 20 Feb 2017 11:23:21 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.5.1 MIME-Version: 1.0 In-Reply-To: <58aabbc5$0$5153$65785112@news.neostrada.pl> Lines: 35 Message-ID: <58aac399$0$645$65785112@news.neostrada.pl> Organization: Telekomunikacja Polska NNTP-Posting-Host: 195.117.101.50 X-Trace: 1487586201 unt-rea-b-01.news.neostrada.pl 645 195.117.101.50:63773 X-Complaints-To: abuse@news.neostrada.pl Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit