Skip to content

Commit

Permalink
Refactor structure, work on readme generator
Browse files Browse the repository at this point in the history
  • Loading branch information
mikeroq committed Dec 11, 2021
1 parent 00d4c62 commit b0293be
Show file tree
Hide file tree
Showing 511 changed files with 46,580 additions and 1,099 deletions.
1 change: 1 addition & 0 deletions .env
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
AOC_SESSION=53616c7465645f5f4771c3dd63698c59cce79783e8471219ea09a0443d42993a3978362151ffaecf751243970509fa65
1 change: 1 addition & 0 deletions .env.sample
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
AOC_SESSION=ValueHere
52 changes: 52 additions & 0 deletions AdventOfCode2015/Day01/Day01.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<?php

namespace mikeroq\AdventOfCode\AdventOfCode2015\Day01;

use mikeroq\AdventOfCode\Shared\Day;

class Day01 extends Day
{
protected int $floor = 0;

protected function formatInput(): void
{
$this->splitInputByCharacter();
}

protected function moveElevator($direction): void
{
match($direction) {
"(" => $this->floor++,
")" => $this->floor--
};
}

public function findFloor(): int
{
foreach ($this->input as $direction) {
$this->moveElevator($direction);
}
return $this->floor;
}

public function findBasement(): int
{
for ($i = 1; $i < count($this->input); $i++) {
$this->moveElevator($this->input[$i-1]);
if ($this->floor == -1) {
break;
}
}
return $i;
}

public function findFirstAnswer(): int
{
return $this->findFloor();
}

public function findSecondAnswer(): int
{
return $this->findBasement();
}
}
64 changes: 64 additions & 0 deletions AdventOfCode2015/Day01/Day01Test.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
<?php
namespace mikeroq\AdventOfCode\AdventOfCode2015\Day01;

use PHPUnit\Framework\TestCase;

final class Day01Test extends TestCase
{
public function testPart1ExampleFiveEquals3(): void
{
$day01 = new Day01();
$day01->importInput("))(((((", true);

$this->assertEquals(3, $day01->findFirstAnswer());
}

public function testPart1ExampleThreeEqualsNegative3(): void
{
$day01 = new Day01();
$day01->importInput(")())())", true);

$this->assertEquals(-3, $day01->findFirstAnswer());
}

public function testPart1ExampleOneEquals0(): void
{
$day01 = new Day01();
$day01->importInput("()()", true);

$this->assertEquals(0, $day01->findFirstAnswer());
}

public function testPart2ExampleOneCharacterEquals1(): void
{
$day01 = new Day01();
$day01->importInput(")", true);

$this->assertEquals(1, $day01->findSecondAnswer());
}

public function testPart2ExampleTwoCharacterEquals5(): void
{
$day01 = new Day01();
$day01->importInput("()())", true);

$this->assertEquals(5, $day01->findSecondAnswer());
}

// public function testPart1RealAnswerEquals74(): void
// {
// $day01 = new Day01();
// $day01->importInput("AdventOfCode2015/day01/input.txt");
//
// $this->assertEquals(74, $day01->findFirstAnswer());
// }
//
// public function testPart2RealAnswerEquals1795(): void
// {
// $day01 = new Day01();
// $day01->importInput("AdventOfCode2015/day01/input.txt");
//
// $this->assertEquals(1795, $day01->findSecondAnswer());
// }

}
44 changes: 44 additions & 0 deletions AdventOfCode2015/Day01/README.MD
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<article class="day-desc"><h2>--- Day 1: Not Quite Lisp ---</h2><p>Santa was hoping for a white Christmas, but his weather machine's "snow" function is powered by stars, and he's fresh out! To save Christmas, he needs you to collect <b class="star">fifty stars</b> by December 25th.</p>
<p>Collect stars by helping Santa solve puzzles. Two puzzles will be made available on each day in the Advent calendar; the second puzzle is unlocked when you complete the first. Each puzzle grants <b class="star">one star</b>. <span title="Also, some puzzles contain Easter eggs like this one. Yes, I know it's not traditional to do Advent calendars for Easter.">Good luck!</span></p>
<p>Here's an easy puzzle to warm you up.</p>
<p>Santa is trying to deliver presents in a large apartment building, but he can't find the right floor - the directions he got are a little confusing. He starts on the ground floor (floor <code>0</code>) and then follows the instructions one character at a time.</p>
<p>An opening parenthesis, <code>(</code>, means he should go up one floor, and a closing parenthesis, <code>)</code>, means he should go down one floor.</p>
<p>The apartment building is very tall, and the basement is very deep; he will never find the top or bottom floors.</p>

