From 3d926bfdb16ba3f0c16ad00dc8403b810d529a71 Mon Sep 17 00:00:00 2001 From: Daniel Flanagan Date: Sun, 4 Dec 2022 02:11:08 -0600 Subject: [PATCH] Small changes to help go fast --- 2022/rust/Cargo.toml | 4 ++++ 2022/rust/fetch_input.sh | 3 ++- 2022/rust/src/common.rs | 8 ++++++++ 2022/rust/src/day5.rs | 7 +++++-- 2022/rust/src/scaffold.rs | 8 +++++--- 5 files changed, 24 insertions(+), 6 deletions(-) diff --git a/2022/rust/Cargo.toml b/2022/rust/Cargo.toml index 1d7b199..b389897 100644 --- a/2022/rust/Cargo.toml +++ b/2022/rust/Cargo.toml @@ -2,6 +2,10 @@ name = "aoc2022" version = "0.1.0" +[[bin]] +name = "scaffold" +path = "src/scaffold.rs" + [[bin]] name = "day1" path = "src/day1.rs" diff --git a/2022/rust/fetch_input.sh b/2022/rust/fetch_input.sh index 18d3fd3..46f79dd 100755 --- a/2022/rust/fetch_input.sh +++ b/2022/rust/fetch_input.sh @@ -15,7 +15,8 @@ url="https://adventofcode.com/$AOC_YEAR/day/$DAY/input" cookie="$(cat "$HOME/.advent-of-code-session-cookie")" mkdir -p "$(dirname "$f")" if curl --fail-with-body -X GET "$url" -H "Cookie:$cookie" > "$f"; then - echo "Downloaded $url to $f" + cat "$f" + echo "Downloaded $url to $f - contents have been output to this terminal as well" exit 0 else echo "Error: curl failed" diff --git a/2022/rust/src/common.rs b/2022/rust/src/common.rs index 1db9c23..be40a80 100644 --- a/2022/rust/src/common.rs +++ b/2022/rust/src/common.rs @@ -8,6 +8,14 @@ pub fn day_input(day: u8) -> String { let home_path = Path::new(home); let path_buf = home_path.join(format!("./.cache/aoc2022/{0}.input", day)); let file_path = path_buf.to_str().unwrap(); + if !path_buf.exists() { + eprintln!("Running input downloaded script with day arg {}...", day); + std::process::Command::new("sh") + .arg("./fetch_input.sh") + .arg(format!("{}", day)) + .status() + .expect("fetch_input.sh failed"); + } fs::read_to_string(file_path).unwrap() } diff --git a/2022/rust/src/day5.rs b/2022/rust/src/day5.rs index 928da8b..eccfaec 100644 --- a/2022/rust/src/day5.rs +++ b/2022/rust/src/day5.rs @@ -8,7 +8,7 @@ fn processed_input(input: &str) -> Input { } fn part1(input: &Input) -> Result { - 0 + 100 } fn part2(input: &Input) -> Result { @@ -16,7 +16,9 @@ fn part2(input: &Input) -> Result { } fn main() { - let input = processed_input(&common::day_input(5)); + let input_text = common::day_input(5); + eprintln!("{}\n\nAbove is your input file.\n\n", input_text); + let input = processed_input(&input_text); common::show_answers(&part1(&input), &part2(&input)) // common::show_both_answers(&both_parts(&input)) } @@ -36,5 +38,6 @@ mod tests { let input = processed_input(TEST_INPUT); assert_eq!(part1(&input), 0); assert_eq!(part2(&input), 0); + // assert_eq!(both_parts(&input), (0, 0)); } } diff --git a/2022/rust/src/scaffold.rs b/2022/rust/src/scaffold.rs index 7e5bf1d..f44d598 100644 --- a/2022/rust/src/scaffold.rs +++ b/2022/rust/src/scaffold.rs @@ -8,7 +8,7 @@ fn processed_input(input: &str) -> Input { } fn part1(input: &Input) -> Result { - 0 + 100 } fn part2(input: &Input) -> Result { @@ -16,9 +16,11 @@ fn part2(input: &Input) -> Result { } fn main() { - let input = processed_input(&common::day_input(panic!( + let input_text = common::day_input(panic!( "PUT THE CORRECT DAY NUMBER HERE AND ADD bin TO Cargo.toml" - ))); + )); + eprintln!("{}\n\nAbove is your input file.\n\n", input_text); + let input = processed_input(&input_text); common::show_answers(&part1(&input), &part2(&input)) // common::show_both_answers(&both_parts(&input)) }