Couple of style tweaks

This commit is contained in:
Smaug123
2021-12-04 22:38:23 +00:00
parent 4039a4b93b
commit 95c7ff8cc2
2 changed files with 10 additions and 9 deletions

View File

@@ -75,7 +75,7 @@ pub mod day_2 {
y: u32,
}
fn step(position: Position, movement: &Movement) -> Position {
const fn step(position: Position, movement: &Movement) -> Position {
match movement.direction {
Direction::Forward => Position {
x: position.x + movement.distance,
@@ -104,7 +104,7 @@ pub mod day_2 {
aim: u32,
}
fn step_2(position: Position2, movement: &Movement) -> Position2 {
const fn step_2(position: Position2, movement: &Movement) -> Position2 {
match movement.direction {
Direction::Forward => Position2 {
aim: position.aim,

View File

@@ -60,15 +60,13 @@ pub mod day_3 {
where
I: Iterator<Item = bool>,
{
let mut falses = 0;
let mut trues = 0;
for elt in input {
let (falses, trues) = input.fold((0, 0), |(falses, trues), elt| {
if elt {
trues += 1;
(falses, trues + 1)
} else {
falses += 1;
(falses + 1, trues)
}
}
});
if trues + falses == 1 {
return None;
}
@@ -104,7 +102,10 @@ pub mod day_3 {
}
}
fn agree<const N: usize>(b1: &[bool; N], b2: &[bool; N], count: usize) -> bool {
fn agree<T, const N: usize>(b1: &[T; N], b2: &[T; N], count: usize) -> bool
where
T: Eq,
{
for i in 0..count {
if b1[i] != b2[i] {
return false;