diff options
| author | CY Fung <fungcheokyin@gmail.com> | 2022-06-12 11:26:01 +0800 |
|---|---|---|
| committer | CY Fung <fungcheokyin@gmail.com> | 2022-06-12 11:26:01 +0800 |
| commit | 625339f89da8024a9de690f5ed163839989fa40a (patch) | |
| tree | 7cf8ea07f96e95e15463f5597f91c63d755c0907 | |
| parent | a2d9f56f20f4773112b0656892fd4a0945fbe401 (diff) | |
| download | perlweeklychallenge-club-625339f89da8024a9de690f5ed163839989fa40a.tar.gz perlweeklychallenge-club-625339f89da8024a9de690f5ed163839989fa40a.tar.bz2 perlweeklychallenge-club-625339f89da8024a9de690f5ed163839989fa40a.zip | |
Task 2 big num
| -rw-r--r-- | challenge-168/cheok-yin-fung/perl/ch-2.pl | 16 |
1 files changed, 8 insertions, 8 deletions
diff --git a/challenge-168/cheok-yin-fung/perl/ch-2.pl b/challenge-168/cheok-yin-fung/perl/ch-2.pl index ea156c4976..6986c4809a 100644 --- a/challenge-168/cheok-yin-fung/perl/ch-2.pl +++ b/challenge-168/cheok-yin-fung/perl/ch-2.pl @@ -18,20 +18,20 @@ sub hp { sub my_hp { + my $num = $_[0]; my $recur_depth = $_[1]; - - die "Number involed too large.\n" + die "Number involved too large.\n" if - Math::BigInt->new(18446744073709551616) # 2**64 - ->bcmp( Math::BigInt->new($_[0]) ) - == -1; + Math::BigInt->new("18446744073709551616") # 2**64 + ->ble( Math::BigInt->new($num) ); + - die "Walk so far but still cannot get result. :(\n" if $recur_depth > 20; - my $num = $_[0]; if (is_prime($num) == 2) { return $num; } + die "Walk so far but still cannot get result. :(\n" if $recur_depth > 20; + my @factors = (); my $p = 2; while ($num != 1) { @@ -47,7 +47,7 @@ sub my_hp { last; } } - my $nxt = (reduce { $a . $b } @factors); + my $nxt = join "", @factors; say " $nxt"; return my_hp($nxt, ++$recur_depth); } |
