From 625339f89da8024a9de690f5ed163839989fa40a Mon Sep 17 00:00:00 2001 From: CY Fung Date: Sun, 12 Jun 2022 11:26:01 +0800 Subject: Task 2 big num --- challenge-168/cheok-yin-fung/perl/ch-2.pl | 16 ++++++++-------- 1 file 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); } -- cgit