Given a list of 4 or more numbers, write a script to find the contiguous sublist that has the maximum product. The length of the sublist is irrelevant; your job is to maximize the product.

Here you go:

raku -e 'say (for ^$_ X ^$_ -> (\a, \b) { $_ => [*] |$_ given $_[a..b] }).max(*.value) given <2 5 -1 3>'

It’s very simple. The trick is really in the $_s (if that’s how you pluralise $_). Just for fun, I’m gonna replace each $_ with the value it holds.

It may not seem like much, but it’s doing exactly what the problem says. The string of numbers is exhaustively matched against what the problem defines as a valid IPv4 address. The pattern tries different ways to partition the string into four numbers (note the ** 4), each of which is either 0, or a number whose leftmost digit is not 0 and which isn’t greater than 255. Each “octet” is captured in the same group 0, so the group is actually a list of octets which we then join using dots — and that’s our address.