From 44907af891ba4c43ee28d3335947d91fbad1a569 Mon Sep 17 00:00:00 2001 From: Simon Proctor Date: Mon, 18 May 2020 13:33:39 +0100 Subject: IPv4 address generator --- challenge-061/simon-proctor/raku/ch-2.raku | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 challenge-061/simon-proctor/raku/ch-2.raku 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('.'); + } +} -- cgit