aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorE7-87-83 <fungcheokyin@gmail.com>2021-08-01 10:50:27 +0800
committerE7-87-83 <fungcheokyin@gmail.com>2021-08-01 10:50:27 +0800
commita49e0ac7bf8b5faae966474e5f3ddf96472d7447 (patch)
treed7c3e88412c008a749c7cd6c9e38ab94f6b7ebb5
parent1e078f86d0f29d2c090bada2035a55afdbe05b77 (diff)
downloadperlweeklychallenge-club-a49e0ac7bf8b5faae966474e5f3ddf96472d7447.tar.gz
perlweeklychallenge-club-a49e0ac7bf8b5faae966474e5f3ddf96472d7447.tar.bz2
perlweeklychallenge-club-a49e0ac7bf8b5faae966474e5f3ddf96472d7447.zip
FINALIZED
-rw-r--r--challenge-123/cheok-yin-fung/perl/ch-1.pl8
-rw-r--r--challenge-123/cheok-yin-fung/perl/ch-2-cube-hypercube.pl12
2 files changed, 14 insertions, 6 deletions
diff --git a/challenge-123/cheok-yin-fung/perl/ch-1.pl b/challenge-123/cheok-yin-fung/perl/ch-1.pl
index c688d10baf..7e14c6c30f 100644
--- a/challenge-123/cheok-yin-fung/perl/ch-1.pl
+++ b/challenge-123/cheok-yin-fung/perl/ch-1.pl
@@ -17,9 +17,9 @@ sub nth_seq_num {
my $parameter = $_[1];
my $k;
my $i = 0;
- while (scalar @seq < $parameter) {
+ while (scalar $_[0]->@* < $parameter) {
$i++;
- $k = $seq[-1] + $i;
+ $k = $_[0]->[-1] + $i;
my $j = $k;
my $tmp_j = 0;
while ( $j != 1 && $tmp_j != $j) {
@@ -29,11 +29,11 @@ sub nth_seq_num {
$j /= 5 if $j % 5 == 0;
}
if ($j == 1) {
- push @seq, $k;
+ push $_[0]->@*, $k;
$i = 0;
}
}
- return $seq[$parameter-1];
+ return $_[0]->[$parameter-1];
}
diff --git a/challenge-123/cheok-yin-fung/perl/ch-2-cube-hypercube.pl b/challenge-123/cheok-yin-fung/perl/ch-2-cube-hypercube.pl
index a70526e819..2e32e03043 100644
--- a/challenge-123/cheok-yin-fung/perl/ch-2-cube-hypercube.pl
+++ b/challenge-123/cheok-yin-fung/perl/ch-2-cube-hypercube.pl
@@ -39,6 +39,8 @@ sub is_square {
}
}
+
+
sub is_cube {
my @p = @_;
my %v;
@@ -52,7 +54,7 @@ sub is_cube {
my $WU = vec_sum($W, $U);
my $UN = vec_sum($U, $N);
my $iter_face = permutations([$NW, $WU, $UN]);
- my $bool = undef;
+ my $bool_face = undef;
while (!$bool && (my $p = $iter_face->next)) {
$bool =
vec_same_f($v{$ind[3]}, $p->[0]) &&
@@ -60,7 +62,7 @@ sub is_cube {
vec_same_f($v{$ind[5]}, $p->[2]) ;
}
- return 0 if !$bool;
+ return 0 if !$bool_face;
my $NWU = vec_sum( $N, $WU);
if ( vec_same_f( $v{$ind[6]} , $NWU ) ) {
@@ -71,6 +73,7 @@ sub is_cube {
}
}
+
sub is_hypercube {
my @p = @_;
my %v;
@@ -132,6 +135,7 @@ sub is_hypercube {
}
}
+
sub vec_prod {
my $first = $_[0];
my $second = $_[1];
@@ -145,6 +149,7 @@ sub vec_prod_f {
return sprintf("%f", vec_prod($_[0], $_[1]));
}
+
sub norm {
my $p = $_[0];
my $sum = 0;
@@ -156,6 +161,7 @@ sub norm_f {
return sprintf("%f", norm($_[0]));
}
+
sub vec_sum {
my $first = $_[0];
my $second = $_[1];
@@ -167,6 +173,7 @@ sub vec_sum {
return $ans;
}
+
sub vec_same {
my $first = $_[0];
my $second = $_[1];
@@ -187,6 +194,7 @@ sub vec_same_f {
return 1;
}
+
sub vec_subtract {
my $first = $_[0];
my $second = $_[1];