More cleanup.

This commit is contained in:
2018-12-19 08:25:15 +01:00
parent 68c5809e43
commit 9d1fdc63c9
3 changed files with 34 additions and 35 deletions

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="mf5f6461c1c" style="stroke:#000000;stroke-width:0.8;"/> " id="m6ad9c1a3cf" style="stroke:#000000;stroke-width:0.8;"/>
</defs> </defs>
<g> <g>
<use style="stroke:#000000;stroke-width:0.8;" x="60.305455" xlink:href="#mf5f6461c1c" y="307.584"/> <use style="stroke:#000000;stroke-width:0.8;" x="60.305455" xlink:href="#m6ad9c1a3cf" 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="#mf5f6461c1c" y="307.584"/> <use style="stroke:#000000;stroke-width:0.8;" x="127.941818" xlink:href="#m6ad9c1a3cf" 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="#mf5f6461c1c" y="307.584"/> <use style="stroke:#000000;stroke-width:0.8;" x="195.578182" xlink:href="#m6ad9c1a3cf" 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="#mf5f6461c1c" y="307.584"/> <use style="stroke:#000000;stroke-width:0.8;" x="263.214545" xlink:href="#m6ad9c1a3cf" 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="#mf5f6461c1c" y="307.584"/> <use style="stroke:#000000;stroke-width:0.8;" x="330.850909" xlink:href="#m6ad9c1a3cf" 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="#mf5f6461c1c" y="307.584"/> <use style="stroke:#000000;stroke-width:0.8;" x="398.487273" xlink:href="#m6ad9c1a3cf" 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="m043448939c" style="stroke:#000000;stroke-width:0.8;"/> " id="ma681a2b43a" style="stroke:#000000;stroke-width:0.8;"/>
</defs> </defs>
<g> <g>
<use style="stroke:#000000;stroke-width:0.8;" x="57.6" xlink:href="#m043448939c" y="295.488"/> <use style="stroke:#000000;stroke-width:0.8;" x="57.6" xlink:href="#ma681a2b43a" 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="#m043448939c" y="247.488"/> <use style="stroke:#000000;stroke-width:0.8;" x="57.6" xlink:href="#ma681a2b43a" 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="#m043448939c" y="199.488"/> <use style="stroke:#000000;stroke-width:0.8;" x="57.6" xlink:href="#ma681a2b43a" 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="#m043448939c" y="151.488"/> <use style="stroke:#000000;stroke-width:0.8;" x="57.6" xlink:href="#ma681a2b43a" 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="#m043448939c" y="103.488"/> <use style="stroke:#000000;stroke-width:0.8;" x="57.6" xlink:href="#ma681a2b43a" 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="#m043448939c" y="55.488"/> <use style="stroke:#000000;stroke-width:0.8;" x="57.6" xlink:href="#ma681a2b43a" 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(#p8a15f99017)" d="M 73.832727 282.048 <path clip-path="url(#p7bdb0fff69)" 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
@@ -592,7 +592,7 @@ L 222.632727 267.648
L 236.16 265.728 L 236.16 265.728
L 249.687273 277.248 L 249.687273 277.248
L 263.214545 251.328 L 263.214545 251.328
L 276.741818 267.648 L 276.741818 266.688
L 290.269091 266.688 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
@@ -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(#p8a15f99017)" d="M 73.832727 295.488 <path clip-path="url(#p7bdb0fff69)" 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(#p8a15f99017)" d="M 73.832727 232.128 <path clip-path="url(#p7bdb0fff69)" 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
@@ -648,7 +648,7 @@ L 222.632727 173.568
L 236.16 95.808 L 236.16 95.808
L 249.687273 205.248 L 249.687273 205.248
L 263.214545 53.568 L 263.214545 53.568
L 276.741818 165.888 L 276.741818 167.808
L 290.269091 176.448 L 290.269091 176.448
L 303.796364 143.808 L 303.796364 143.808
L 317.323636 223.488 L 317.323636 223.488
@@ -870,7 +870,7 @@ L 348.72625 83.926688
</g> </g>
</g> </g>
<defs> <defs>
<clipPath id="p8a15f99017"> <clipPath id="p7bdb0fff69">
<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

@@ -6,8 +6,8 @@ use std::io::Read;
use regex::Regex; use regex::Regex;
use common::Solution; use common::Solution;
use cpu::OpCode;
use cpu::CPU; use cpu::CPU;
use cpu::OpCode;
pub struct Day16 { pub struct Day16 {
matcher: Regex, matcher: Regex,
@@ -17,7 +17,7 @@ pub struct Day16 {
impl Day16 { impl Day16 {
pub fn new() -> Self { pub fn new() -> Self {
Day16 { Day16 {
matcher: Regex::new(r"(\d+),? (\d+),? (\d+),? (\d+)").unwrap(), matcher: Regex::new(r"\d+").unwrap(),
buf: String::new(), buf: String::new(),
} }
} }
@@ -28,15 +28,14 @@ impl Day16 {
return false; return false;
} }
if let Some(captures) = self.matcher.captures(&self.buf) { let mut found = false;
for (target, cap) in target.iter_mut().zip(captures.iter().skip(1)) {
*target = cap.unwrap().as_str().parse().unwrap();
}
true for (target, num) in target.iter_mut().zip(self.matcher.find_iter(&self.buf)) {
} else { *target = num.as_str().parse().unwrap();
false found = true
} }
found
} }
fn determine_options(&mut self, mut reader: &mut BufReader<&mut Read>) -> [HashSet<OpCode>; 16] { fn determine_options(&mut self, mut reader: &mut BufReader<&mut Read>) -> [HashSet<OpCode>; 16] {
@@ -49,9 +48,9 @@ impl Day16 {
let mut before = [0; 6]; let mut before = [0; 6];
let mut op = [0; 4]; let mut op = [0; 4];
let mut after = [0; 6]; let mut after = [0; 6];
while self.read(&mut reader, &mut before[..4]) { while self.read(&mut reader, &mut before) {
self.read(&mut reader, &mut op); self.read(&mut reader, &mut op);
self.read(&mut reader, &mut after[..4]); self.read(&mut reader, &mut after);
reader.read_line(&mut self.buf).unwrap_or(0); reader.read_line(&mut self.buf).unwrap_or(0);
if mappings[op[0] as usize].is_empty() { if mappings[op[0] as usize].is_empty() {
@@ -114,9 +113,9 @@ impl Solution for Day16 {
let mut after = [0; 6]; let mut after = [0; 6];
let mut counter = 0; let mut counter = 0;
while self.read(&mut reader, &mut before[..4]) { while self.read(&mut reader, &mut before) {
self.read(&mut reader, &mut op); self.read(&mut reader, &mut op);
self.read(&mut reader, &mut after[..4]); self.read(&mut reader, &mut after);
reader.read_line(&mut self.buf).unwrap_or(0); reader.read_line(&mut self.buf).unwrap_or(0);
let valid = OpCode::values() let valid = OpCode::values()

View File

@@ -28,8 +28,8 @@ impl Day19 {
let mut parts = line.split(' '); let mut parts = line.split(' ');
let opcode = OpCode::from(parts.next().unwrap()); let opcode = OpCode::from(parts.next().unwrap());
let mut operands = [0; 3]; let mut operands = [0; 3];
for i in 0..3 { for (target, part) in operands.iter_mut().zip(parts) {
operands[i] = parts.next().unwrap().parse().unwrap(); *target = part.parse().unwrap();
} }
self.program.push((opcode, operands)); self.program.push((opcode, operands));