SlideShare a Scribd company logo
1 of 37
Perlでおねえさんを
                           救った話
   Perl saved a lady
     2012.9.28 @hiratara
I’m a reporter of gihyo.jp
I heard a rumor
that a lady is in
    trouble.
“フカシギ”のおねえさん
  She’s in trouble.
She can’t
answer a
question.
The question seems easy :)
Combinatorial
 explosion
For 10 by 10,
it takes 250,000 years
“Teacheeeeeeer!!!!!”
“Teacheeeeeeer!!!!!”
I wish
 to help her!!!!
Look
   the FreakOut Sticker.
50ms,
or
die
Speed up
   computation
Counting ways with perl


 ZBDD speeds up counting

 Knuth introduced simpath algorithm

 I implemented Algorithm::Simpath
Count ways in 9 by 9
6 years
use   strict;
use   warnings;
use   Algorithm::Simpath;
use   Algorithm::Simpath::GridMaker;

my $edges = create_edges(9, 9);
my $zdd = solve(
    start => '0,0',
    goal => "9,9",
    edges => $edges,
);
print $zdd->count, "n";
% time perl -Ilib teacher99.pl
4.10442087026325e+19
perl -Ilib teacher99.pl 115.88s user 0.69s
system 99% cpu 1:56.70 total
% time perl -Ilib teacher99.pl
4.10442087026325e+19
perl -Ilib teacher99.pl 115.88s user 0.69s
system 99% cpu 1:56.70 total
1,630,000
   times
Algorithm
example: 1 by 2

 s



            g
Out of 2^7 patterns,
     how many answers are there?
 s            s       s       s



          g       g       g       g

 s            s       s       s



          g       g       g       g

 s            s       s       s



          g       g       g       g
Out of 2^7 patterns,
     how many answers are there?
 s            s       s       s



          g       g       g       g

 s            s       s       s



          g       g       g       g

 s            s       s       s



          g       g       g       g
Number each edge

      2       5

  1       4       7


      3       6
    my %mate = %{$node->{mate}};
    my $next_grid_node = $grid_edge->[1];



               Binary Decision diagram
    $mate{$next_grid_node} = $next_grid_node unless exists $mate{$next_grid_node};

    {mate => %mate};
}

