mod tests {
use super::*;
- #[test]
- fn part1() {
- let calories =
- "1000
- 2000
- 3000
+ static CALORIES: &str =
+ "1000
+ 2000
+ 3000
+
+ 4000
- 4000
+ 5000
+ 6000
- 5000
- 6000
+ 7000
+ 8000
+ 9000
- 7000
- 8000
- 9000
+ 10000";
- 10000";
- assert_eq!(get_most_calories(&read_calories(calories.as_bytes())), 24000);
+ #[test]
+ fn part1() {
+ assert_eq!(get_most_calories(&read_calories(CALORIES.as_bytes())), 24000);
}
#[test]
fn part2() {
- let calories =
- "1000
- 2000
- 3000
-
- 4000
-
- 5000
- 6000
-
- 7000
- 8000
- 9000
-
- 10000";
- assert_eq!(get_sum_most_three_calories(&read_calories(calories.as_bytes())), 45000);
+ assert_eq!(get_sum_most_three_calories(&read_calories(CALORIES.as_bytes())), 45000);
}
}
\ No newline at end of file
mod tests {
use super::*;
+ static STRATEGY_GUIDE: &str =
+ "A Y
+ B X
+ C Z";
+
#[test]
fn part1() {
- let stategy_guide =
- "A Y
- B X
- C Z";
- assert_eq!(get_score(&read_shapes(stategy_guide.as_bytes())), 15);
+ assert_eq!(get_score(&read_shapes(STRATEGY_GUIDE.as_bytes())), 15);
}
#[test]
fn part2() {
- let stategy_guide =
- "A Y
- B X
- C Z";
- assert_eq!(get_score(&read_shapes_2(stategy_guide.as_bytes())), 12);
+ assert_eq!(get_score(&read_shapes_2(STRATEGY_GUIDE.as_bytes())), 12);
}
}
\ No newline at end of file
mod tests {
use super::*;
- #[test]
- fn part1() {
- let rucksacks =
+ static RUCKSACKS: &str =
"vJrwpWtwJgWrhcsFMMfFFhFp
jqHRNqRjqzjGDLGLrsFMfFZSrLrFZsSL
PmmdzqPrVvPwwTWBwg
ttgJtRGJQctTZtZT
CrZsJsPPZsGzwwsLwLmpwMDw";
- assert_eq!(priority_sum(&parse(rucksacks)), 157);
+ #[test]
+ fn part1() {
+ assert_eq!(priority_sum(&parse(RUCKSACKS)), 157);
}
#[test]
fn part2() {
- let rucksacks =
- "vJrwpWtwJgWrhcsFMMfFFhFp
-jqHRNqRjqzjGDLGLrsFMfFZSrLrFZsSL
-PmmdzqPrVvPwwTWBwg
-wMqvLMZHhHMvwLHjbvcjnnSBnvTQFn
-ttgJtRGJQctTZtZT
-CrZsJsPPZsGzwwsLwLmpwMDw";
-
- assert_eq!(badge_sum(&parse(rucksacks)), 70);
+ assert_eq!(badge_sum(&parse(RUCKSACKS)), 70);
}
}
\ No newline at end of file
mod tests {
use super::*;
- #[test]
- fn part1() {
- let pairs ="2-4,6-8
+ static PAIRS: &str ="2-4,6-8
2-3,4-5
5-7,7-9
2-8,3-7
6-6,4-6
2-6,4-8";
- assert_eq!(number_fully_contain(&parse(pairs)), 2);
+ #[test]
+ fn part1() {
+ assert_eq!(number_fully_contain(&parse(PAIRS)), 2);
}
#[test]
fn part2() {
- let pairs ="2-4,6-8
-2-3,4-5
-5-7,7-9
-2-8,3-7
-6-6,4-6
-2-6,4-8";
-
- assert_eq!(number_overlaps(&parse(pairs)), 4);
+ assert_eq!(number_overlaps(&parse(PAIRS)), 4);
}
}
\ No newline at end of file
mod tests {
use super::*;
- #[test]
- fn part1() {
- let stacks_and_moves =" [D]
+ static STACKS_AND_MOVES: &str =" [D]
[N] [C]
[Z] [M] [P]
1 2 3
move 3 from 1 to 3
move 2 from 2 to 1
move 1 from 1 to 2";
- let (mut stacks, moves) = parse(stacks_and_moves);
+
+ #[test]
+ fn part1() {
+ let (mut stacks, moves) = parse(STACKS_AND_MOVES);
apply_moves_by_crate_mover_9000(&mut stacks, &moves);
assert_eq!(get_top_as_string(&stacks), "CMZ");
}
#[test]
fn part2() {
- let stacks_and_moves =" [D]
-[N] [C]
-[Z] [M] [P]
- 1 2 3
-
-move 1 from 2 to 1
-move 3 from 1 to 3
-move 2 from 2 to 1
-move 1 from 1 to 2";
- let (mut stacks, moves) = parse(stacks_and_moves);
+ let (mut stacks, moves) = parse(STACKS_AND_MOVES);
apply_moves_by_crate_mover_9001(&mut stacks, &moves);
assert_eq!(get_top_as_string(&stacks), "MCD");
}
mod tests {
use super::*;
- #[test]
- fn part1() {
- let commands = "$ cd /
+ static INPUT: &str = "$ cd /
$ ls
dir a
14848514 b.txt
8033020 d.log
5626152 d.ext
7214296 k";
- let root = parse(commands);
+
+ #[test]
+ fn part1() {
+ let root = parse(INPUT);
let mut sizes: Vec<i64> = Vec::new();
root.dir_sizes(|size| size <= 100_000, &mut sizes);
assert_eq!(sizes.iter().sum::<i64>(), 95_437);
#[test]
fn part2() {
- let commands = "$ cd /
-$ ls
-dir a
-14848514 b.txt
-8504156 c.dat
-dir d
-$ cd a
-$ ls
-dir e
-29116 f
-2557 g
-62596 h.lst
-$ cd e
-$ ls
-584 i
-$ cd ..
-$ cd ..
-$ cd d
-$ ls
-4060174 j
-8033020 d.log
-5626152 d.ext
-7214296 k";
- let root = parse(commands);
-
+ let root = parse(INPUT);
let root_size = root.dir_sizes(|size| size <= 100_000, &mut Vec::new());
-
- let required = root_size - (70_000_000 - 30_000_000);
+ let to_free = root_size - (70_000_000 - 30_000_000);
let mut sizes: Vec<i64> = Vec::new();
- root.dir_sizes(|size| size >= required, &mut sizes);
-
- assert_eq!(*sizes.iter().min().unwrap(), 24933642);
+ root.dir_sizes(|size| size >= to_free, &mut sizes);
+ assert_eq!(*sizes.iter().min().unwrap(), 2_493_3642);
}
}
\ No newline at end of file
fn day07() -> String {
let root = day07::parse(&fs::read_to_string("data/day07.input").unwrap());
- let (root_size, sum_part1 ) = {
+ let (root_size, sum_part1, ) = {
let mut sizes: Vec<i64> = Vec::new();
(root.dir_sizes(|size| size <= 100_000, &mut sizes), sizes.iter().sum::<i64>())
};