aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSimon Proctor <simon.proctor@zoopla.co.uk>2020-05-18 13:33:39 +0100
committerSimon Proctor <simon.proctor@zoopla.co.uk>2020-05-18 13:33:39 +0100
commit44907af891ba4c43ee28d3335947d91fbad1a569 (patch)
treec623d24dbf9404260193d5542d9da4c651f43cb9
parent78758c83bb71a3b303be7ff07330e18d4c4d1788 (diff)
downloadperlweeklychallenge-club-44907af891ba4c43ee28d3335947d91fbad1a569.tar.gz
perlweeklychallenge-club-44907af891ba4c43ee28d3335947d91fbad1a569.tar.bz2
perlweeklychallenge-club-44907af891ba4c43ee28d3335947d91fbad1a569.zip
IPv4 address generator
-rw-r--r--challenge-061/simon-proctor/raku/ch-2.raku15
1 files changed, 15 insertions, 0 deletions
diff --git a/challenge-061/simon-proctor/raku/ch-2.raku b/challenge-061/simon-proctor/raku/ch-2.raku
new file mode 100644
index 0000000000..a6ff38cdba
--- /dev/null
+++ b/challenge-061/simon-proctor/raku/ch-2.raku
@@ -0,0 +1,15 @@
+#!/usr/bin/env raku
+
+use v6;
+
+#| Print all valid IPv4 addresses from the given string
+#| Will output nothing if no valid IPv4 address can be made from the given string
+sub MAIN(
+ Str $possible where * ~~ /^ <[0..9]> ** 4..12 $/ #= String of numbers to make IPv4 addresses from (between 4 and 12 characters)
+){
+ for $possible ~~ m:ex/^ ( <[0..9]> ** 1..3 ) ** 4 $/ -> $match {
+ my @vals = $match[0].map(*.Str);
+ next unless all( @vals.map( { $_ ~~ $_.Int.Str && 0 <= $_ <= 255 } ) );
+ say @vals.join('.');
+ }
+}