Ryan is an engineer in the Sacramento Area with a focus in Python, Ruby, and Rust. Bash/Python Exercism mentor. Coding, physics, calculus, music, woodworking. Looking for work!
I found out (seems like a lot of other people did too) that rotating a doubly-linked list is way faster than inserting/removing with indices. Still felt like a boss when my code cranked through seven million possibilities in a few seconds :) Man, I love coding.
/// Day 9: Marble Mania/// /// Figure out the scores of elves playing marblesusestd::collections::VecDeque;/// Calculate what the highest player's score ispubfnwinning_score(number_of_players:usize,max_points:usize)->usize{letmutmarbles:VecDeque<usize>=VecDeque::new();letmutplayers:Vec<usize>=Vec::new();for_iin0..number_of_players{players.push(0);}marbles.push_back(0);marbles.push_back(1);foriin2..=max_points{ifi%100000==0{println!("{}",i)};// Speed testing feedbackifi%23==0{players[i%number_of_players]+=i;rotate_right(&mutmarbles,7);players[i%number_of_players]+=marbles.pop_back().unwrap();rotate_left(&mutmarbles,1);}else{rotate_left(&mutmarbles,1);marbles.push_back(i);}}*players.iter().max().unwrap()}fnrotate_right(list:&mutVecDeque<usize>,times:usize){for_iin0..times{letvalue=list.pop_back().expect("Empty VecDeque");list.push_front(value);}}fnrotate_left(list:&mutVecDeque<usize>,times:usize){for_iin0..times{letvalue=list.pop_front().expect("Empty VecDeque");list.push_back(value);}}
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
I found out (seems like a lot of other people did too) that rotating a doubly-linked list is way faster than inserting/removing with indices. Still felt like a boss when my code cranked through seven million possibilities in a few seconds :) Man, I love coding.