aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLubos Kolouch <lubos@kolouch.net>2021-11-13 14:00:19 +0100
committerLubos Kolouch <lubos@kolouch.net>2021-11-13 14:00:19 +0100
commit5c261d09314f08e9851d667ac796adcf9225c6f5 (patch)
tree90b282fdeff0de22fe24c816067bf1aa6569fb45
parent296aebee4b1c7d91da164033ebecfa47cefbb75c (diff)
downloadperlweeklychallenge-club-5c261d09314f08e9851d667ac796adcf9225c6f5.tar.gz
perlweeklychallenge-club-5c261d09314f08e9851d667ac796adcf9225c6f5.tar.bz2
perlweeklychallenge-club-5c261d09314f08e9851d667ac796adcf9225c6f5.zip
Challenge 137 Task2 Perl LK
-rw-r--r--challenge-138/lubos-kolouch/perl/ch-2.pl30
1 files changed, 30 insertions, 0 deletions
diff --git a/challenge-138/lubos-kolouch/perl/ch-2.pl b/challenge-138/lubos-kolouch/perl/ch-2.pl
new file mode 100644
index 0000000000..1579dd7984
--- /dev/null
+++ b/challenge-138/lubos-kolouch/perl/ch-2.pl
@@ -0,0 +1,30 @@
+use strict;
+use warnings;
+use Algorithm::Combinatorics qw/partitions/;
+
+sub is_split_number {
+ my $what = shift;
+ my $sqr = int(sqrt($what));
+
+ my @what_arr = split //, $what;
+ my @what_partitions = partitions(\@what_arr);
+
+ for my $part (@what_partitions) {
+ my $result = 0;
+
+ for my $item(@$part) {
+ $result += join '',@$item;
+ }
+
+ return 1 if $result == $sqr;
+ }
+
+ return 0;
+}
+
+use Test::More;
+is(is_split_number(81), 1);
+is(is_split_number(9801), 1);
+is(is_split_number(36), 0);
+
+done_testing;