aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMohammad S Anwar <Mohammad.Anwar@yahoo.com>2020-05-18 13:46:12 +0100
committerGitHub <noreply@github.com>2020-05-18 13:46:12 +0100
commite04945402abdff3aa57bc9c62c5faec0cb6e98a7 (patch)
tree4aeffc4d541a7d5558f57acee01778d8fc172e18
parent78fe2f72354f77a833346bcf8571780c6fd2be5e (diff)
parent44907af891ba4c43ee28d3335947d91fbad1a569 (diff)
downloadperlweeklychallenge-club-e04945402abdff3aa57bc9c62c5faec0cb6e98a7.tar.gz
perlweeklychallenge-club-e04945402abdff3aa57bc9c62c5faec0cb6e98a7.tar.bz2
perlweeklychallenge-club-e04945402abdff3aa57bc9c62c5faec0cb6e98a7.zip
Merge pull request #1732 from Scimon/master
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('.');
+ }
+}