<ul>
<li><code>(())</code> and <code>()()</code> both result in floor <code>0</code>.</li>
<li><code>(((</code> and <code>(()(()(</code> both result in floor <code>3</code>.</li>
<li><code>))(((((</code> also results in floor <code>3</code>.</li>
<li><code>())</code> and <code>))(</code> both result in floor <code>-1</code> (the first basement level).</li>
<li><code>)))</code> and <code>)())())</code> both result in floor <code>-3</code>.</li>
</ul>

</article>
<p>Your puzzle answer was <code>74</code>.</p><article class="day-desc"><h2 id="part2">--- Part Two ---</h2><p>Now, given the same instructions, find the <b>position</b> of the first character that causes him to enter the basement (floor <code>-1</code>). The first character in the instructions has position <code>1</code>, the second character has position <code>2</code>, and so on.</p>

<ul>
<li><code>)</code> causes him to enter the basement at character position <code>1</code>.</li>
<li><code>()())</code> causes him to enter the basement at character position <code>5</code>.</li>
</ul>

</article>
<p>Your puzzle answer was <code>1795</code>.</p><p class="day-success"><b>Both parts of this puzzle are complete! They provide two gold stars: 🌟🌟</b></p>
<h2>--- Results ---</h2>
<pre><code>2015 Day01 - First Answer: 74
2015 Day01 - Second Answer: 1795
2015 Day01 - Execution finished in 0.0025238990783691 seconds.
</code></pre>
<pre><code>*** TESTING 2015 DAY Day01 ***
PHPUnit 9.5.10 by Sebastian Bergmann and contributors.

Day01 (mikeroq\AdventOfCode\AdventOfCode2015\Day01\Day01)
✔ Part 1 example five equals 3
✔ Part 1 example three equals negative 3
✔ Part 1 example one equals 0
✔ Part 2 example one character equals 1
✔ Part 2 example two character equals 5

Time: 00:00.008, Memory: 4.00 MB