sub high_node($$) {                                          1
    my ($node, $grid_edge) = @_;
   s
       2
    my %mate = %{$node->{mate}};
  1                                           2                         2
    my @grid_nodes;
        3               g
    # loop detection
    return undef if ($mate{$grid_edge->[0]} / '') eq $grid_edge->[1];
                                             /
                            3                3
    for my $grid_node ($grid_edge->[0], $grid_edge->[1]) {
                                                                        3            3
        if (! exists $mate{$grid_node}) {
            push @grid_nodes, $grid_node; # That's the new grid node
        } elsif (! defined $mate{$grid_node}) { # Have already connected :/
            return undef;
        } else {
           4              4              4
            push @grid_nodes, $mate{$grid_node};
                                                     4
            $mate{$grid_node} = undef; # Connect to new grid node
                                                                 4           4       4   4
        }
    }

    $mate{$grid_nodes[0]} = $grid_nodes[1];
    $mate{$grid_nodes[1]} = $grid_nodes[0];
                                              ・・・・・・
    {mate => %mate};
            # delete mate which isn't frontier
            my $child_node = sub {
                my $new_node = shift;


                         Pruning trees
                defined $new_node or return undef;

                my $new_mate = $new_node->{mate};
                for (@done_grid_nodes) {
                    if ($_ eq $start || $_ eq $goal) {
                        return undef unless defined $new_mate->{$_} &&
                                            $new_mate->{$_} ne $_;
                    } elsif (defined $new_mate->{$_} &&
                        $new_mate->{$_} ne $_
                    ) {
               Stop computing if it will be impossible
                        return undef; # won't be connected forever
                    }
                  if 2 ways intersect
                    delete $new_node->{mate}{$_};
                }
                  if a node becomes a dead end
                return 1 if has_one_route $new_node, $start => $goal;

                $next_nodes_map{node_id $new_node} / $new_node;
                                                       /=
            };
            $node->{low} = $child_node->($low_node);
            $node->{high} = $child_node->($high_node);
BDD
                                    1
s
    2
1                           2               2
    3       g

                    3       3               3       3


        4       4       4       4       4       4   4   4

                            ・・・・・・
sub node_id($) {
                         Sharing trees
    my $node = shift;
    my $mate = $node->{mate};
    join "t", map {"$_-" . ($mate->{$_} / '')} sort keys %$mate;
                                          /
}

...
    my @active_nodes = ($top_node);
    for my $grid_edge (@grid_edges) { are connected
               Track how nodes
...
        my %next_nodes_map;
               Share 2 trees if{ they have same status
        for my $node (@active_nodes)
                                                                    of
               connections
            $next_nodes_map{node_id $new_node} / $new_node;
                                                /=
        };
...
    };
x is connected with y
                     in both diagram


    x    2   y       5           x   2   y       5

1                4       7   1               4       7


         3           6               3           6
Sharing
   the result of computation
                         1

                 2               2

         3       3               3       3


 4   4       4       4       4       4   4   4


     5                   5
Originally
we must have
2^5=16 patterns.
Now we have
only 2 patterns.
surprising
 compressibility
I’m not afraid of 不可思議.


    ※ 1不可思議 =
    1000000000000000000000
    0000000000000000000000
    000000000000000000000
Conclusion


Perl mongers had better help ladies!

Combinatorial explosion is bother.

Good algorithms are very important.
My implementation
https://github.com/hiratara/p5-Simpath

Reference
http://shogo82148.github.com/letscount/

More Related Content

What's hot

Magicke metody v Pythonu
Magicke metody v PythonuMagicke metody v Pythonu
Magicke metody v Pythonu
Jirka Vejrazka
 
Doctrator Symfony Live 2011 San Francisco
Doctrator Symfony Live 2011 San FranciscoDoctrator Symfony Live 2011 San Francisco
Doctrator Symfony Live 2011 San Francisco
pablodip
 
how to hack with pack and unpack
how to hack with pack and unpackhow to hack with pack and unpack
how to hack with pack and unpack
David Lowe
 

What's hot (20)

Fnt Software Solutions Pvt Ltd Placement Papers - PHP Technology
Fnt Software Solutions Pvt Ltd Placement Papers - PHP TechnologyFnt Software Solutions Pvt Ltd Placement Papers - PHP Technology
Fnt Software Solutions Pvt Ltd Placement Papers - PHP Technology
 
Pim Elshoff "Technically DDD"
Pim Elshoff "Technically DDD"Pim Elshoff "Technically DDD"
Pim Elshoff "Technically DDD"
 
Creating a compiler in Perl 6
Creating a compiler in Perl 6Creating a compiler in Perl 6
Creating a compiler in Perl 6
 
PHP and MySQL
PHP and MySQLPHP and MySQL
PHP and MySQL
 
Magicke metody v Pythonu
Magicke metody v PythonuMagicke metody v Pythonu
Magicke metody v Pythonu
 
TerminalでTwitter
TerminalでTwitterTerminalでTwitter
TerminalでTwitter
 
Difference between mysql_fetch_array and mysql_fetch_assoc in PHP
Difference between mysql_fetch_array and mysql_fetch_assoc in PHPDifference between mysql_fetch_array and mysql_fetch_assoc in PHP
Difference between mysql_fetch_array and mysql_fetch_assoc in PHP
 
Php & my sql
Php & my sqlPhp & my sql
Php & my sql
 
Introdução ao Perl 6
Introdução ao Perl 6Introdução ao Perl 6
Introdução ao Perl 6
 
Mythread.h
Mythread.hMythread.h
Mythread.h
 
Wx::Perl::Smart
Wx::Perl::SmartWx::Perl::Smart
Wx::Perl::Smart
 
PHP Benelux 2012: Magic behind the numbers. Software metrics in practice
PHP Benelux 2012: Magic behind the numbers. Software metrics in practice PHP Benelux 2012: Magic behind the numbers. Software metrics in practice
PHP Benelux 2012: Magic behind the numbers. Software metrics in practice
 
OOP Is More Then Cars and Dogs - Midwest PHP 2017
OOP Is More Then Cars and Dogs - Midwest PHP 2017OOP Is More Then Cars and Dogs - Midwest PHP 2017
OOP Is More Then Cars and Dogs - Midwest PHP 2017
 
Bouncingballs sh
Bouncingballs shBouncingballs sh
Bouncingballs sh
 
Doctrator Symfony Live 2011 San Francisco
Doctrator Symfony Live 2011 San FranciscoDoctrator Symfony Live 2011 San Francisco
Doctrator Symfony Live 2011 San Francisco
 
Internationalizing CakePHP Applications
Internationalizing CakePHP ApplicationsInternationalizing CakePHP Applications
Internationalizing CakePHP Applications
 
how to hack with pack and unpack
how to hack with pack and unpackhow to hack with pack and unpack
how to hack with pack and unpack
 
Python dictionary : past, present, future
Python dictionary: past, present, futurePython dictionary: past, present, future
Python dictionary : past, present, future
 
Ruby Topic Maps Tutorial (2007-10-10)
Ruby Topic Maps Tutorial (2007-10-10)Ruby Topic Maps Tutorial (2007-10-10)
Ruby Topic Maps Tutorial (2007-10-10)
 
CakeFest 2013 keynote
CakeFest 2013 keynoteCakeFest 2013 keynote
CakeFest 2013 keynote
 

Viewers also liked

Monads in python
Monads in pythonMonads in python
Monads in python
eldariof
 
Stateモナドの解説 後編
Stateモナドの解説 後編Stateモナドの解説 後編
Stateモナドの解説 後編
Masahiro Honma
 
Stateモナドの解説 中編
Stateモナドの解説 中編Stateモナドの解説 中編
Stateモナドの解説 中編
Masahiro Honma
 
Stateモナドの解説 前編
Stateモナドの解説 前編Stateモナドの解説 前編
Stateモナドの解説 前編
Masahiro Honma
 

Viewers also liked (20)

Hachioji.pm in Machida の LT
Hachioji.pm in Machida の LTHachioji.pm in Machida の LT
Hachioji.pm in Machida の LT
 
Monads in python
Monads in pythonMonads in python
Monads in python
 
カレーとHokkaidopm
カレーとHokkaidopmカレーとHokkaidopm
カレーとHokkaidopm
 
Types and perl language
Types and perl languageTypes and perl language
Types and perl language
 
定理3
定理3定理3
定理3
 
20120526 hachioji.pm
20120526 hachioji.pm20120526 hachioji.pm
20120526 hachioji.pm
 
Git入門
Git入門Git入門
Git入門
 
循環参照のはなし
循環参照のはなし循環参照のはなし
循環参照のはなし
 
TraitとMoose::Role
TraitとMoose::RoleTraitとMoose::Role
TraitとMoose::Role
 
Math::Category
Math::CategoryMath::Category
Math::Category
 
Stateモナドの解説 後編
Stateモナドの解説 後編Stateモナドの解説 後編
Stateモナドの解説 後編
 
モデルから知るGit
モデルから知るGitモデルから知るGit
モデルから知るGit
 
モナモナ言うモナド入門.tar.gz
モナモナ言うモナド入門.tar.gzモナモナ言うモナド入門.tar.gz
モナモナ言うモナド入門.tar.gz
 
Stateモナドの解説 中編
Stateモナドの解説 中編Stateモナドの解説 中編
Stateモナドの解説 中編
 
Stateモナドの解説 前編
Stateモナドの解説 前編Stateモナドの解説 前編
Stateモナドの解説 前編
 
レンズ (ぶつかり稽古の没プレゼン)
レンズ (ぶつかり稽古の没プレゼン)レンズ (ぶつかり稽古の没プレゼン)
レンズ (ぶつかり稽古の没プレゼン)
 
ウヰスキーとPSGI
ウヰスキーとPSGIウヰスキーとPSGI
ウヰスキーとPSGI
 
すべてが@__kanになる
すべてが@__kanになるすべてが@__kanになる
すべてが@__kanになる
 
Arrows in perl
Arrows in perlArrows in perl
Arrows in perl
 
AnyEvent and Plack
AnyEvent and PlackAnyEvent and Plack
AnyEvent and Plack
 

Similar to Perl saved a lady.

Perl Intro 7 Subroutines
Perl Intro 7 SubroutinesPerl Intro 7 Subroutines
Perl Intro 7 Subroutines
Shaun Griffith
 
Good Evils In Perl (Yapc Asia)
Good Evils In Perl (Yapc Asia)Good Evils In Perl (Yapc Asia)
Good Evils In Perl (Yapc Asia)
Kang-min Liu
 
Good Evils In Perl
Good Evils In PerlGood Evils In Perl
Good Evils In Perl
Kang-min Liu
 
Ruby: OOP, metaprogramming, blocks, iterators, mix-ins, duck typing. Code style
Ruby: OOP, metaprogramming, blocks, iterators, mix-ins, duck typing. Code styleRuby: OOP, metaprogramming, blocks, iterators, mix-ins, duck typing. Code style
Ruby: OOP, metaprogramming, blocks, iterators, mix-ins, duck typing. Code style
Anton Shemerey
 
Benchmarking Perl Lightning Talk (NPW 2007)
Benchmarking Perl Lightning Talk (NPW 2007)Benchmarking Perl Lightning Talk (NPW 2007)
Benchmarking Perl Lightning Talk (NPW 2007)
brian d foy
 

Similar to Perl saved a lady. (20)

Perl Intro 7 Subroutines
Perl Intro 7 SubroutinesPerl Intro 7 Subroutines
Perl Intro 7 Subroutines
 
Good Evils In Perl (Yapc Asia)
Good Evils In Perl (Yapc Asia)Good Evils In Perl (Yapc Asia)
Good Evils In Perl (Yapc Asia)
 
Good Evils In Perl
Good Evils In PerlGood Evils In Perl
Good Evils In Perl
 
Learning Perl 6 (NPW 2007)
Learning Perl 6 (NPW 2007)Learning Perl 6 (NPW 2007)
Learning Perl 6 (NPW 2007)
 
Ruby: OOP, metaprogramming, blocks, iterators, mix-ins, duck typing. Code style
Ruby: OOP, metaprogramming, blocks, iterators, mix-ins, duck typing. Code styleRuby: OOP, metaprogramming, blocks, iterators, mix-ins, duck typing. Code style
Ruby: OOP, metaprogramming, blocks, iterators, mix-ins, duck typing. Code style
 
Simple Photo Processing and Web Display with Perl
Simple Photo Processing and Web Display with PerlSimple Photo Processing and Web Display with Perl
Simple Photo Processing and Web Display with Perl
 
Adventures in Optimization
Adventures in OptimizationAdventures in Optimization
Adventures in Optimization
 
Object::Franger: Wear a Raincoat in your Code
Object::Franger: Wear a Raincoat in your CodeObject::Franger: Wear a Raincoat in your Code
Object::Franger: Wear a Raincoat in your Code
 
Learning Perl 6
Learning Perl 6 Learning Perl 6
Learning Perl 6
 
Method::Signatures
Method::SignaturesMethod::Signatures
Method::Signatures
 
Perl6 a whistle stop tour
Perl6 a whistle stop tourPerl6 a whistle stop tour
Perl6 a whistle stop tour
 
Perl6 a whistle stop tour
Perl6 a whistle stop tourPerl6 a whistle stop tour
Perl6 a whistle stop tour
 
PHP Tips & Tricks
PHP Tips & TricksPHP Tips & Tricks
PHP Tips & Tricks
 
Simple Ways To Be A Better Programmer (OSCON 2007)
Simple Ways To Be A Better Programmer (OSCON 2007)Simple Ways To Be A Better Programmer (OSCON 2007)
Simple Ways To Be A Better Programmer (OSCON 2007)
 
mro-every.pdf
mro-every.pdfmro-every.pdf
mro-every.pdf
 
Bag of tricks
Bag of tricksBag of tricks
Bag of tricks
 
Neatly folding-a-tree
Neatly folding-a-treeNeatly folding-a-tree
Neatly folding-a-tree
 
Benchmarking Perl Lightning Talk (NPW 2007)
Benchmarking Perl Lightning Talk (NPW 2007)Benchmarking Perl Lightning Talk (NPW 2007)
Benchmarking Perl Lightning Talk (NPW 2007)
 
Random. Kinda.
Random. Kinda.Random. Kinda.
Random. Kinda.
 
Functional Pe(a)rls version 2
Functional Pe(a)rls version 2Functional Pe(a)rls version 2
Functional Pe(a)rls version 2
 

Recently uploaded

+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
?#DUbAI#??##{{(☎️+971_581248768%)**%*]'#abortion pills for sale in dubai@
 

Recently uploaded (20)

Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
 
CNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In PakistanCNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In Pakistan
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
Cyberprint. Dark Pink Apt Group [EN].pdf
Cyberprint. Dark Pink Apt Group [EN].pdfCyberprint. Dark Pink Apt Group [EN].pdf
Cyberprint. Dark Pink Apt Group [EN].pdf
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectors
 
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Spring Boot vs Quarkus the ultimate battle - DevoxxUK
Spring Boot vs Quarkus the ultimate battle - DevoxxUKSpring Boot vs Quarkus the ultimate battle - DevoxxUK
Spring Boot vs Quarkus the ultimate battle - DevoxxUK
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024
 
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamDEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
 

Perl saved a lady.

  • 1. Perlでおねえさんを 救った話 Perl saved a lady 2012.9.28 @hiratara
  • 2. I’m a reporter of gihyo.jp
  • 3. I heard a rumor that a lady is in trouble.
  • 8. For 10 by 10, it takes 250,000 years
  • 11. I wish to help her!!!!
  • 12. Look the FreakOut Sticker.
  • 14. Speed up computation
  • 15. Counting ways with perl ZBDD speeds up counting Knuth introduced simpath algorithm I implemented Algorithm::Simpath
  • 16. Count ways in 9 by 9
  • 18. use strict; use warnings; use Algorithm::Simpath; use Algorithm::Simpath::GridMaker; my $edges = create_edges(9, 9); my $zdd = solve( start => '0,0', goal => "9,9", edges => $edges, ); print $zdd->count, "n";
  • 19. % time perl -Ilib teacher99.pl 4.10442087026325e+19 perl -Ilib teacher99.pl 115.88s user 0.69s system 99% cpu 1:56.70 total
  • 20. % time perl -Ilib teacher99.pl 4.10442087026325e+19 perl -Ilib teacher99.pl 115.88s user 0.69s system 99% cpu 1:56.70 total
  • 21. 1,630,000 times
  • 23. example: 1 by 2 s g
  • 24. Out of 2^7 patterns, how many answers are there? s s s s g g g g s s s s g g g g s s s s g g g g
  • 25. Out of 2^7 patterns, how many answers are there? s s s s g g g g s s s s g g g g s s s s g g g g
  • 26. Number each edge 2 5 1 4 7 3 6
  • 27.     my %mate = %{$node->{mate}};     my $next_grid_node = $grid_edge->[1]; Binary Decision diagram     $mate{$next_grid_node} = $next_grid_node unless exists $mate{$next_grid_node};     {mate => %mate}; } sub high_node($$) { 1     my ($node, $grid_edge) = @_; s 2     my %mate = %{$node->{mate}}; 1 2 2     my @grid_nodes; 3 g     # loop detection     return undef if ($mate{$grid_edge->[0]} / '') eq $grid_edge->[1]; / 3 3     for my $grid_node ($grid_edge->[0], $grid_edge->[1]) { 3 3         if (! exists $mate{$grid_node}) {             push @grid_nodes, $grid_node; # That's the new grid node         } elsif (! defined $mate{$grid_node}) { # Have already connected :/             return undef;         } else { 4 4 4             push @grid_nodes, $mate{$grid_node}; 4             $mate{$grid_node} = undef; # Connect to new grid node 4 4 4 4         }     }     $mate{$grid_nodes[0]} = $grid_nodes[1];     $mate{$grid_nodes[1]} = $grid_nodes[0]; ・・・・・・     {mate => %mate};
  • 28.             # delete mate which isn't frontier             my $child_node = sub {                 my $new_node = shift; Pruning trees                 defined $new_node or return undef;                 my $new_mate = $new_node->{mate};                 for (@done_grid_nodes) {                     if ($_ eq $start || $_ eq $goal) {                         return undef unless defined $new_mate->{$_} &&                                             $new_mate->{$_} ne $_;                     } elsif (defined $new_mate->{$_} &&                         $new_mate->{$_} ne $_                     ) { Stop computing if it will be impossible                         return undef; # won't be connected forever                     } if 2 ways intersect                     delete $new_node->{mate}{$_};                 } if a node becomes a dead end                 return 1 if has_one_route $new_node, $start => $goal;                 $next_nodes_map{node_id $new_node} / $new_node; /=             };             $node->{low} = $child_node->($low_node);             $node->{high} = $child_node->($high_node);
  • 29. BDD 1 s 2 1 2 2 3 g 3 3 3 3 4 4 4 4 4 4 4 4 ・・・・・・
  • 30. sub node_id($) { Sharing trees     my $node = shift;     my $mate = $node->{mate};     join "t", map {"$_-" . ($mate->{$_} / '')} sort keys %$mate; / } ...     my @active_nodes = ($top_node);     for my $grid_edge (@grid_edges) { are connected Track how nodes ...         my %next_nodes_map; Share 2 trees if{ they have same status         for my $node (@active_nodes) of connections             $next_nodes_map{node_id $new_node} / $new_node; /=         }; ...     };
  • 31. x is connected with y in both diagram x 2 y 5 x 2 y 5 1 4 7 1 4 7 3 6 3 6
  • 32. Sharing the result of computation 1 2 2 3 3 3 3 4 4 4 4 4 4 4 4 5 5
  • 33. Originally we must have 2^5=16 patterns. Now we have only 2 patterns.
  • 35. I’m not afraid of 不可思議. ※ 1不可思議 = 1000000000000000000000 0000000000000000000000 000000000000000000000
  • 36. Conclusion Perl mongers had better help ladies! Combinatorial explosion is bother. Good algorithms are very important.

Editor's Notes

  1. \n
  2. \n
  3. \n
  4. \n
  5. \n
  6. \n
  7. \n
  8. \n
  9. \n
  10. \n
  11. \n
  12. \n
  13. \n
  14. \n
  15. \n
  16. \n
  17. \n
  18. \n
  19. \n
  20. \n
  21. \n
  22. \n
  23. \n
  24. \n
  25. \n
  26. \n
  27. \n
  28. \n
  29. \n
  30. \n
  31. \n
  32. \n
  33. \n
  34. \n
  35. \n
  36. \n