cargo fmt
This commit is contained in:
parent
561a1453df
commit
05c89e5f11
3 changed files with 92 additions and 90 deletions
|
@ -1,6 +1,5 @@
|
||||||
use aoc_runner_derive::{aoc, aoc_generator};
|
use aoc_runner_derive::{aoc, aoc_generator};
|
||||||
|
|
||||||
|
|
||||||
#[aoc_generator(day1)]
|
#[aoc_generator(day1)]
|
||||||
pub fn input_generator(input: &str) -> Vec<usize> {
|
pub fn input_generator(input: &str) -> Vec<usize> {
|
||||||
input
|
input
|
||||||
|
|
|
@ -54,10 +54,10 @@ pub fn input_generator(input: &str) -> Vec<Rule> {
|
||||||
|
|
||||||
#[aoc(day2, part1)]
|
#[aoc(day2, part1)]
|
||||||
pub fn solve_part1(input: &Vec<Rule>) -> usize {
|
pub fn solve_part1(input: &Vec<Rule>) -> usize {
|
||||||
return input.iter().filter(|v| v.is_valid_part1()).count()
|
return input.iter().filter(|v| v.is_valid_part1()).count();
|
||||||
}
|
}
|
||||||
|
|
||||||
#[aoc(day2, part2)]
|
#[aoc(day2, part2)]
|
||||||
pub fn solve_part2(input: &Vec<Rule>) -> usize {
|
pub fn solve_part2(input: &Vec<Rule>) -> usize {
|
||||||
return input.iter().filter(|v| v.is_valid_part2()).count()
|
return input.iter().filter(|v| v.is_valid_part2()).count();
|
||||||
}
|
}
|
||||||
|
|
27
src/day5.rs
27
src/day5.rs
|
@ -5,22 +5,25 @@ pub enum Direction {
|
||||||
Front,
|
Front,
|
||||||
Back,
|
Back,
|
||||||
Left,
|
Left,
|
||||||
Right
|
Right,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[aoc_generator(day5)]
|
#[aoc_generator(day5)]
|
||||||
pub fn input_generator(input: &str) -> Vec<Vec<Direction>> {
|
pub fn input_generator(input: &str) -> Vec<Vec<Direction>> {
|
||||||
input.lines().map(|line| {
|
input
|
||||||
line.chars().map(|c| {
|
.lines()
|
||||||
match c {
|
.map(|line| {
|
||||||
|
line.chars()
|
||||||
|
.map(|c| match c {
|
||||||
'L' => Direction::Left,
|
'L' => Direction::Left,
|
||||||
'R' => Direction::Right,
|
'R' => Direction::Right,
|
||||||
'F' => Direction::Front,
|
'F' => Direction::Front,
|
||||||
'B' => Direction::Back,
|
'B' => Direction::Back,
|
||||||
other => panic!("Invalid direction: {}",other)
|
other => panic!("Invalid direction: {}", other),
|
||||||
}
|
})
|
||||||
}).collect()
|
.collect()
|
||||||
}).collect()
|
})
|
||||||
|
.collect()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn seat_to_pos(seat: &Vec<Direction>) -> (usize, usize) {
|
pub fn seat_to_pos(seat: &Vec<Direction>) -> (usize, usize) {
|
||||||
|
@ -32,16 +35,16 @@ pub fn seat_to_pos(seat: &Vec<Direction>) -> (usize,usize) {
|
||||||
match inst {
|
match inst {
|
||||||
Direction::Back => {
|
Direction::Back => {
|
||||||
row_range.0 += delta_row;
|
row_range.0 += delta_row;
|
||||||
},
|
}
|
||||||
Direction::Front => {
|
Direction::Front => {
|
||||||
row_range.1 -= delta_row;
|
row_range.1 -= delta_row;
|
||||||
},
|
}
|
||||||
Direction::Left => {
|
Direction::Left => {
|
||||||
col_range.1 -= delta_col;
|
col_range.1 -= delta_col;
|
||||||
},
|
}
|
||||||
Direction::Right => {
|
Direction::Right => {
|
||||||
col_range.0 += delta_col;
|
col_range.0 += delta_col;
|
||||||
},
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if row_range.1 - row_range.0 != 1 {
|
if row_range.1 - row_range.0 != 1 {
|
||||||
|
|
Loading…
Reference in a new issue