OK (5 tests, 5 assertions)
</code></pre>
1 change: 1 addition & 0 deletions AdventOfCode2015/Day01/input.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
((((()(()(((((((()))(((()((((()())(())()(((()((((((()((()(()(((()(()((())))()((()()())))))))))()((((((())((()))(((((()(((((((((()()))((()(())()((())((()(()))((()))()))()(((((()(((()()))()())((()((((())()())()((((())()(()(()(((()(())(()(())(((((((())()()(((())(()(()(()(())))(()((((())((()))(((()(()()(((((()()(()(((()(((((())()))()((()(()))()((()((((())((((())(()(((())()()(()()()()()(())((((())((())(()()))()((((())))((((()())()((((())((()())((())(())(((((()((((()(((()((((())(()(((()()))()))((((((()((())()())))(((()(()))(()()(()(((()(()))((()()()())((()()()(((())())()())())())((()))(()(()))(((((()(()(())((()(())(())()((((()())()))((((())(())((())())((((()(((())(())((()()((((()((((((()(())()()(()(()()((((()))(())()())()))(())))(())))())()()(())(()))()((()(()(())()()))(()())))))(()))(()()))(())(((((()(()(()()((())()())))))((())())((())(()(())((()))(())(((()((((((((()()()(()))()()(((()))()((()()(())(())())()(()(())))(((((()(())(())(()))))())()))(()))()(()(((((((()((((())))())())())())()((((((((((((((()()((((((()()()())())()())())())(())(())))())((()())((()(()))))))()))))))))))))))))())((())((())()()))))))(((()((()(()()))((())(()()))()()())))(())))))))(()(((())))())()())))()()(())()))()(()))())((()()))))(()))))()))(()()(())))))))()(((()))))()(()))(())())))))()))((()))((()))())(())))))))))((((())()))()))()))())(())()()(())))())))(()())()))((()()(())))(())((((((()(())((()(((()(()()(())))()))))))()))()(()((()))()(()))(()(((())((((())())(())(()))))))))())))))))())())))))())))))()()(((())()(()))))))))())))))(())()()()))()))()))(()(())()()())())))))))())()(()(()))))()()()))))())(()))))()()))))()())))))(((())()()))(()))))))))))()()))))()()()))))(()())())()()())()(()))))()(()))(())))))))(((((())(())())()()))()()))(())))))()(()))))(())(()()))()())()))()))()))()))))())()()))())())))(()))(()))))))())()(((())()))))))))()))()())))())))())))()))))))))))()()))(()()))))))(())()(()))))())(()))))(()))))(()())))))())())()()))))())()))))))))(()))))()))))))()(()())))))))()))())))())))())))())))))))())(()()))))))(()())())))()())()))))))))))))))())))()(())))()))())()()(())(()()))(())))())()())(()(()(()))))())))))))))))())(()))()))()))))(())()())()())))))))))))()()))))))))))))())())))))(()())))))))))))())(())))()))))))))())())(()))()))(())))()))()()(())()))))))()((((())()))())())))))()))()))))((()())()))))())))(())))))))))))))))))()))))()()())()))()()))))())()))((()())))())))(()))(()())))))))()))()))))(())))))))(())))))())()()(()))())()))()()))))())()()))))())()))())))))))(()))))()())()))))))))(()))())))(()))()))))(())()))())())(())())())))))))((((())))))()))()))()())()(())))()))()))()())(()())()()(()())()))))())())))))(()))()))))())(()()(())))))(())()()((())())))))(())(())))))))())))))))))()(())))))))()())())())()(()))))))))(()))))))))())()()))()(()))))))()))))))())))))))(())))()()(())()())))))(((())))()((())()))())))(()()))())(())())))()(((()())))))()(()()())))()()(()()(()()))())()(()()()))())()()))()())(()))))())))))())))(())()()))))(()))))(())(()))(())))))()()))()))))())()))()()(())())))((()))())()))))))()()))))((()(()))))()()))))))())))))())(()((()())))))))))))()())())))()))(()))))))(()))(())()())))(()))))))))())()()()()))))(()())))))))((())))()))(()))(())(())()())()))))))))(())))())))(()))()()))(()()))(()))())))()(())))())((()((()(())))((())))()))))((((())())()())))(())))()))))))())(()()((())))())()(()())))))(()())()))())))))))((())())))))))(()(()))())()()(()()(((()(((()())))))()))))))()(())(()()((()()(())()()))())()())()))()())())())))))))(((())))))))()()))))))(((())()))(()()))(()()))))(()(()()((((())()())((()()))))(()(())))))()((()()()())()()((()((()()))(()))(((()()()))(((())))()(((())()))))))((()(())())))(()())(((((()(()))(()((()))(()())()))))(()(()))()(()))(())(((())(()()))))()()))(((()))))(()()()()))())))((()()()(())()))()))))()()))()))))))((((((()()()))))())((()()(((()))))(()(())(()()())())())))()(((()()))(())((())))(()))(()()()())((())())())(()))))()))()((()(())()(()()(())(()))(())()))(())(()))))(())(())())(()()(()((()()((())))((()))()((())))(((()()()()((((()))(()()))()()()(((())((())())(()()(()()()))()((())(())()))())(((()()(())))()((()()())()())(()(())())(((())(())())((())(())()(((()()))(())))((())(()())())(())((()()()((((((())))((()(((((())()))()))(())(()()))()))(())()()))(())((()()())()()(()))())()((())))()((()()())((((()())((())())())((()((()))()))((())((()()(()((()()(((())(()()))))((()((())()(((())(()((())())((())(()((((((())())()(()())()(())(((())((((((()(())(()((()()()((()()(()()()())))()()(((((()()))()((((((()))()(()(()(()(((()())((()))())()((()))(())))()))()()))())()()))())((((())(()(()))(((((((())(((()(((((()(((()()((((())(((())())))(()()()(()(()))()))((((((()))((()(((()(())((()((((()((((((())(((((())))(((()(()))))(((()(((())()((())(()((()))(((()()(((())((((()(()(((((()))(((()(((((((()(()()()(()(()(()()())(())(((((()(())())()())(()(()(()))()(()()()())(()()(()((()))()((())())()(()))((())(()))()(()))()(((()(()(()((((((()()()()())()(((((()()(((()()()((()(((((()))((((((((()()()(((((()))))))(()()()(())(()))(()()))))(())()))(((((()(((((()()(()(()())(((()))((((()((()(()(()((()(()((())))()(((()((()))((()))(((((((((()((()((()(())))()((((()((()()))((())(((()(((((()()(()(()()((()(()()()(((((((())())()())))))((((()()(()))()))(()((())()(()(((((((((()()(((()(()())(()((()())((())())((((()(((()(((()((((()((()((((()(()((((((())((((((((((((()()(()()((((((((((((((()((()()))()((((((((((((())((((()(()())((()(()(()))()(((((()()(((()()))()())(())((()(((((()((())(((((()((()(((((()))()()((((())()((((())(((((((((()(())(()(())))())(()((())(((())(())(())())(()(()(())()()((()((())()(((()(((((()(())))()(((()((())))((()()()(((()(((()((()(()(())(()((()())(()(()(((()(((((((((())(()((((()()))(()((((()()()()(((()((((((((()(()()((((((()(()()(()((()((((((((((()()(((((((()())(())))(((()()))(((((()((()()())(()()((((())((()((((()))))(())((()(()()(((()(()(((()((((()(((((()))())())(()((())()))(((()())((())((())((((()((()((((((())(()((((()()))((((((())()(()))((()(((())((((((((((()()(((((()(((((()((()()()((((())))(()))()((()(())()()((()((((((((((()((())(())(((((()(()(()()))((((()((((()()((()(((()(((((((((()(()((()((()))((((((()(((())()()((()(((((((()())))()()(()((()((()()(((()(()()()()((((()((())((((()(((((((((()(((()()(((()(()(((()(((()((())()(()((()(()(()(()))()(((()))(()((((()((())((((())((((((())(()))(()((((())((()(()((((((((()()((((((()(()(()()()(())((()((()()(((()(((((((()()((()(((((((()))(((((()(((()(()()()(()(((()((()()((())(()(((((((((()(()((()((((((()()((())()))(((((()((())()())()(((((((((((()))((((()()()()())(()()(()(()()))()))(()))(()(((()()))())(()(()))()()((())(()())()())()(()))()))(()()(()((((((())((()(((((((((((()(())()((()(()((()((()(()((()((((((((((()()())((())()(())))((())()())()(((((()(()())((((()((()(())(()))(((())()((()))(((((())(()))()()(()))(((())((((()((((()(())))(((((((()))))())()())(())((())()(()()((()(()))()(()()(()()((()())((())((()()))((((()))()()))(()()(())()()(((((()(())((()((((()))()))(()())())(((()()(()()))(())))))(()))((())(((((()((((()))()((((()))()((())(((())))(((()())))((()(()()((
3 changes: 3 additions & 0 deletions AdventOfCode2015/Day01/results.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
2015 Day01 - First Answer: 74
2015 Day01 - Second Answer: 1795
2015 Day01 - Execution finished in 0.0025238990783691 seconds.
13 changes: 13 additions & 0 deletions AdventOfCode2015/Day01/test_results.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
*** TESTING 2015 DAY Day01 ***
PHPUnit 9.5.10 by Sebastian Bergmann and contributors.

Day01 (mikeroq\AdventOfCode\AdventOfCode2015\Day01\Day01)
✔ Part 1 example five equals 3
✔ Part 1 example three equals negative 3
✔ Part 1 example one equals 0
✔ Part 2 example one character equals 1
✔ Part 2 example two character equals 5

Time: 00:00.008, Memory: 4.00 MB

OK (5 tests, 5 assertions)
58 changes: 58 additions & 0 deletions AdventOfCode2015/Day02/Day02.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<?php

namespace mikeroq\AdventOfCode\AdventOfCode2015\Day02;

use mikeroq\AdventOfCode\Shared\Day;

class Day02 extends Day
{
private array $packages = [];
private int $square_feet = 0;
private int $ribbon = 0;

protected function formatInput(): void
{
$this->explodeInputByNewLine();
foreach ($this->input as $package) {
$this->packages[] = explode("x", $package);
}
}

public function calcSquareFeet()
{
// 0 = l, 1 = w, 2 = h
// 2*l*w + 2*w*h + 2*h*l
foreach ($this->packages as $package) {
$area = [
($package[0]*$package[1]),
($package[1]*$package[2]),
($package[2]*$package[0])
];
$this->square_feet += array_sum($area)*2 + min($area);
}
}

public function calcRibbonRequired()
{
foreach ($this->packages as $package) {
$perimeters = [
2*($package[0] + $package[1]),
2*($package[1] + $package[2]),
2*($package[2] + $package[0])
];
$this->ribbon += min($perimeters) + array_product($package);
}
}

public function findFirstAnswer(): int
{
$this->calcSquareFeet();
return $this->square_feet;
}

public function findSecondAnswer(): int
{
$this->calcRibbonRequired();
return $this->ribbon;
}
}
25 changes: 25 additions & 0 deletions AdventOfCode2015/Day02/Day02Test.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php
namespace mikeroq\AdventOfCode\AdventOfCode2015\Day02;

use PHPUnit\Framework\TestCase;

final class Day02Test extends TestCase
{
// total is 101
public function testPart1Equals101(): void
{
$day02 = new Day02();
$day02->importInput('AdventOfCode2015/Day02/test_input.txt');

$this->assertEquals(101, $day02->findFirstAnswer());
}

public function testPart2Equals48(): void
{
$day02 = new Day02();
$day02->importInput('AdventOfCode2015/Day02/test_input.txt');

$this->assertEquals(48, $day02->findSecondAnswer());
}

}
35 changes: 35 additions & 0 deletions AdventOfCode2015/Day02/README.MD
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<article class="day-desc"><h2>--- Day 2: I Was Told There Would Be No Math ---</h2><p>The elves are running low on wrapping paper, and so they need to submit an order for more. They have a list of the dimensions (length <code>l</code>, width <code>w</code>, and height <code>h</code>) of each present, and only want to order exactly as much as they need.</p>
<p>Fortunately, every present is a box (a perfect <a href="https://en.wikipedia.org/wiki/Cuboid#Rectangular_cuboid">right rectangular prism</a>), which makes calculating the required wrapping paper for each gift a little easier: find the surface area of the box, which is <code>2*l*w + 2*w*h + 2*h*l</code>. The elves also need a little extra paper for each present: the area of the smallest side.</p>

<ul>
<li>A present with dimensions <code>2x3x4</code> requires <code>2*6 + 2*12 + 2*8 = 52</code> square feet of wrapping paper plus <code>6</code> square feet of slack, for a total of <code>58</code> square feet.</li>
<li>A present with dimensions <code>1x1x10</code> requires <code>2*1 + 2*10 + 2*10 = 42</code> square feet of wrapping paper plus <code>1</code> square foot of slack, for a total of <code>43</code> square feet.</li>
</ul>

</article>
<p>Your puzzle answer was <code>1598415</code>.</p><article class="day-desc"><h2 id="part2">--- Part Two ---</h2><p>The elves are also running low on ribbon. Ribbon is all the same width, so they only have to worry about the length they need to order, which they would again like to be exact.</p>
<p>The ribbon required to wrap a present is the shortest distance around its sides, or the smallest perimeter of any one face. Each present also requires a bow made out of ribbon as well; the feet of ribbon required for the perfect bow is equal to the cubic feet of volume of the present. Don't ask how they tie the bow, though; they'll never tell.</p>

<ul>
<li>A present with dimensions <code>2x3x4</code> requires <code>2+2+3+3 = 10</code> feet of ribbon to wrap the present plus <code>2*3*4 = 24</code> feet of ribbon for the bow, for a total of <code>34</code> feet.</li>
<li>A present with dimensions <code>1x1x10</code> requires <code>1+1+1+1 = 4</code> feet of ribbon to wrap the present plus <code>1*1*10 = 10</code> feet of ribbon for the bow, for a total of <code>14</code> feet.</li>
</ul>

</article>
<p>Your puzzle answer was <code>3812909</code>.</p><p class="day-success"><b>Both parts of this puzzle are complete! They provide two gold stars: 🌟🌟</b></p>
<h2>--- Results ---</h2>
<pre><code>2015 Day02 - First Answer: 1598415
2015 Day02 - Second Answer: 3812909
2015 Day02 - Execution finished in 0.0022399425506592 seconds.
</code></pre>
<pre><code>*** TESTING 2015 DAY Day02 ***
PHPUnit 9.5.10 by Sebastian Bergmann and contributors.

Day02 (mikeroq\AdventOfCode\AdventOfCode2015\Day02\Day02)
✔ Part 1 equals 101
✔ Part 2 equals 48

Time: 00:00.009, Memory: 4.00 MB

OK (2 tests, 2 assertions)
</code></pre>
Loading

0 comments on commit b0293be

Please sign in to comment.