about summary refs log tree commit diff stats
path: root/072channel.mu
Commit message (Collapse)AuthorAgeFilesLines
* 2798 - experiment: split channels into two endsKartik K. Agaram2016-03-191-94/+123
| | | | | | | | | | This way when you pass one end to a function or routine, you can implicitly give it the right to either read or write the channel, but not both. The cost: code gets more convoluted, names get more convoluted. You can see this in particular in the test for buffer-lines. Let's see how it goes..
* 2794Kartik K. Agaram2016-03-191-40/+40
| | | | Arrange for tests to run multiple variants of channel functions.
* 2793 - more fixes to make channels genericKartik K. Agaram2016-03-191-8/+8
| | | | Finally..
* 2788Kartik K. Agaram2016-03-171-5/+5
|
* 2787Kartik K. Agaram2016-03-171-2/+2
| | | | | | *Really* make channels generic. I'd fixed all the call sites in 2785, but forgotten to actually switch the declaration. It works though; generics working smoothly.
* 2784 - make channels genericKartik K. Agaram2016-03-141-60/+60
| | | | | | I've ignored Mu's concurrency primitives for a while, but they're starting to return to front-and-center as I work on the file system interfaces.
* 2778 - fix all layersKartik K. Agaram2016-03-141-0/+357
-color: #fff0f0 } /* Literal.String.Double */ .highlight .se { color: #0044dd; background-color: #fff0f0 } /* Literal.String.Escape */ .highlight .sh { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Heredoc */ .highlight .si { color: #3333bb; background-color: #fff0f0 } /* Literal.String.Interpol */ .highlight .sx { color: #22bb22; background-color: #f0fff0 } /* Literal.String.Other */ .highlight .sr { color: #008800; background-color: #fff0ff } /* Literal.String.Regex */ .highlight .s1 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Single */ .highlight .ss { color: #aa6600; background-color: #fff0f0 } /* Literal.String.Symbol */ .highlight .bp { color: #003388 } /* Name.Builtin.Pseudo */ .highlight .fm { color: #0066bb; font-weight: bold } /* Name.Function.Magic */ .highlight .vc { color: #336699 } /* Name.Variable.Class */ .highlight .vg { color: #dd7700 } /* Name.Variable.Global */ .highlight .vi { color: #3333bb } /* Name.Variable.Instance */ .highlight .vm { color: #336699 } /* Name.Variable.Magic */ .highlight .il { color: #0000DD; font-weight: bold } /* Literal.Number.Integer.Long */
#!/usr/bin/env raku

sub MAIN (
    # Part to run.
    Int $part where * == 1|2 = 1
) {
    my $input = slurp "input";
    my @passports = $input.split("\n\n");
    my $valid_passports = 0;

    MAIN: for @passports -> $passport {
        my %fields;

        for $passport.words -> $field {
            my ($key, $value) = $field.split(":");
            %fields{$key} = $value;
        }

        # Check for fields that are strictly required. `cid' can
        # be skipped. Skip this passport if it's not valid.
        for <byr iyr eyr hgt hcl ecl pid> -> $field {
            next MAIN unless %fields{$field};
        }

        # Do validation in part 2.
        if $part == 2 {
            next MAIN unless (
                (1920%fields{<byr>} ≤ 2002)
                and (2010%fields{<iyr>} ≤ 2020)
                and (2020%fields{<eyr>} ≤ 2030)
                and (<amb blu brn gry grn hzl oth>%fields{<ecl>})
                and (%fields{<pid>} ~~ /^\d ** 9$/)
                and (%fields{<hcl>} ~~ /^'#' <[\d a..f]> ** 6/)
            );
            given substr(%fields{<hgt>}, *-2) {
                when 'cm' {
                    next MAIN unless 150substr(%fields{<hgt>}, 0, *-2) ≤ 193;
                }
		when 'in' {
                    next MAIN unless 59substr(%fields{<hgt>}, 0, *-2) ≤ 76;
                }
                default { next MAIN; }
	    }
        }
        $valid_passports++;
    }
    say "Part $part: " ~ $valid_passports;
}