diff options
| author | Luca Ferrari <fluca1978@gmail.com> | 2020-05-18 15:40:39 +0200 |
|---|---|---|
| committer | Luca Ferrari <fluca1978@gmail.com> | 2020-05-18 15:40:39 +0200 |
| commit | 5d2255dc4370c5795abfca1d1e55b9b295002fec (patch) | |
| tree | 792d0fdb8ff383bd2b2c3efd1dde1c15d9af0d9d | |
| parent | 8516118fec77f8e5e643aa442615afc400d18e7b (diff) | |
| download | perlweeklychallenge-club-5d2255dc4370c5795abfca1d1e55b9b295002fec.tar.gz perlweeklychallenge-club-5d2255dc4370c5795abfca1d1e55b9b295002fec.tar.bz2 perlweeklychallenge-club-5d2255dc4370c5795abfca1d1e55b9b295002fec.zip | |
Task2 done.
| -rw-r--r-- | challenge-061/luca-ferrari/raku/ch-2.p6 | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/challenge-061/luca-ferrari/raku/ch-2.p6 b/challenge-061/luca-ferrari/raku/ch-2.p6 new file mode 100644 index 0000000000..5c28e0d39b --- /dev/null +++ b/challenge-061/luca-ferrari/raku/ch-2.p6 @@ -0,0 +1,29 @@ +#!env raku +# +# +# You are given a string containing only digits (0..9). +# The string should have between 4 and 12 digits. +# +# Write a script to print every possible valid IPv4 address that can be made by partitioning the input string. +# +# For the purpose of this challenge, a valid IPv4 address consists of four “octets” i.e. A, B, C and D, separated by dots (.). +# +# Each octet must be between 0 and 255, and must not have any leading zeroes. (e.g., 0 is OK, but 01 is not.) +# Example +# +# Input: 25525511135, +# +# Output: +# +# 255.255.11.135 +# 255.255.111.35 +# + +sub MAIN( Int $string = 25525511135 ) { + say "Starting from $string"; + + for $string ~~ m:ex/ ^ ( <[0..9]> ** 1..3 ) ** 4 $/ { + my @ip = $_[0].map( *.Int ); + say @ip.join( '.' ) if @ip.grep( 0 <= * <= 255).elems == @ip.elems; + } +} |
