aboutsummaryrefslogtreecommitdiff
path: root/challenge-050/simon-proctor
diff options
context:
space:
mode:
authorSimon Proctor <simon.proctor@zpg.co.uk>2020-03-02 14:05:31 +0000
committerSimon Proctor <simon.proctor@zpg.co.uk>2020-03-02 14:05:31 +0000
commit91d0a3b129c4c59dd93186e1c81664376a16dfec (patch)
tree819f1ebeaeeed6210edb52945c08681304febcf5 /challenge-050/simon-proctor
parent16116626d45bf678a0209a92d27478423fbcfab3 (diff)
downloadperlweeklychallenge-club-91d0a3b129c4c59dd93186e1c81664376a16dfec.tar.gz
perlweeklychallenge-club-91d0a3b129c4c59dd93186e1c81664376a16dfec.tar.bz2
perlweeklychallenge-club-91d0a3b129c4c59dd93186e1c81664376a16dfec.zip
Challenge 50 part 1
Diffstat (limited to 'challenge-050/simon-proctor')
-rw-r--r--challenge-050/simon-proctor/raku/ch-1.p630
1 files changed, 30 insertions, 0 deletions
diff --git a/challenge-050/simon-proctor/raku/ch-1.p6 b/challenge-050/simon-proctor/raku/ch-1.p6
new file mode 100644
index 0000000000..a9de6f7119
--- /dev/null
+++ b/challenge-050/simon-proctor/raku/ch-1.p6
@@ -0,0 +1,30 @@
+#!/usr/bin/raku
+
+use v6;
+
+subset IntPair of Str where m!^ \d+ "," \d+ $!;
+
+multi sub MAIN ( IntPair $pair ) is hidden-from-USAGE {
+ MAIN( [$pair,] );
+}
+
+#| Given a list of Integer Pairs print the sorted list of pairs with intersections combined
+multi sub MAIN (
+ *@pairs where { $_.all ~~ IntPair } #= List of comma seperated integer pairs
+) {
+ my @working = @pairs.map(*.split(",")).sort( *[0] <=> *[0] );
+ my @out;
+ my $current = @working.shift;
+
+ while ( @working ) {
+ my $next = @working.shift;
+ if ( $current[0] <= $next[1] && $current[1] >= $next[0] ) {
+ $current = [ $current[0] < $next[0] ?? $current[0] !! $next[0],
+ $current[1] > $next[1] ?? $current[1] !! $next[1] ];
+ } else {
+ @out.push( $current );
+ $current = $next;
+ }
+ }
+ @out.push( $current ).map( *.join(",") ).join(" ").say;
+}