aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorGravatar alecdwm 2018-12-02 22:26:59 +1000
committerGravatar alecdwm 2018-12-02 22:26:59 +1000
commit3f1bdbf5a4b345c8d1e7d946d9c6878390a967e6 (patch)
treeed51bada3ebd3ebf400d714072df80fa4a5f7c3d /src
parent5ab86f420a63d19356873a9bb4f820ebc97073bc (diff)
use BTreeSet instead of BTreeMap for day1::part2
Diffstat (limited to 'src')
-rw-r--r--src/day1.rs8
1 files changed, 4 insertions, 4 deletions
diff --git a/src/day1.rs b/src/day1.rs
index b3b1dd5..4b2e014 100644
--- a/src/day1.rs
+++ b/src/day1.rs
@@ -6,7 +6,7 @@
//!
//! 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!
-use std::collections::BTreeMap;
+use std::collections::BTreeSet;
#[derive(Debug)]
struct FrequencyChange {
@@ -80,17 +80,17 @@ pub fn part2() {
let changes = build_changes(input);
let mut frequency: i64 = 0;
- let mut frequency_seen: BTreeMap<i64, bool> = BTreeMap::new();
+ let mut frequency_seen: BTreeSet<i64> = BTreeSet::new();
'find_duplicate: loop {
for change in changes.iter() {
frequency = match change.operation {
FrequencyOperation::Add => frequency + change.magnitude,
FrequencyOperation::Subtract => frequency - change.magnitude,
};
- if frequency_seen.contains_key(&frequency) {
+ if frequency_seen.contains(&frequency) {
break 'find_duplicate;
}
- frequency_seen.insert(frequency, true);
+ frequency_seen.insert(frequency);
}
}