Implement day 21.

This commit is contained in:
2018-12-21 13:54:12 +01:00
parent 92e305db46
commit 71c18e44e1
4 changed files with 78 additions and 28 deletions

View File

@@ -72,8 +72,10 @@ day_bench!(day17, 17);
day_bench!(day18, 18); day_bench!(day18, 18);
day_bench!(day19, 19); day_bench!(day19, 19);
day_bench!(day20, 20); day_bench!(day20, 20);
day_bench!(day21, 21);
benchmark_main!(day01, day02, day03, day04, day05, benchmark_main!(day01, day02, day03, day04, day05,
day06, day07, day08, day09, day10, day06, day07, day08, day09, day10,
day11, day12, day13, day14, day15, day11, day12, day13, day14, day15,
day16, day17, day18, day19, day20); day16, day17, day18, day19, day20,
day21);

View File

@@ -32,10 +32,10 @@ z
<defs> <defs>
<path d="M 0 0 <path d="M 0 0
L 0 3.5 L 0 3.5
" id="me1cf09a1d9" style="stroke:#000000;stroke-width:0.8;"/> " id="mec9193305a" style="stroke:#000000;stroke-width:0.8;"/>
</defs> </defs>
<g> <g>
<use style="stroke:#000000;stroke-width:0.8;" x="60.305455" xlink:href="#me1cf09a1d9" y="307.584"/> <use style="stroke:#000000;stroke-width:0.8;" x="60.305455" xlink:href="#mec9193305a" y="307.584"/>
</g> </g>
</g> </g>
<g id="text_1"> <g id="text_1">
@@ -71,7 +71,7 @@ z
<g id="xtick_2"> <g id="xtick_2">
<g id="line2d_2"> <g id="line2d_2">
<g> <g>
<use style="stroke:#000000;stroke-width:0.8;" x="127.941818" xlink:href="#me1cf09a1d9" y="307.584"/> <use style="stroke:#000000;stroke-width:0.8;" x="127.941818" xlink:href="#mec9193305a" y="307.584"/>
</g> </g>
</g> </g>
<g id="text_2"> <g id="text_2">
@@ -110,7 +110,7 @@ z
<g id="xtick_3"> <g id="xtick_3">
<g id="line2d_3"> <g id="line2d_3">
<g> <g>
<use style="stroke:#000000;stroke-width:0.8;" x="195.578182" xlink:href="#me1cf09a1d9" y="307.584"/> <use style="stroke:#000000;stroke-width:0.8;" x="195.578182" xlink:href="#mec9193305a" y="307.584"/>
</g> </g>
</g> </g>
<g id="text_3"> <g id="text_3">
@@ -139,7 +139,7 @@ z
<g id="xtick_4"> <g id="xtick_4">
<g id="line2d_4"> <g id="line2d_4">
<g> <g>
<use style="stroke:#000000;stroke-width:0.8;" x="263.214545" xlink:href="#me1cf09a1d9" y="307.584"/> <use style="stroke:#000000;stroke-width:0.8;" x="263.214545" xlink:href="#mec9193305a" y="307.584"/>
</g> </g>
</g> </g>
<g id="text_4"> <g id="text_4">
@@ -153,7 +153,7 @@ z
<g id="xtick_5"> <g id="xtick_5">
<g id="line2d_5"> <g id="line2d_5">
<g> <g>
<use style="stroke:#000000;stroke-width:0.8;" x="330.850909" xlink:href="#me1cf09a1d9" y="307.584"/> <use style="stroke:#000000;stroke-width:0.8;" x="330.850909" xlink:href="#mec9193305a" y="307.584"/>
</g> </g>
</g> </g>
<g id="text_5"> <g id="text_5">
@@ -193,7 +193,7 @@ z
<g id="xtick_6"> <g id="xtick_6">
<g id="line2d_6"> <g id="line2d_6">
<g> <g>
<use style="stroke:#000000;stroke-width:0.8;" x="398.487273" xlink:href="#me1cf09a1d9" y="307.584"/> <use style="stroke:#000000;stroke-width:0.8;" x="398.487273" xlink:href="#mec9193305a" y="307.584"/>
</g> </g>
</g> </g>
<g id="text_6"> <g id="text_6">
@@ -286,10 +286,10 @@ z
<defs> <defs>
<path d="M 0 0 <path d="M 0 0
L -3.5 0 L -3.5 0
" id="m480ecff4e3" style="stroke:#000000;stroke-width:0.8;"/> " id="mcf4dca2140" style="stroke:#000000;stroke-width:0.8;"/>
</defs> </defs>
<g> <g>
<use style="stroke:#000000;stroke-width:0.8;" x="57.6" xlink:href="#m480ecff4e3" y="295.488"/> <use style="stroke:#000000;stroke-width:0.8;" x="57.6" xlink:href="#mcf4dca2140" y="295.488"/>
</g> </g>
</g> </g>
<g id="text_8"> <g id="text_8">
@@ -302,7 +302,7 @@ L -3.5 0
<g id="ytick_2"> <g id="ytick_2">
<g id="line2d_8"> <g id="line2d_8">
<g> <g>
<use style="stroke:#000000;stroke-width:0.8;" x="57.6" xlink:href="#m480ecff4e3" y="247.488"/> <use style="stroke:#000000;stroke-width:0.8;" x="57.6" xlink:href="#mcf4dca2140" y="247.488"/>
</g> </g>
</g> </g>
<g id="text_9"> <g id="text_9">
@@ -316,7 +316,7 @@ L -3.5 0
<g id="ytick_3"> <g id="ytick_3">
<g id="line2d_9"> <g id="line2d_9">
<g> <g>
<use style="stroke:#000000;stroke-width:0.8;" x="57.6" xlink:href="#m480ecff4e3" y="199.488"/> <use style="stroke:#000000;stroke-width:0.8;" x="57.6" xlink:href="#mcf4dca2140" y="199.488"/>
</g> </g>
</g> </g>
<g id="text_10"> <g id="text_10">
@@ -331,7 +331,7 @@ L -3.5 0
<g id="ytick_4"> <g id="ytick_4">
<g id="line2d_10"> <g id="line2d_10">
<g> <g>
<use style="stroke:#000000;stroke-width:0.8;" x="57.6" xlink:href="#m480ecff4e3" y="151.488"/> <use style="stroke:#000000;stroke-width:0.8;" x="57.6" xlink:href="#mcf4dca2140" y="151.488"/>
</g> </g>
</g> </g>
<g id="text_11"> <g id="text_11">
@@ -346,7 +346,7 @@ L -3.5 0
<g id="ytick_5"> <g id="ytick_5">
<g id="line2d_11"> <g id="line2d_11">
<g> <g>
<use style="stroke:#000000;stroke-width:0.8;" x="57.6" xlink:href="#m480ecff4e3" y="103.488"/> <use style="stroke:#000000;stroke-width:0.8;" x="57.6" xlink:href="#mcf4dca2140" y="103.488"/>
</g> </g>
</g> </g>
<g id="text_12"> <g id="text_12">
@@ -361,7 +361,7 @@ L -3.5 0
<g id="ytick_6"> <g id="ytick_6">
<g id="line2d_12"> <g id="line2d_12">
<g> <g>
<use style="stroke:#000000;stroke-width:0.8;" x="57.6" xlink:href="#m480ecff4e3" y="55.488"/> <use style="stroke:#000000;stroke-width:0.8;" x="57.6" xlink:href="#mcf4dca2140" y="55.488"/>
</g> </g>
</g> </g>
<g id="text_13"> <g id="text_13">
@@ -577,7 +577,7 @@ z
</g> </g>
</g> </g>
<g id="line2d_13"> <g id="line2d_13">
<path clip-path="url(#p431c152dea)" d="M 73.832727 282.048 <path clip-path="url(#p16eef5b12e)" d="M 73.832727 282.048
L 87.36 277.248 L 87.36 277.248
L 100.887273 270.528 L 100.887273 270.528
L 114.414545 269.568 L 114.414545 269.568
@@ -597,7 +597,7 @@ L 290.269091 266.688
L 303.796364 263.808 L 303.796364 263.808
L 317.323636 278.208 L 317.323636 278.208
L 330.850909 270.528 L 330.850909 270.528
L 344.378182 289.728 L 344.378182 283.008
L 357.905455 289.728 L 357.905455 289.728
L 371.432727 289.728 L 371.432727 289.728
L 384.96 289.728 L 384.96 289.728
@@ -605,7 +605,7 @@ L 398.487273 289.728
" style="fill:none;stroke:#1f77b4;stroke-linecap:square;stroke-width:1.5;"/> " style="fill:none;stroke:#1f77b4;stroke-linecap:square;stroke-width:1.5;"/>
</g> </g>
<g id="line2d_14"> <g id="line2d_14">
<path clip-path="url(#p431c152dea)" d="M 73.832727 295.488 <path clip-path="url(#p16eef5b12e)" d="M 73.832727 295.488
L 87.36 293.568 L 87.36 293.568
L 100.887273 295.488 L 100.887273 295.488
L 114.414545 295.488 L 114.414545 295.488
@@ -633,7 +633,7 @@ L 398.487273 295.488
" style="fill:none;stroke:#ff7f0e;stroke-linecap:square;stroke-width:1.5;"/> " style="fill:none;stroke:#ff7f0e;stroke-linecap:square;stroke-width:1.5;"/>
</g> </g>
<g id="line2d_15"> <g id="line2d_15">
<path clip-path="url(#p431c152dea)" d="M 73.832727 232.128 <path clip-path="url(#p16eef5b12e)" d="M 73.832727 232.128
L 87.36 218.688 L 87.36 218.688
L 100.887273 208.128 L 100.887273 208.128
L 114.414545 191.808 L 114.414545 191.808
@@ -653,7 +653,7 @@ L 290.269091 176.448
L 303.796364 143.808 L 303.796364 143.808
L 317.323636 225.408 L 317.323636 225.408
L 330.850909 140.928 L 330.850909 140.928
L 344.378182 277.248 L 344.378182 237.888
L 357.905455 277.248 L 357.905455 277.248
L 371.432727 277.248 L 371.432727 277.248
L 384.96 277.248 L 384.96 277.248
@@ -870,7 +870,7 @@ L 348.72625 83.926688
</g> </g>
</g> </g>
<defs> <defs>
<clipPath id="p431c152dea"> <clipPath id="p16eef5b12e">
<rect height="266.112" width="357.12" x="57.6" y="41.472"/> <rect height="266.112" width="357.12" x="57.6" y="41.472"/>
</clipPath> </clipPath>
</defs> </defs>

Before

Width:  |  Height:  |  Size: 25 KiB

After

Width:  |  Height:  |  Size: 25 KiB

View File

@@ -19,7 +19,7 @@ def preamble():
int c = 0; int c = 0;
int d = 0; int d = 0;
int e = 0; int e = 0;
int f = 0;''') int f = 0;\n''')
def footer(): def footer():

View File

@@ -1,9 +1,48 @@
use std::collections::HashSet;
use std::io::Read; use std::io::Read;
use common::Solution; use common::Solution;
#[derive(Default)] #[derive(Default)]
pub struct Day21 {} pub struct Day21 {
}
struct ValidInputs {
f: i64
}
impl ValidInputs {
pub fn new(start: i64) -> Self {
ValidInputs {
f: start
}
}
}
impl Iterator for ValidInputs {
type Item = i64;
fn next(&mut self) -> Option<i64> {
let mut f = self.f;
let mut e = f | 0x10000;
f = 13284195;
loop {
let d = e & 0xff;
f += d;
f &= 0xffffff;
f *= 65899;
f &= 0xffffff;
if 0x100 > e {
self.f = f;
return Some(f);
}
e >>= 8;
}
}
}
impl Day21 { impl Day21 {
pub fn new() -> Self { pub fn new() -> Self {
@@ -13,13 +52,22 @@ impl Day21 {
impl Solution for Day21 { impl Solution for Day21 {
fn part1(&mut self, _input: &mut Read) -> String { fn part1(&mut self, _input: &mut Read) -> String {
unimplemented!() format!("{}", ValidInputs::new(0).next().unwrap())
} }
fn part2(&mut self, _input: &mut Read) -> String { fn part2(&mut self, _input: &mut Read) -> String {
unimplemented!() let inputs = ValidInputs::new(0);
let mut seen = HashSet::new();
let mut last = None;
for input in inputs {
if seen.contains(&input) {
return format!("{}", last.unwrap());
} else {
last = Some(input);
seen.insert(input);
}
}
unreachable!();
} }
} }
#[cfg(test)]
mod tests {}