Browse Source

[WIP] [2018-12-04] Add first challange sample

master
Elis Hirwing 3 years ago
parent
commit
0d153ab3bf
Signed by: etu GPG Key ID: D57EFA625C9A925F
  1. 2
      Makefile
  2. 39
      day4/main.php

2
Makefile

@ -10,6 +10,8 @@ day3:
php day3/main.php
day4:
php day4/main.php
day5:
day6:
day7:

39
day4/main.php

@ -0,0 +1,39 @@
<?php
// https://adventofcode.com/2018/day/4
function puzzle1(array $logEntries)
{
$sleepMatrix = [];
$guardOnDuty = -1;
foreach ($logEntries as $entry) {
preg_match(
'/\[(\d{4})-(\d\d)-(\d\d)\s(\d\d):(\d\d)\]\s(.+)/',
$entry,
$matches
);
print_r($matches);
}
}
echo 'First challange sample:'.PHP_EOL;
echo puzzle1([
'[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',
]).PHP_EOL; // 240
Loading…
Cancel
Save