aboutsummaryrefslogtreecommitdiff
path: root/challenge-061/simon-proctor/raku/ch-2.raku
blob: a6ff38cdba5d72f02ec2d5e190164942522078e0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
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('.');
    }
}