updated the convert_to array function
Dieser Commit ist enthalten in:
Ursprung
194e904ccc
Commit
dec9308b2f
3 geänderte Dateien mit 6 neuen und 6 gelöschten Zeilen
|
@ -1,4 +1,4 @@
|
||||||
use advent_of_code::strings::{parsenumber, splitspace};
|
use advent_of_code::strings::{convert_to_array, parsenumber, splitspace};
|
||||||
#[allow(unused_imports)]
|
#[allow(unused_imports)]
|
||||||
use advent_of_code::{include_data, include_example};
|
use advent_of_code::{include_data, include_example};
|
||||||
|
|
||||||
|
@ -37,7 +37,7 @@ fn similarity(leftlist: &Vec<u32>, rightlist: &Vec<u32>) -> u32 {
|
||||||
fn main() {
|
fn main() {
|
||||||
let mut leftlist = Vec::<u32>::with_capacity(1000);
|
let mut leftlist = Vec::<u32>::with_capacity(1000);
|
||||||
let mut rightlist = 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));
|
leftlist.push(parsenumber(left));
|
||||||
rightlist.push(parsenumber(right));
|
rightlist.push(parsenumber(right));
|
||||||
}
|
}
|
||||||
|
|
|
@ -101,7 +101,7 @@ fn safe(record: Vec<u32>) -> bool {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn main() {
|
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_reports = 0;
|
||||||
let mut safe_with_dampener = 0;
|
let mut safe_with_dampener = 0;
|
||||||
for report in numbers {
|
for report in numbers {
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
const MAXMUL: u32 = 100000;
|
const MAXMUL: u32 = 100000;
|
||||||
|
|
||||||
pub fn splitspace(input: &str) -> (&str, &str) {
|
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())
|
(output.next().unwrap(), output.next().unwrap())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -162,6 +162,6 @@ pub fn line_to_char(line: &str) -> Vec<char> {
|
||||||
Vec::from_iter(line.chars())
|
Vec::from_iter(line.chars())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn convert_to_array<T, F: FnMut(&str) -> T>(input: &str, func: F) -> Vec<T> {
|
pub fn convert_to_array<T, F: FnMut(&str) -> T, const S: char>(input: &str, func: F) -> Vec<T> {
|
||||||
input.split('\n').map(func).collect()
|
input.split(S).map(func).collect()
|
||||||
}
|
}
|
||||||
|
|
Laden …
Tabelle hinzufügen
In neuem Issue referenzieren