aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJames Smith <js5@sanger.ac.uk>2023-04-06 22:52:06 +0100
committerGitHub <noreply@github.com>2023-04-06 22:52:06 +0100
commit2051cadd9c1604377a84b650a898ae46b5f6a9e4 (patch)
tree98660ac37a559d03f4ab4378eeda23f55b81db0f
parent57ef36f9f13d807c25ced6c193f8a16e8f391645 (diff)
downloadperlweeklychallenge-club-2051cadd9c1604377a84b650a898ae46b5f6a9e4.tar.gz
perlweeklychallenge-club-2051cadd9c1604377a84b650a898ae46b5f6a9e4.tar.bz2
perlweeklychallenge-club-2051cadd9c1604377a84b650a898ae46b5f6a9e4.zip
Create ch-2.pl
-rw-r--r--challenge-211/james-smith/perl/ch-2.pl24
1 files changed, 24 insertions, 0 deletions
diff --git a/challenge-211/james-smith/perl/ch-2.pl b/challenge-211/james-smith/perl/ch-2.pl
new file mode 100644
index 0000000000..8c259b88c1
--- /dev/null
+++ b/challenge-211/james-smith/perl/ch-2.pl
@@ -0,0 +1,24 @@
+#!/usr/local/bin/perl
+
+use strict;
+use warnings;
+use feature qw(say);
+use Test::More;
+
+my @TESTS = (
+ [ [1,2,3,4,5,6,7,8], 1 ],
+ [ [1,3], 0 ],
+);
+
+sub equal_split {
+ my( $t, $c ) = ( 0, scalar @_ );
+ $t += $_ for @_;
+ for my $x ( 1 .. ( 1 << $c-1 ) -1 ) {
+ my($m,$n)=(0,0); my @T;
+ ( $x & 1 ) && ( $m += $_[$_], $n++, push @T, $_[$_] ), $x >>= 1 for 1 .. $c-1;
+ return 1 unless $n*$t-$m*$c;
+ }
+ 0
+}
+
+is( equal_split( @{$_->[0]} ), $_->[1] ) for @TESTS;