1
0

added AOC 2020 data

This commit is contained in:
Mike Schwörer 2020-12-02 08:32:04 +01:00
parent 647e78575c
commit 8207ece48c
Signed by: Mikescher
GPG Key ID: D3C7172E0A70F8CF
16 changed files with 1467 additions and 14 deletions

View File

@ -1397,6 +1397,11 @@ html, body {
.bc_aoc_solution_value {
background: #888888;
color: #000000;
padding-left: 2px;
}
.bc_aoc_solution_value.multi {
border-top: 1px solid #333333;
}
.prgl_parent {

View File

@ -260,7 +260,8 @@ html,body{margin:0;padding:0;height:100%}
.bc_aoc_solution_parent{border:1px solid #333}
.bc_aoc_solution_code{padding:0}
.bc_aoc_solution_code pre{margin:0 !important;border:0}
.bc_aoc_solution_value{background:#888;color:#000}
.bc_aoc_solution_value{background:#888;color:#000;padding-left:2px}
.bc_aoc_solution_value.multi{border-top:1px solid #333}
.prgl_parent{display:flex;flex-direction:column}
@media(max-device-width:850px){.prgl_parent{align-items:center}}
.prgl_elem{display:flex;flex-direction:row;text-decoration:none;background:#bbb;border:1px solid #444;color:#333;margin:5px 0}

View File

@ -158,4 +158,9 @@
.bc_aoc_solution_value {
background: $LAYER2_HEADER_BG;
color: $LAYER2_HEADER_FG;
padding-left: 2px;
}
.bc_aoc_solution_value.multi {
border-top: $LAYER2_BORDER;
}

View File

@ -32,7 +32,7 @@ $FRAME_OPTIONS->alternative_url = "/adventofcode/$year";
</div>
<div class="bc_data">
<?php $SITE->renderMarkdown($SITE->modules->Blog()->getPostFragment($post)); ?>
<?php echo $SITE->renderMarkdown($SITE->modules->Blog()->getPostFragment($post)); ?>
<br/>
<?php echo $SITE->fragments->PanelAdventOfCodeCalendar($year, true, false, false); ?>
</div>

View File

@ -45,18 +45,34 @@ $FRAME_OPTIONS->alternative_url = $day['url-alternative'];
<div class="bc_aoc_input"><?php echo nl2br(htmlspecialchars(file_get_contents($day['file_input']))); ?></div>
<br/>
<?php for ($i=1; $i<=$day['parts']; $i++): ?>
<?php if ($day['single_solution_file']): ?>
<b>Part <?php echo $i; ?>:</b>
<div class="bc_aoc_solution_parent">
<div class="bc_aoc_solution_code">
<pre><code class="<?php echo $SITE->modules->AdventOfCode()->getLanguageCSS($day) ?>"><?php echo htmlspecialchars($SITE->modules->AdventOfCode()->getSolutionCode($day, $i-1)); ?></code></pre>
<pre><code class="<?php echo $SITE->modules->AdventOfCode()->getLanguageCSS($day) ?>"><?php echo htmlspecialchars($SITE->modules->AdventOfCode()->getSolutionCode($day, 0)); ?></code></pre>
</div>
<div class="bc_aoc_solution_value"><b>Result:</b> <?php echo $day['solutions'][$i-1]; ?></div>
<?php for ($i=1; $i<=$day['parts']; $i++): ?>
<div class="bc_aoc_solution_value multi"><b>Result Part <?= $i ?>:</b> <?php echo $day['solutions'][$i-1]; ?></div>
<?php endfor; ?>
</div>
<br/>
<?php endfor; ?>
<?php else: ?>
<?php for ($i=1; $i<=$day['parts']; $i++): ?>
<b>Part <?php echo $i; ?>:</b>
<div class="bc_aoc_solution_parent">
<div class="bc_aoc_solution_code">
<pre><code class="<?php echo $SITE->modules->AdventOfCode()->getLanguageCSS($day) ?>"><?php echo htmlspecialchars($SITE->modules->AdventOfCode()->getSolutionCode($day, $i-1)); ?></code></pre>
</div>
<div class="bc_aoc_solution_value"><b>Result:</b> <?php echo $day['solutions'][$i-1]; ?></div>
</div>
<br/>
<?php endfor; ?>
<?php endif; ?>
<?php $FRAME_OPTIONS->addScript("/data/javascript/prism.js", true); ?>
<?php $FRAME_OPTIONS->addStylesheet("/data/rawcss/prism.css"); ?>

View File

@ -4,9 +4,10 @@ class AdventOfCode implements IWebsiteModule
{
const YEARS =
[
'2017' => [ 'url-aoc'=>'https://adventofcode.com/2017/day/', 'blog-id' => 25, 'github' => 'https://github.com/Mikescher/AdventOfCode2017' ],
'2018' => [ 'url-aoc'=>'https://adventofcode.com/2018/day/', 'blog-id' => 23, 'github' => 'https://github.com/Mikescher/AdventOfCode2018' ],
'2019' => [ 'url-aoc'=>'https://adventofcode.com/2019/day/', 'blog-id' => 24, 'github' => 'https://github.com/Mikescher/AdventOfCode2019' ],
'2017' => [ 'url-aoc'=>'https://adventofcode.com/2017/day/', 'blog-id' => 25, 'github' => 'https://github.com/Mikescher/AdventOfCode2017', 'single_solution_file' => false ],
'2018' => [ 'url-aoc'=>'https://adventofcode.com/2018/day/', 'blog-id' => 23, 'github' => 'https://github.com/Mikescher/AdventOfCode2018', 'single_solution_file' => false ],
'2019' => [ 'url-aoc'=>'https://adventofcode.com/2019/day/', 'blog-id' => 24, 'github' => 'https://github.com/Mikescher/AdventOfCode2019', 'single_solution_file' => false ],
'2020' => [ 'url-aoc'=>'https://adventofcode.com/2020/day/', 'blog-id' => 26, 'github' => 'https://github.com/Mikescher/AdventOfCode2020', 'single_solution_file' => true ],
];
const LANGUAGES =
@ -80,6 +81,8 @@ class AdventOfCode implements IWebsiteModule
{
$yeardata = self::YEARS[$year];
$a['single_solution_file'] = $yeardata['single_solution_file'];
$n2p = str_pad($a['day'], 2, '0', STR_PAD_LEFT);
$a['day-padded'] = $n2p;
@ -97,9 +100,16 @@ class AdventOfCode implements IWebsiteModule
$solutionfiles = [];
for ($i=1; $i <= $a['parts']; $i++)
if ($a['single_solution_file'])
{
$solutionfiles []= (__DIR__ . '/../../statics/aoc/' . $year . '/' . $n2p . '_solution-' . $i . '.' . self::LANGUAGES[$a['language']]['ext']);
$solutionfiles []= (__DIR__ . '/../../statics/aoc/' . $year . '/' . $n2p . '_solution' . '.' . self::LANGUAGES[$a['language']]['ext']);
}
else
{
for ($i=1; $i <= $a['parts']; $i++)
{
$solutionfiles []= (__DIR__ . '/../../statics/aoc/' . $year . '/' . $n2p . '_solution-' . $i . '.' . self::LANGUAGES[$a['language']]['ext']);
}
}
$a['file_solutions'] = $solutionfiles;
@ -200,10 +210,15 @@ class AdventOfCode implements IWebsiteModule
if (in_array($aocdata['title'], $titlelist)) return ['result'=>'err', 'message' => 'Duplicate title ' . $aocdata['title']];
$titlelist []= $aocdata['title'];
if ($aocdata['day'] < 1 || $aocdata['day'] > 25) return ['result'=>'err', 'message' => 'Invali [day]-value title ' . $aocdata['day']];
if ($aocdata['day'] < 1 || $aocdata['day'] > 25) return ['result'=>'err', 'message' => 'Invalid [day]-value title ' . $aocdata['day']];
if (count($aocdata['solutions']) !== $aocdata['parts']) return ['result'=>'err', 'message' => 'Not enough solution-values in day' . $aocdata['day']];
if (count($aocdata['file_solutions']) !== $aocdata['parts']) return ['result'=>'err', 'message' => 'Not enough solution-files in day' . $aocdata['day']];
if ($aocdata['single_solution_file']) {
if (count($aocdata['file_solutions']) !== 1) return ['result'=>'err', 'message' => 'Not enough solution-files in day' . $aocdata['day']];
} else {
if (count($aocdata['file_solutions']) !== $aocdata['parts']) return ['result'=>'err', 'message' => 'Not enough solution-files in day' . $aocdata['day']];
}
if (!file_exists($aocdata['file_challenge'])) return ['result'=>'err', 'message' => 'file_challenge not found ' . $aocdata['file_challenge']];
if (!file_exists($aocdata['file_input'])) return ['result'=>'err', 'message' => 'file_input not found ' . $aocdata['file_input']];

View File

@ -128,6 +128,8 @@ class Blog implements IWebsiteModule
} else if ($post['type'] === 'aoc') {
if (!file_exists($post['file_fragment'])) return ['result'=>'err', 'message' => 'Fragment not found ' . $post['fragment']];
if (!array_key_exists('aoc:year', $post['extras'])) return ['result'=>'err', 'message' => 'AdventOfCode metadata [aoc:year] missing: ' . $post['title']];
// aok

View File

@ -0,0 +1,34 @@
--- Day 1: Report Repair ---
After saving Christmas five years in a row, you've decided to take a vacation at a nice resort on a tropical island. Surely, Christmas will go on without you.
The tropical island has its own currency and is entirely cash-only. The gold coins used there have a little picture of a starfish; the locals just call them stars. None of the currency exchanges seem to have heard of them, but somehow, you'll need to find fifty of these coins by the time you arrive so you can pay the deposit on your room.
To save your vacation, you need to get all fifty stars by December 25th.
Collect stars by solving 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 one star. Good luck!
Before you leave, the Elves in accounting just need you to fix your expense report (your puzzle input); apparently, something isn't quite adding up.
Specifically, they need you to find the two entries that sum to 2020 and then multiply those two numbers together.
For example, suppose your expense report contained the following:
1721
979
366
299
675
1456
In this list, the two entries that sum to 2020 are 1721 and 299. Multiplying them together produces 1721 * 299 = 514579, so the correct answer is 514579.
Of course, your expense report is much larger. Find the two entries that sum to 2020; what do you get if you multiply them together?
--- Part Two ---
The Elves in accounting are thankful for your help; one of them even offers you a starfish coin they had left over from a past vacation. They offer you a second one if you can find three numbers in your expense report that meet the same criteria.
Using the above example again, the three entries that sum to 2020 are 979, 366, and 675. Multiplying them together produces the answer, 241861950.
In your expense report, what is the product of the three entries that sum to 2020?

View File

@ -0,0 +1,200 @@
1597
1857
1703
1956
1809
1683
1629
230
1699
1875
1564
1700
1911
1776
1955
1585
1858
1725
1813
1568
1962
1535
487
1621
1620
1573
1918
1794
2003
1957
1840
1936
285
1630
1753
1649
1951
1968
1916
1694
1593
1980
1806
1779
1637
1674
1842
1659
1553
1846
1677
1944
1811
1645
1784
1791
1988
1864
1596
1773
1132
1715
1938
1901
1617
1892
1708
1788
1765
1684
1595
1971
1798
1543
507
1772
1757
1950
1844
1898
1671
1602
1599
1524
2005
1855
1624
1884
1990
1604
1873
1736
1747
1900
1534
1713
1690
1525
1838
587
74
1979
1635
1896
1580
1727
1994
1940
1819
1758
1852
1639
1754
1559
1919
1879
1874
1921
1575
1693
1710
1949
1719
1933
1673
1909
1989
1897
909
1889
1641
1658
1530
1541
1952
1627
1839
1803
833
1527
1756
2009
1605
1548
1660
1966
1770
1552
1939
1726
382
1665
1960
1733
1983
1544
1974
1985
1625
609
1931
1749
1975
1562
1563
1922
2008
2010
1704
1545
1636
1762
1841
1717
622
2007
1670
1771
1910
1978
1615
1805
1999
1643
1748
1531
1539
1787
1722
1111
1774
1540
1607
1902
1991
1763
1691
1812
1783
1579

View File

@ -0,0 +1,45 @@
use crate::common::AdventOfCodeDay;
pub struct Day01 {
input: Vec<i32>,
}
impl Day01 {
pub fn new() -> Self {
let input_bytes = include_bytes!("../res/01_input.txt");
let input = String::from_utf8_lossy(input_bytes);
let numbers = input.lines().map(|p| p.parse::<i32>().unwrap()).collect::<Vec<i32>>();
Self {
input: numbers
}
}
}
impl AdventOfCodeDay for Day01 {
fn task_1(&self) -> String {
for v1 in &self.input {
for v2 in &self.input {
if v1+v2 == 2020 {
return format!("{}", v1*v2);
}
}
}
panic!();
}
fn task_2(&self) -> String {
for v1 in &self.input {
for v2 in &self.input {
for v3 in &self.input {
if v1+v2+v3 == 2020 {
return format!("{}", v1*v2*v3);
}
}
}
}
panic!();
}
}

View File

@ -0,0 +1,37 @@
--- Day 2: Password Philosophy ---
Your flight departs in a few days from the coastal airport; the easiest way down to the coast from here is via toboggan.
The shopkeeper at the North Pole Toboggan Rental Shop is having a bad day. "Something's wrong with our computers; we can't log in!" You ask if you can take a look.
Their password database seems to be a little corrupted: some of the passwords wouldn't have been allowed by the Official Toboggan Corporate Policy that was in effect when they were chosen.
To try to debug the problem, they have created a list (your puzzle input) of passwords (according to the corrupted database) and the corporate policy when that password was set.
For example, suppose you have the following list:
1-3 a: abcde
1-3 b: cdefg
2-9 c: ccccccccc
Each line gives the password policy and then the password. The password policy indicates the lowest and highest number of times a given letter must appear for the password to be valid. For example, 1-3 a means that the password must contain a at least 1 time and at most 3 times.
In the above example, 2 passwords are valid. The middle password, cdefg, is not; it contains no instances of b, but needs at least 1. The first and third passwords are valid: they contain one a or nine c, both within the limits of their respective policies.
How many passwords are valid according to their policies?
--- Part Two ---
While it appears you validated the passwords correctly, they don't seem to be what the Official Toboggan Corporate Authentication System is expecting.
The shopkeeper suddenly realizes that he just accidentally explained the password policy rules from his old job at the sled rental place down the street! The Official Toboggan Corporate Policy actually works a little differently.
Each policy actually describes two positions in the password, where 1 means the first character, 2 means the second character, and so on. (Be careful; Toboggan Corporate Policies have no concept of "index zero"!) Exactly one of these positions must contain the given letter. Other occurrences of the letter are irrelevant for the purposes of policy enforcement.
Given the same example list from above:
1-3 a: abcde is valid: position 1 contains a and position 3 does not.
1-3 b: cdefg is invalid: neither position 1 nor position 3 contains b.
2-9 c: ccccccccc is invalid: both position 2 and position 9 contain c.
How many passwords are valid according to the new interpretation of the policies?

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,68 @@
use crate::common::AdventOfCodeDay;
use std::convert::TryInto;
#[derive(Debug)]
struct Data {
num1: i32,
num2: i32,
character: char,
password: String,
}
pub struct Day02 {
input: Vec<Data>,
}
impl Day02 {
pub fn new() -> Self {
let input_bytes = include_bytes!("../res/02_input.txt");
let input_str = String::from_utf8_lossy(input_bytes);
let lines = input_str
.lines()
.map(|p| p.split(" ").map(String::from).collect::<Vec<String>>())
.map(|p| Data
{
num1: p[0].split("-").nth(0).unwrap().parse::<i32>().unwrap(),
num2: p[0].split("-").nth(1).unwrap().parse::<i32>().unwrap(),
character: p[1].chars().nth(0).unwrap(),
password: p[2].to_owned(),
})
.collect::<Vec<Data>>();
Self {
input: lines
}
}
}
impl AdventOfCodeDay for Day02 {
fn task_1(&self) -> String {
//for v in &self.input { println!("{:?}", v); }
return self.input.iter().filter(|p|
{
return (p.password.chars().filter(|c| *c == p.character).count() as i32) >= p.num1 &&
(p.password.chars().filter(|c| *c == p.character).count() as i32) <= p.num2;
})
.count()
.to_string()
}
fn task_2(&self) -> String {
return self.input
.iter()
.filter(|p|
{
let c1 = ((p.password.len() as i32) > p.num1-1) && p.password.chars().nth((p.num1 - 1).try_into().unwrap()).unwrap() == p.character;
let c2 = ((p.password.len() as i32) > p.num2-1) && p.password.chars().nth((p.num2 - 1).try_into().unwrap()).unwrap() == p.character;
return c1 ^ c2;
})
.count()
.to_string()
}
}

View File

@ -68,4 +68,9 @@ return
['day' => 24, 'parts' => 2, 'title' => 'Planet of Discord', 'language' => 'ts', 'solutions' => ['25719471', '1916'] ],
['day' => 25, 'parts' => 1, 'title' => 'Cryostasis', 'language' => 'ts', 'solutions' => ['2236672'] ],
],
'2020' =>
[
['day' => 1, 'parts' => 2, 'title' => 'Report Repair', 'language' => 'rust', 'solutions' => ['1009899', '44211152'] ],
['day' => 2, 'parts' => 2, 'title' => 'Password Philosophy', 'language' => 'rust', 'solutions' => ['564', '325'] ],
],
];

View File

@ -27,4 +27,5 @@ return
[ 'id' => 23, 'date' => '2018-12-01', 'visible' => true, 'title' => 'Advent of Code 2018', 'fragment' => 'aoc2018.md', 'type' => 'aoc', 'cat' => 'blog', 'extras' => ['aoc:year' => '2018'] ],
[ 'id' => 24, 'date' => '2019-12-01', 'visible' => true, 'title' => 'Advent of Code 2019', 'fragment' => 'aoc2019.md', 'type' => 'aoc', 'cat' => 'blog', 'extras' => ['aoc:year' => '2019'] ],
[ 'id' => 25, 'date' => '2020-01-09', 'visible' => true, 'title' => 'Advent of Code 2017', 'fragment' => 'aoc2017.md', 'type' => 'aoc', 'cat' => 'blog', 'extras' => ['aoc:year' => '2017'] ],
[ 'id' => 26, 'date' => '2020-12-01', 'visible' => true, 'title' => 'Advent of Code 2020', 'fragment' => 'aoc2020.md', 'type' => 'aoc', 'cat' => 'blog', 'extras' => ['aoc:year' => '2020'] ],
];

View File

@ -0,0 +1,19 @@
Not much to talk about this time.
I decided to try out rust this year (I have little experience, but I'm still fighting against the borrow-checker...)
I'm a bit sad I can't make a nice [web version](https://mikescher.github.io/AdventOfCode2019/) as last year (with typescript) so you either have to believe my solutions or compile/run it local:
~~~
> run with cargo run {arguments}:
Usage:
advent_of_code_2020 help
advent_of_code_2020 <day>
advent_of_code_2020 <day> <task>
advent_of_code_2020 all
advent_of_code_2020 table
Options:
-h --help
-b --benchmark
~~~