summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJustin Wernick <justin@worthe-it.co.za>2020-12-08 20:56:43 +0200
committerJustin Wernick <justin@worthe-it.co.za>2020-12-08 20:56:43 +0200
commit60f0fce822527372135ead5ca2a4843ee9b8d31c (patch)
tree5132cd67ac4930ddfcefa78525a81b8bc33dd64e
parentcc9288b7e8bebaf5828d53ecd88ca316a1840b42 (diff)
Improvement!
-rw-r--r--src/bin/day_8.rs11
1 files changed, 6 insertions, 5 deletions
diff --git a/src/bin/day_8.rs b/src/bin/day_8.rs
index c7df9f5..2c0c227 100644
--- a/src/bin/day_8.rs
+++ b/src/bin/day_8.rs
@@ -1,7 +1,7 @@
use bevy::{app::AppExit, prelude::*};
-use std::fs::File;
+use std::convert::TryFrom;
use std::io::{BufRead, BufReader};
-use std::{collections::BTreeMap, convert::TryFrom};
+use std::{collections::BTreeSet, fs::File};
fn main() {
App::build()
@@ -45,7 +45,7 @@ struct Computer {
termiated: bool,
}
#[derive(Default)]
-struct LineTracker(BTreeMap<i32, usize>);
+struct LineTracker(BTreeSet<i32>);
impl Computer {
fn exec(&mut self, program: &Program) {
@@ -123,8 +123,7 @@ fn track_program_line_execution(
computer: &Computer,
unaltered: Option<&UnalteredProgram>,
) {
- *line_tracker.0.entry(computer.program_counter).or_insert(0) += 1;
- if *line_tracker.0.get(&computer.program_counter).unwrap() > 1 {
+ if line_tracker.0.contains(&computer.program_counter) {
if unaltered.is_some() {
println!(
"About to execute a line for the second time! Line {}. Accumulator: {}",
@@ -132,6 +131,8 @@ fn track_program_line_execution(
);
}
commands.despawn(entity);
+ } else {
+ line_tracker.0.insert(computer.program_counter);
}
}