ç´ç©ã®å°åºã¨èãããå ¨ã¦ã®å¤ãç¶²ç¾ ããããã·ã¥ã®çæ
æ¨æ¥ããæ¿ããæ©ãã§ããå 容ã§ãid:kazuhookuããã¨nishioããã«è²ã æãã£ãã®ã§ããã®å 容ã®ã¾ã¨ãã
ããããäº
my $entries = { A => [0..5], B => ["A".."D"], C => ["a".."c"] };
ã¿ãããªéåA, B, Cã£ã¦ã®ãããã¨ãã¦ãA, B, Cããä¸åãã¤å¤ãæ½åºãã¦ããçµåããåæããã¨è¨ãã話ã
ã¡ãªã¿ã«å ´åã®æ°ã¨ãã¦ã6 * 4 * 3 = 72 éãåå¨ããããºã§ãã
List::Utilã®reduceã使ã
id:kazuhookuããæ¡ãé©å½ã«æ´å½¢ã
#!/usr/bin/perl use strict; use warnings; use Data::Dump qw(dump); use List::Util qw(reduce); my $entries = { A => [0..5], B => ["A".."D"], C => ["a".."c"] }; { no warnings; my $j = reduce { [map { my $x = $_; map { (ref $x eq "ARRAY") ? [@$x, $_] : [$x, $_] } @$b; } @$a] } values %$entries; print dump(@$j); }
Set::CrossProductã使ãã
CrossProductã¯æ°å¦ã§ã¯ãç´ç©ãã¨è¨ãã¨nishioããã«æãã¦è²°ãã¾ããã
#!/usr/bin/perl use strict; use warnings; use Data::Dump qw(dump); use Set::CrossProduct; my $entries = { A => [0..5], B => ["A".."D"], C => ["a".."c"] }; my $cp = Set::CrossProduct->new([values %$entries]); print dump($cp->combinations);
ããã§åæãããã§ãã
ã§ãä½ã«ä½¿ãã®ã
ãã¹ãç¨ã®ãã¼ã¿ã®çµåããã´ãªã´ãªä½ãããã¨ãã£ã¦æã«ä¾¿å©ã ã£ãããã¾ãã
ä¾ãã°ãããªæãã
#!/usr/bin/perl use strict; use warnings; use Data::Dump qw(dump); use DateTime; use DateTime::Duration; use DateTime::Format::HTTP; use Set::CrossProduct; use Text::SimpleTable; my $date = DateTime::Format::HTTP->format_datetime(DateTime->now - DateTime::Duration->new(minutes => 30)); my $entries = { 'Cache-Control' => [q|max-age=0|, q|max-age=300|, undef], 'If-None-Match' => [q|"1111"|, q|"2222"|, undef], 'If-Modified-Since' => [$date, undef] }; my $cp = Set::CrossProduct->new([values %$entries]); my @headers = (); for my $header_vals ($cp->combinations) { my %header; @header{keys %$entries} = @$header_vals; push(@headers, \%header); } my $table = Text::SimpleTable->new([20, "Cache-Control"], [20, "If-None-Match"], [20, "If-Modified-Since"]); for (@headers) { $table->row(values %$_); } print $table->draw;
ã§ãå®è¡çµæã
.----------------------+----------------------+----------------------. | Cache-Control | If-None-Match | If-Modified-Since | +----------------------+----------------------+----------------------+ | max-age=0 | "1111" | Tue, 14 Aug 2007 07- | | | | :01:57 GMT | | max-age=0 | "2222" | Tue, 14 Aug 2007 07- | | | | :01:57 GMT | | max-age=0 | | Tue, 14 Aug 2007 07- | | | | :01:57 GMT | | max-age=0 | "1111" | | | max-age=0 | "2222" | | | max-age=0 | | | | max-age=300 | "1111" | Tue, 14 Aug 2007 07- | | | | :01:57 GMT | | max-age=300 | "2222" | Tue, 14 Aug 2007 07- | | | | :01:57 GMT | | max-age=300 | | Tue, 14 Aug 2007 07- | | | | :01:57 GMT | | max-age=300 | "1111" | | | max-age=300 | "2222" | | | max-age=300 | | | | | "1111" | Tue, 14 Aug 2007 07- | | | | :01:57 GMT | | | "2222" | Tue, 14 Aug 2007 07- | | | | :01:57 GMT | | | | Tue, 14 Aug 2007 07- | | | | :01:57 GMT | | | "1111" | | | | "2222" | | '----------------------+----------------------+----------------------'
ãã®ä»
ãã®éç¨ã§ã ãã¶å¯ãéãã¦è¦ã¤ãã¦é¢ç½ãã£ãã¢ã¸ã¥ã¼ã«ã
Math::Combinatorics
é åãçµåããéè¤çµåããªã©ä½¿ãããå ´åã¯ãã¡ãã使ãã¨è¯ãã§ãã
ãã¨ã½ã¼ã¹ã¨çµæã¯ã¡ãã£ã¨ç´ãã¾ããã