Download the raw code.

use v6;

my  @ranges  = $*IN.get.comb: /'-'? \d+ | ['+'|'-']/; # <[+-]> raises an error
my ($number) = $*IN.get.comb: /'-'? \d+/;

if +@ranges % 3  or  ! defined $number {
    say 'invalid input';

my $allowed = False;
for @ranges -> $op, $start, $end {
    $allowed = $op ne '-' if $start <= $number <= $end;

say $allowed ?? 'yes' !! 'no';


Look at that! Some scripts have a natural air of lightness about them. This is an example.

Some things are vertically aligned. I have a weakness for that.


The program has six variables. I like the names of all of them.

Clarity of intent

Another exit with zero status on a faulty condition.

A subtler complaint: the algorithm not so much defines the input data, as it exploits the existing examples. The parsing at line 3 basically assumes that things will be sent in the right order, and the only subsequent checking that's done is on the number of items, not their types. Say what you want about more intricate parsing mechanisms, but they would rule out a few inputs that were never intended to work.

Algorithmic efficiency

As expected, loops over the input data once and is done with it.

Idiomatic use of Perl 6

Reading people's code like this, I feel I'm getting a good grip on people's various coding styles. Whereas many of the other submitters like to put things into nested data structures, Matthias like to have things readily available in a shallow array. That mixes really well with Perl 6's for loops. You get to for @ranges -> $op, $start, $end on line 12, and realize that all the heavy lifting with preparing that array had already been done on line 3. Yes, it's cheating, but it's nice cheating.


Admirably short.