diff options
author | Matias Linares <matiaslina@gmail.com> | 2020-12-05 10:55:56 -0300 |
---|---|---|
committer | Matias Linares <matiaslina@gmail.com> | 2020-12-05 10:55:56 -0300 |
commit | a0fcb600572ea0da9dee1b5b9e7a24ce674ebe7e (patch) | |
tree | a663ee4f6a427e98db0878ca539c9288bfbc70d0 /2018/day4.p6 | |
parent | 5fa17cd54a1170449a91da48a2fe88a99349daa2 (diff) | |
download | advent-of-code-a0fcb600572ea0da9dee1b5b9e7a24ce674ebe7e.tar.gz |
Add 2018 and 2017
Diffstat (limited to '2018/day4.p6')
-rw-r--r-- | 2018/day4.p6 | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/2018/day4.p6 b/2018/day4.p6 new file mode 100644 index 0000000..def1084 --- /dev/null +++ b/2018/day4.p6 @@ -0,0 +1,50 @@ +#`[ +[1518-11-01 00:00] Guard #10 begins shift +[1518-11-01 00:05] falls asleep +[1518-11-01 00:25] wakes up +[1518-11-01 00:30] falls asleep +[1518-11-01 00:55] wakes up +[1518-11-01 23:58] Guard #99 begins shift +[1518-11-02 00:40] falls asleep +[1518-11-02 00:50] wakes up +[1518-11-03 00:05] Guard #10 begins shift +[1518-11-03 00:24] falls asleep +[1518-11-03 00:29] wakes up +[1518-11-04 00:02] Guard #99 begins shift +[1518-11-04 00:36] falls asleep +[1518-11-04 00:46] wakes up +[1518-11-05 00:03] Guard #99 begins shift +[1518-11-05 00:45] falls asleep +[1518-11-05 00:55] wakes up +] + +use Grammar::Tracer; + +grammar GuardLog { + token TOP { [ <guard-log> ]+ } + rule guard-log { + <shift-start> 'Guard #' <id> begins shift + [ <log> ]+ + } + rule log { <date> <action> } + token shift-start { <date> } + token id { \d+ } + token date { '[' \d ** 4 '-' \d ** 2 '-' \d ** 2 ' ' <hour> ']'} + token hour { \d ** 2 ':' \d ** 2 } + + rule action { + | 'falls asleep' + | 'wakes up' + } +} + +my $log = GuardLog.parse(q:to/EOF/); +[1518-11-01 00:00] Guard #10 begins shift +[1518-11-01 00:05] falls asleep +[1518-11-01 00:25] wakes up +[1518-11-01 00:30] falls asleep +[1518-11-01 00:55] wakes up +EOF + +say $log<guard-log>[0]<log>.elems; + |