updated the convert_to array function

Dieser Commit ist enthalten in:
Sebastian Tobie 2024-12-07 12:47:53 +01:00
Ursprung 194e904ccc
Commit dec9308b2f
3 geänderte Dateien mit 6 neuen und 6 gelöschten Zeilen

Datei anzeigen

@ -1,4 +1,4 @@
use advent_of_code::strings::{parsenumber, splitspace};
use advent_of_code::strings::{convert_to_array, parsenumber, splitspace};
#[allow(unused_imports)]
use advent_of_code::{include_data, include_example};
@ -37,7 +37,7 @@ fn similarity(leftlist: &Vec<u32>, rightlist: &Vec<u32>) -> u32 {
fn main() {
let mut leftlist = Vec::<u32>::with_capacity(1000);
let mut rightlist = Vec::<u32>::with_capacity(1000);
for (left, right) in DATA.split("\n").map(splitspace) {
for (left, right) in convert_to_array::<_, _, '\n'>(DATA, splitspace) {
leftlist.push(parsenumber(left));
rightlist.push(parsenumber(right));
}

Datei anzeigen

@ -101,7 +101,7 @@ fn safe(record: Vec<u32>) -> bool {
}
fn main() {
let numbers = convert_to_array(DATA, get_numbers);
let numbers = convert_to_array::<_,_,'\n'>(DATA, get_numbers);
let mut safe_reports = 0;
let mut safe_with_dampener = 0;
for report in numbers {

Datei anzeigen

@ -1,7 +1,7 @@
const MAXMUL: u32 = 100000;
pub fn splitspace(input: &str) -> (&str, &str) {
let mut output = input.split_ascii_whitespace();
let mut output = input.clone().split_ascii_whitespace();
(output.next().unwrap(), output.next().unwrap())
}
@ -162,6 +162,6 @@ pub fn line_to_char(line: &str) -> Vec<char> {
Vec::from_iter(line.chars())
}
pub fn convert_to_array<T, F: FnMut(&str) -> T>(input: &str, func: F) -> Vec<T> {
input.split('\n').map(func).collect()
pub fn convert_to_array<T, F: FnMut(&str) -> T, const S: char>(input: &str, func: F) -> Vec<T> {
input.split(S).map(func).collect()
}