Implement day 05.

This was a nice exercise in not allocating memory. Or at least it was,
for part 1.
This commit is contained in:
2018-12-05 10:39:39 +01:00
parent 3d68f20097
commit 3543351c20
4 changed files with 91 additions and 1 deletions

View File

@@ -29,6 +29,25 @@ pub fn prime_sieve(dest: &mut[bool]) {
}
}
/// Trim ascii whitespace from a byte vector.
///
/// This method does no allocations, guaranteed.
pub fn trim_back(input: &mut Vec<u8>) {
let mut to_truncate = 0;
for b in input.iter().rev() {
if b.is_ascii_whitespace() {
to_truncate += 1;
} else {
break;
}
}
if to_truncate > 0 {
let new_len = input.len() - to_truncate;
input.truncate(new_len);
}
}
/// Solution trait
///
/// Every day's solution should implement this function so that it can