Day 15, switch to vec for more performance
This commit is contained in:
parent
ce55569030
commit
739b17dd32
1 changed files with 4 additions and 5 deletions
|
@ -1,9 +1,8 @@
|
|||
use aoc_runner_derive::{aoc, aoc_generator};
|
||||
use std::collections::BTreeMap;
|
||||
use std::{collections::VecDeque, io::Write};
|
||||
use std::collections::HashMap;
|
||||
type Data = Vec<usize>;
|
||||
|
||||
#[derive(Debug)]
|
||||
#[derive(Debug,Clone)]
|
||||
enum Seen {
|
||||
Never,
|
||||
Once(usize),
|
||||
|
@ -45,11 +44,11 @@ pub fn input_generator(input: &str) -> Data {
|
|||
}
|
||||
|
||||
fn get_number(start: &[usize], num_turns: usize) -> usize {
|
||||
let mut cache: BTreeMap<usize, Seen> = BTreeMap::new();
|
||||
let mut cache = vec![Seen::Never;num_turns];
|
||||
let mut nums = start.to_vec();
|
||||
let mut num=std::usize::MAX;
|
||||
for i in 1..num_turns {
|
||||
num = cache.entry(nums[i - 1]).or_default().add(i);
|
||||
num = cache[nums[i - 1]].add(i);
|
||||
if i >= nums.len() {
|
||||
nums.push(num);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue