Skip to content

Commit 406d22d

Browse files
committed
d6p2
1 parent 3820880 commit 406d22d

File tree

1 file changed

+8
-15
lines changed

1 file changed

+8
-15
lines changed

2017/day6/src/main.rs

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1-
use std::collections::HashSet;
1+
const BANK_QTY: usize = 16;
22

33
fn main() {
44
let input = "5 1 10 0 1 7 13 14 3 12 8 10 7 12 0 6";
5-
const BANK_QTY: usize = 16;
65

76
// setup memory banks
87
let mut banks: [u32; BANK_QTY] = [0; BANK_QTY];
@@ -12,22 +11,16 @@ fn main() {
1211
banks[index] = element.parse::<u32>().unwrap();
1312
}
1413

15-
let index = get_max_index(&banks);
16-
17-
let mut set = HashSet::new();
18-
let mut iteration = 0;
19-
14+
let mut history: Vec<_> = Vec::new();
2015

2116
let result = loop {
22-
// println!("{:?}", (banks));
23-
24-
// add array to hashset and check lengths
25-
set.insert(banks.clone());
26-
iteration += 1;
27-
28-
if iteration != set.len() {
29-
break set.len();
17+
// check if prev exists
18+
if history.iter().any(|&d| d == banks) {
19+
let pos = history.iter().position(|&p| p == banks).unwrap();
20+
break (pos, banks, history.iter().count() - pos);
3021
}
22+
// count it
23+
history.push(banks.clone());
3124

3225
// iterate
3326
let index = get_max_index(&banks);

0 commit comments

Comments
 (0)