advent-of-code/2019/10/src/main.rs

125 lines
2.4 KiB
Rust
Raw Normal View History

2019-12-10 14:59:21 +01:00
use std::collections::HashSet;
2019-12-10 08:05:30 +01:00
fn main() {
println!("Hello, world!");
}
2019-12-10 11:45:56 +01:00
fn calculate_angle(x_offset: i32, y_offset: i32) -> f32 {
return ((y_offset as f32).atan2(x_offset as f32).to_degrees() * 1000.0).round();
}
2019-12-10 14:59:21 +01:00
fn parse_input(raw: std::str::Lines) -> HashSet<(i32, i32)> {
unimplemented!()
}
fn part1(asteroids: &HashSet<(i32, i32)>) -> (i32, i32) {
unimplemented!()
}
2019-12-10 11:45:56 +01:00
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_angle_calculation() {
assert_eq!(calculate_angle(1, 1), 45_000.0);
assert_eq!(calculate_angle(1, 0), 0.0);
assert_eq!(calculate_angle(0, -1), -90_000.0);
assert_eq!(calculate_angle(2, 1), 26_565.0);
assert_eq!(calculate_angle(1, 1), calculate_angle(3, 3));
assert_eq!(calculate_angle(-2, -2), -135_000.0);
assert_eq!(calculate_angle(-2, 2), 135_000.0);
assert_ne!(calculate_angle(1, 1), calculate_angle(3, -3));
}
2019-12-10 14:59:21 +01:00
#[test]
fn test_part_1() {
assert_eq!(
part1(&parse_input(
".#..#
.....
#####
....#
...##"
.lines()
)),
(3, 4)
);
assert_eq!(
part1(&parse_input(
"#.#...#.#.
.###....#.
.#....#...
##.#.#.#.#
....#.#.#.
.##..###.#
..#...##..
..##....##
......#...
.####.###."
.lines()
)),
(1, 2)
);
assert_eq!(
part1(&parse_input(
".#..#..###
####.###.#
....###.#.
..###.##.#
##.##.#.#.
....###..#
..#.#..#.#
#..#.#.###
.##...##.#
.....#.#.."
.lines()
)),
(6, 3)
);
assert_eq!(
part1(&parse_input(
"......#.#.
#..#.#....
..#######.
.#.#.###..
.#..#.....
..#....#.#
#..#....#.
.##.#..###
##...#..#.
.#....####"
.lines()
)),
(5, 8)
);
assert_eq!(
part1(&parse_input(
".#..##.###...#######
##.############..##.
.#.######.########.#
.###.#######.####.#.
#####.##.#.##.###.##
..#####..#.#########
####################
#.####....###.#.#.##
##.#################
#####.##.###..####..
..######..##.#######
####.##.####...##..#
.#####..#.######.###
##...#.##########...
#.##########.#######
.####.#.###.###.#.##
....##.##.###..#####
.#.#.###########.###
#.#.#.#####.####.###
###.##.####.##.#..##"
.lines()
)),
(11, 13)
);
}
2019-12-10 11:45:56 +01:00
}