diff options
| author | mimosinnet <mimosinnet@gmail.com> | 2020-12-27 21:53:51 +0100 |
|---|---|---|
| committer | mimosinnet <mimosinnet@gmail.com> | 2020-12-27 21:53:51 +0100 |
| commit | dbd14b6d2a4bcde1abc3aefcc3201075d872c005 (patch) | |
| tree | ad3f37e28e83c21472c90e98c677b81058a48fbd /challenge-092/mimosinnet | |
| parent | 2ccc5ee9ff49fa8affc161a8271dbadeac9c5982 (diff) | |
| download | perlweeklychallenge-club-dbd14b6d2a4bcde1abc3aefcc3201075d872c005.tar.gz perlweeklychallenge-club-dbd14b6d2a4bcde1abc3aefcc3201075d872c005.tar.bz2 perlweeklychallenge-club-dbd14b6d2a4bcde1abc3aefcc3201075d872c005.zip | |
Challenge 092
Diffstat (limited to 'challenge-092/mimosinnet')
| -rw-r--r-- | challenge-092/mimosinnet/raku/ch-1.raku | 37 | ||||
| -rw-r--r-- | challenge-092/mimosinnet/raku/ch-2.raku | 59 |
2 files changed, 96 insertions, 0 deletions
diff --git a/challenge-092/mimosinnet/raku/ch-1.raku b/challenge-092/mimosinnet/raku/ch-1.raku new file mode 100644 index 0000000000..ed7c4bb7d6 --- /dev/null +++ b/challenge-092/mimosinnet/raku/ch-1.raku @@ -0,0 +1,37 @@ +sub challenge( $A, $B ) { + return 0 if $A.chars ne $B.chars; + return 0 if ($A.comb Z=> $B.comb).Hash.elems ne ($B.comb Z=> $A.comb).Hash.elems; + return 1; +} + + +multi sub MAIN( Str:D $A, Str:D $B) { + my $output = challenge($A,$B); + say 'Input $A = ' ~ $A ~ '; $B = ' ~ $B; + say "Output: $output \n" +} + +multi sub MAIN( 'challenge' ) { + for [ < abc xyz >, < abb xyy >, < sum add > ] -> [ $A, $B ] { + &MAIN( $A, $B); + } +} + +multi sub MAIN( 'test' ) { + use Test; + + my @tests = ( + ( < abcd xyz >, 0 ), + ( < aaa xyz >, 0 ), + ( < xyz aaa >, 0 ), + ( < abc xyz >, 1 ), + ( < abb xyy >, 1 ), + ( < sum add >, 0 ) + ); + + for @tests -> @test { + is(challenge(@test[0][0], @test[0][1]), @test[1]); + } +} + + diff --git a/challenge-092/mimosinnet/raku/ch-2.raku b/challenge-092/mimosinnet/raku/ch-2.raku new file mode 100644 index 0000000000..c2ae190f13 --- /dev/null +++ b/challenge-092/mimosinnet/raku/ch-2.raku @@ -0,0 +1,59 @@ +# The script prints a new set of intervals, but merges adjacent intervals :( + +sub challenge( @S, $N ) { + my @initial = @S.shift; + my $final = (@initial[0][0]...@initial[0][1]); + for @S -> @s { + $final = $final ∪ (@s[0]...@s[1]); + } + my @items = ( $final ∪ ($N[0]...$N[1]) ).keys.sort; + my ($item_start, $item_end) = (shift @items, ); + my @final_array = $item_start; + for @items -> $item { + if $item eq ++$item_start { + $item_end = $item; + next; + } + @final_array.push: $item_end, $item; + $item_start = $item; + } + + return @final_array.push: $item_end; +} + +multi sub MAIN( @S, $N ) { + print "\nInput \$S = "; + for @S -> @a { + print "(@a[0], @a[1]), "; + } + print "; \$N = ($N)"; + print "\nOutput: "; + my @output = challenge( @S, $N ); + for @output.sort -> $a, $b { + print "($a, $b), "; + } + print "\n"; +} + +multi sub MAIN( 'challenge' ) { + say "The script prints a new set of intervals, but merges adjacent intervals :( \n"; + my @S1 = (1,4), (8,10); + my $N1 = (2,6); + + my @S2 = (1,2), (3,7), (8,10); + my $N2 = (5,8); + + my @S3 = (1,5), (7,9); + my $N3 = (10,11); + + my @challenges = ( + (@S1, $N1), + (@S2, $N2), + (@S3, $N3) + ); + + for @challenges -> @challenge { + &MAIN(@challenge[0],@challenge[1]); + } +} + |
