From a3c164970c4e43cc71b5fe8bd1c4a3fb02a35709 Mon Sep 17 00:00:00 2001 From: E7-87-83 Date: Mon, 15 Nov 2021 06:17:56 +0800 Subject: commenting --- challenge-138/cheok-yin-fung/perl/ch-2.pl | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/challenge-138/cheok-yin-fung/perl/ch-2.pl b/challenge-138/cheok-yin-fung/perl/ch-2.pl index 3cf1916ec2..5c4d5c160d 100644 --- a/challenge-138/cheok-yin-fung/perl/ch-2.pl +++ b/challenge-138/cheok-yin-fung/perl/ch-2.pl @@ -22,12 +22,17 @@ sub split_number { my $len = length $N; my $upper = length $rt; - my %wlen; - + my %wlen; # hash to record each unordered partition my $i = Integer::Partition->new($len); while (my $a = $i->next) { - next if any { $_ > $upper } @$a; + next if any { $_ > $upper } @$a; + # Explanation for above line: + # It is an optimization. + # For example, sqrt(9663676416) = 98304 + # so we can expect partitions with number > 99999, + # i.e. length number > 5, + # cannot fulfill the requirement. my $j = permutations($a); while (my $b = $j->next) { if (!defined($wlen{join ",", @$b})) { @@ -41,7 +46,7 @@ sub split_number { push @config, $temp; } if ( (sum @config) == $rt) { - say "sqrt($N) = " , + say "sqrt($N) = " , #print the formula "$rt = ", join " + ", map { $_ == 0 ? "(0)" : $_ } @config; return 1; -- cgit