Commit 1da06267 authored by Kai Brandes's avatar Kai Brandes

borrow input for 4

parent 22171fb8
......@@ -11,7 +11,7 @@ fn line_valid(input: &str) -> bool {
}
pub fn calc_day_4_a(input: String) -> u32 {
pub fn calc_day_4_a(input: &String) -> u32 {
return input.lines()
.map(line_valid)
.filter(|a| *a == true)
......@@ -29,7 +29,7 @@ fn to_normalized_line(input: &str) -> String {
}
pub fn calc_day_4_b(input: String) -> u32 {
pub fn calc_day_4_b(input: &String) -> u32 {
return input.lines()
.map(to_normalized_line)
.map(|a|line_valid(&a))
......@@ -59,7 +59,7 @@ mod tests {
#[test]
fn it_aoc_example_4() {
assert_eq!(2, calc_day_4_a(String::from("aa bb cc dd ee\naa bb cc dd aa\naa bb cc dd aaa")));
assert_eq!(2, calc_day_4_a(&String::from("aa bb cc dd ee\naa bb cc dd aa\naa bb cc dd aaa")));
}
......@@ -75,22 +75,22 @@ mod tests {
#[test]
fn it_aoc_b_example3() {
assert_eq!(1, calc_day_4_b(String::from("abcde fghij")));
assert_eq!(1, calc_day_4_b(&String::from("abcde fghij")));
}
#[test]
fn it_aoc_b_example4() {
assert_eq!(0, calc_day_4_b(String::from("abcde xyz ecdab")));
assert_eq!(0, calc_day_4_b(&String::from("abcde xyz ecdab")));
}
#[test]
fn it_aoc_b_example5() {
assert_eq!(1, calc_day_4_b(String::from("a ab abc abd abf abj")));
assert_eq!(1, calc_day_4_b(&String::from("a ab abc abd abf abj")));
}
#[test]
fn it_aoc_b_example6() {
assert_eq!(1, calc_day_4_b(String::from("iiii oiii ooii oooi oooo")));
assert_eq!(1, calc_day_4_b(&String::from("iiii oiii ooii oooi oooo")));
}
......
......@@ -39,9 +39,9 @@ pub fn day_3_b() -> u32 {
}
pub fn day_4_a() -> u32 {
return day4::calc_day_4_a(parse_input_from_file(String::from("src/day4/a.txt")));
return day4::calc_day_4_a(&parse_input_from_file(String::from("src/day4/a.txt")));
}
pub fn day_4_b() -> u32 {
return day4::calc_day_4_b(parse_input_from_file(String::from("src/day4/b.txt")));
return day4::calc_day_4_b(&parse_input_from_file(String::from("src/day4/b.txt")));
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment