diff --git a/aoc/src/run.rs b/aoc/src/run.rs index f99ed1b..3194512 100644 --- a/aoc/src/run.rs +++ b/aoc/src/run.rs @@ -66,6 +66,7 @@ where if main_only && version.is_some() { continue; } + let results_start = results.chars().count(); write!(&mut results, "Day {day} - part {part}")?; if let Some(version) = version { write!(&mut results, " — {version}")?; @@ -73,10 +74,12 @@ where let before = chrono::Utc::now(); let result = runner()?; let after = chrono::Utc::now(); - write!(&mut results, ": {result}")?; if timings { write!(&mut results, " ({})", pretty_duration(after - before))?; } + write!(&mut results, ": ")?; + let sep = format!("\n{}", " ".repeat(results.chars().count() - results_start)); + write!(&mut results, "{}", result.trim().replace('\n', &sep))?; writeln!(&mut results)?; } } diff --git a/aoc/tests/dummy-year.rs b/aoc/tests/dummy-year.rs index fb4f09d..b6f0602 100644 --- a/aoc/tests/dummy-year.rs +++ b/aoc/tests/dummy-year.rs @@ -37,7 +37,11 @@ fn day1_main() { fn day2() { insta::assert_snapshot!(run_with(&["-d", "2"]), @r###" Day 2 - part 1: 1606483 - Day 2 - part 2: 3842356 + Day 2 - part 2: 20x3x11 + 15x27x5 + Day 2 - part 2 — no_eol: 20x3x11 + 15x27x5 + "###); } @@ -51,7 +55,11 @@ fn all_days() { Day 1 - part 2 — result: 1783 Day 1 - part 2 — result_string: 1783 Day 2 - part 1: 1606483 - Day 2 - part 2: 3842356 + Day 2 - part 2: 20x3x11 + 15x27x5 + Day 2 - part 2 — no_eol: 20x3x11 + 15x27x5 + "###); } @@ -62,6 +70,8 @@ fn all_days_main() { Day 1 - part 1: 232 Day 1 - part 2: 1783 Day 2 - part 1: 1606483 - Day 2 - part 2: 3842356 + Day 2 - part 2: 20x3x11 + 15x27x5 + "###); } diff --git a/dummy-year/expected.txt b/dummy-year/expected.txt index d64c47f..f42fd03 100644 --- a/dummy-year/expected.txt +++ b/dummy-year/expected.txt @@ -4,4 +4,7 @@ Day 1 - part 2: 1783 Day 1 - part 2 — result: 1783 Day 1 - part 2 — result_string: 1783 Day 2 - part 1: 1606483 -Day 2 - part 2: 3842356 +Day 2 - part 2: 20x3x11 + 15x27x5 +Day 2 - part 2 — no_eol: 20x3x11 + 15x27x5 diff --git a/dummy-year/src/day2.rs b/dummy-year/src/day2.rs index 1a434c0..7343f02 100644 --- a/dummy-year/src/day2.rs +++ b/dummy-year/src/day2.rs @@ -25,14 +25,11 @@ fn part1(input: &str) -> u32 { } #[aoc(day2, part2)] -fn part2(input: &str) -> u32 { - generator(input) - .unwrap() - .iter() - .map(|v| { - let mut v = v.clone(); - v.sort_unstable(); - (v[0] + v[1]) * 2 + v[0] * v[1] * v[2] - }) - .sum() +fn part2(input: &[&str]) -> String { + format!("{}\n{}\n", input[0], input[1]) +} + +#[aoc(day2, part2, no_eol)] +fn part2_no_eol(input: &[&str]) -> String { + format!("{}\n{}", input[0], input[1]) }