Minor cleanup for D22
This commit is contained in:
parent
5af783fc94
commit
ab5b3a20f7
|
@ -35,17 +35,23 @@ fn apply(deck: &mut Vec<usize>, operation: &str) {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn create_deck(len: usize) -> Vec<usize> {
|
||||||
|
let mut deck = Vec::with_capacity(len);
|
||||||
|
(0..len).for_each(|n| deck.push(n));
|
||||||
|
deck
|
||||||
|
}
|
||||||
|
|
||||||
const DECK_SIZE: usize = 10007;
|
const DECK_SIZE: usize = 10007;
|
||||||
|
const P2_DECK_SIZE: usize = 119315717514047;
|
||||||
|
const P2_ITERATIONS: usize = 101741582076661;
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let input: Vec<_> = io::stdin().lock().lines().map(|l| l.unwrap()).collect();
|
let input: Vec<_> = io::stdin().lock().lines().map(|l| l.unwrap()).collect();
|
||||||
let mut deck = Vec::with_capacity(DECK_SIZE);
|
let mut deck = create_deck(DECK_SIZE);
|
||||||
(0..DECK_SIZE).for_each(|n| deck.push(n));
|
for command in &input {
|
||||||
for line in input {
|
apply(&mut deck, command);
|
||||||
apply(&mut deck, &line);
|
|
||||||
}
|
}
|
||||||
println!("{}", deck.iter().position(|&x| x == 2019).unwrap());
|
println!("{}", deck.iter().position(|&x| x == 2019).unwrap());
|
||||||
assert_eq!(deck.capacity(), 10007);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
mod tests {
|
mod tests {
|
||||||
|
@ -53,7 +59,7 @@ mod tests {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn deal_test() {
|
fn deal_test() {
|
||||||
let mut deck: Vec<usize> = (0..10).collect();
|
let mut deck = create_deck(10);
|
||||||
let instructions = "deal with increment 7
|
let instructions = "deal with increment 7
|
||||||
deal into new stack
|
deal into new stack
|
||||||
deal into new stack";
|
deal into new stack";
|
||||||
|
@ -65,7 +71,7 @@ deal into new stack";
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn cut_deal_test() {
|
fn cut_deal_test() {
|
||||||
let mut deck: Vec<usize> = (0..10).collect();
|
let mut deck = create_deck(10);
|
||||||
let instructions = "cut 6
|
let instructions = "cut 6
|
||||||
deal with increment 7
|
deal with increment 7
|
||||||
deal into new stack";
|
deal into new stack";
|
||||||
|
@ -77,7 +83,7 @@ deal into new stack";
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_all() {
|
fn test_all() {
|
||||||
let mut deck: Vec<usize> = (0..10).collect();
|
let mut deck = create_deck(10);
|
||||||
let instructions = "deal into new stack
|
let instructions = "deal into new stack
|
||||||
cut -2
|
cut -2
|
||||||
deal with increment 7
|
deal with increment 7
|
||||||
|
|
Loading…
Reference in New Issue
Block a user