diff options
| author | KUEPPO <tcheukueppo@tutanota.com> | 2022-12-04 21:49:56 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-12-04 21:49:56 +0100 |
| commit | 9b472e693d91d27d71d7c9a05bc6cb616b6043e4 (patch) | |
| tree | 97eb59a2c126312ecc783a9d19b924a42fef785c | |
| parent | 50e7a7dea394043a4328a4a5bafd04a710dbd3df (diff) | |
| download | perlweeklychallenge-club-9b472e693d91d27d71d7c9a05bc6cb616b6043e4.tar.gz perlweeklychallenge-club-9b472e693d91d27d71d7c9a05bc6cb616b6043e4.tar.bz2 perlweeklychallenge-club-9b472e693d91d27d71d7c9a05bc6cb616b6043e4.zip | |
ch-1.pl
| -rw-r--r-- | challenge-193/kueppo-wesley/Perl/ch-1.pl | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/challenge-193/kueppo-wesley/Perl/ch-1.pl b/challenge-193/kueppo-wesley/Perl/ch-1.pl new file mode 100644 index 0000000000..5156292c81 --- /dev/null +++ b/challenge-193/kueppo-wesley/Perl/ch-1.pl @@ -0,0 +1,31 @@ +#!/usr/bin/env perl + +use strict; +use warnings; +use feature qw/ state current_sub /; + +use Test::More; + +sub find_bins { + my ( $size, $partial ) = @_; + state $solution; + + $partial = '', $solution = undef unless defined $partial; + if ( $size == 0 ) { + push @$solution, $partial; + } + else { + __SUB__->( $size - 1, '0' . $partial ); + __SUB__->( $size - 1, '1' . $partial ); + } + + return $solution; +} + +subtest 'find_bins' => sub { + is_deeply(find_bins(3), [ qw( 000 100 010 110 001 101 011 111 ) ], "works for 3?"); + is_deeply(find_bins(2), [ qw( 00 10 01 11 ) ], "works for 2?"); + is_deeply(find_bins(1), [ qw( 0 1 ) ], "works for 1?"); +}; + +done_testing(1); |
