Correct formatting.

This commit is contained in:
2019-02-18 15:13:48 +01:00
parent 171d9fa2e9
commit c16ef40d73
28 changed files with 316 additions and 195 deletions

View File

@@ -6,8 +6,8 @@ use std::io::Read;
use regex::Regex;
use common::Solution;
use cpu::CPU;
use cpu::OpCode;
use cpu::CPU;
pub struct Day16 {
matcher: Regex,
@@ -38,12 +38,27 @@ impl Day16 {
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] {
let mut mappings: [HashSet<OpCode>; 16] = [
HashSet::new(), HashSet::new(), HashSet::new(), HashSet::new(),
HashSet::new(), HashSet::new(), HashSet::new(), HashSet::new(),
HashSet::new(), HashSet::new(), HashSet::new(), HashSet::new(),
HashSet::new(), HashSet::new(), HashSet::new(), HashSet::new(),
HashSet::new(),
HashSet::new(),
HashSet::new(),
HashSet::new(),
HashSet::new(),
HashSet::new(),
HashSet::new(),
HashSet::new(),
HashSet::new(),
HashSet::new(),
HashSet::new(),
HashSet::new(),
HashSet::new(),
HashSet::new(),
HashSet::new(),
HashSet::new(),
];
let mut before = [0; 6];
let mut op = [0; 4];
@@ -54,11 +69,10 @@ impl Day16 {
reader.read_line(&mut self.buf).unwrap_or(0);
if mappings[op[0] as usize].is_empty() {
mappings[op[0] as usize].extend(OpCode::values()
.filter(|x| x.is_valid(&op, &before, &after)));
mappings[op[0] as usize]
.extend(OpCode::values().filter(|x| x.is_valid(&op, &before, &after)));
} else {
for option in OpCode::values()
.filter(|x| !x.is_valid(&op, &before, &after)) {
for option in OpCode::values().filter(|x| !x.is_valid(&op, &before, &after)) {
mappings[op[0] as usize].remove(&option);
}
continue;
@@ -149,7 +163,6 @@ impl Solution for Day16 {
}
}
#[cfg(test)]
mod tests {
use common::Solution;