Passed
Push — master ( d32d2e...ea64ab )
by Daan
01:29
created

Day1::loadInput()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 1
eloc 2
c 1
b 0
f 1
nc 1
nop 0
dl 0
loc 5
rs 10
1
<?php
2
3
namespace DaanMooij\AdventOfCode\Year2015;
4
5
use DaanMooij\AdventOfCode\Day;
6
7
class Day1 implements Day
8
{
9
    const FLOOR_UP = '(';
10
    const FLOOR_DOWN = ')';
11
12
    private array $directions = [];
13
14
    public function loadInput(): void
15
    {
16
        $filepath = __DIR__ . "/input/day-1.txt";
17
18
        $this->directions = str_split(file_get_contents($filepath));
19
    }
20
21
    public function solve()
22
    {
23
        printf("The resulting floor is: %s\n", $this->calculateFloor());
24
    }
25
26
    public function calculateFloor(int $floor = 0): int
27
    {
28
        foreach ($this->directions as $direction) {
29
            if ($direction === self::FLOOR_UP) {
30
                $floor++;
31
            } elseif ($direction === self::FLOOR_DOWN) {
32
                $floor--;
33
            }
34
        }
35
36
        return $floor;
37
    }
38
39
    public function setDirections(array $directions): void
40
    {
41
        $this->directions = $directions;
42
    }
43
44
    public function getDirections(): array
45
    {
46
        return $this->directions;
47
    }
48
}