Improve scaffolding

This commit is contained in:
Daniel Flanagan 2022-12-04 01:55:11 -06:00
parent 1fc8a7f4fe
commit d79c2756da
Signed by: lytedev
GPG key ID: 5B2020A0F9921EF4
4 changed files with 62 additions and 35 deletions

View file

@ -22,4 +22,12 @@ path = "src/day3.rs"
name = "day4" name = "day4"
path = "src/day4.rs" path = "src/day4.rs"
[[bin]]
name = "day4-alt1"
path = "src/day4-alt1.rs"
[[bin]]
name = "day5"
path = "src/day5.rs"
[dependencies] [dependencies]

View file

@ -11,10 +11,13 @@ pub fn day_input(day: u8) -> String {
fs::read_to_string(file_path).unwrap() fs::read_to_string(file_path).unwrap()
} }
#[allow(dead_code)]
pub fn show_answers(answer1: &impl Debug, answer2: &impl Debug) { pub fn show_answers(answer1: &impl Debug, answer2: &impl Debug) {
println!("Part 1: {:?}", answer1); println!("Part 1: {:?}", answer1);
println!("Part 2: {:?}", answer2); println!("Part 2: {:?}", answer2);
} }
#[allow(dead_code)]
pub fn show_both_answers((a, b): &(impl Debug, impl Debug)) { pub fn show_both_answers((a, b): &(impl Debug, impl Debug)) {
show_answers(a, b) show_answers(a, b)
} }

View file

@ -1,18 +1,29 @@
mod common; mod common;
type Input = String;
type Result = usize;
fn processed_input(input: &str) -> Input {
input.to_owned()
}
fn part1(input: &Input) -> Result {
0
}
fn part2(input: &Input) -> Result {
0
}
fn main() { fn main() {
let input = common::day_input(5); let input = processed_input(&common::day_input(5));
println!("Part 1: {}", part1(&input)); common::show_answers(&part1(&input), &part2(&input))
println!("Part 2: {}", part2(&input)); // common::show_both_answers(&both_parts(&input))
} }
fn part1(input: &str) -> i32 { // fn both_parts(input: &Input) -> (Result, Result) {
0 // (0, 0)
} // }
fn part2(input: &str) -> i32 {
0
}
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
@ -21,12 +32,9 @@ mod tests {
const TEST_INPUT: &str = ""; const TEST_INPUT: &str = "";
#[test] #[test]
fn test_part1() { fn test() {
assert_eq!(part1(TEST_INPUT), 0) let input = processed_input(TEST_INPUT);
} assert_eq!(part1(&input), 0);
assert_eq!(part2(&input), 0);
#[test]
fn test_part2() {
assert_eq!(part2(TEST_INPUT), 0)
} }
} }

View file

@ -1,20 +1,31 @@
mod common; mod common;
type Input = &str; type Input = String;
type Result = usize;
fn processed_input(input: &str) -> Input {
input.to_owned()
}
fn part1(input: &Input) -> Result {
0
}
fn part2(input: &Input) -> Result {
0
}
fn main() { fn main() {
let input = common::day_input(panic!("PUT THE CORRECT DAY NUMBER HERE")); let input = processed_input(&common::day_input(panic!(
println!("Part 1: {}", part1(&input)); "PUT THE CORRECT DAY NUMBER HERE AND ADD bin TO Cargo.toml"
println!("Part 2: {}", part2(&input)); )));
common::show_answers(&part1(&input), &part2(&input))
// common::show_both_answers(&both_parts(&input))
} }
fn part1(input: &str) -> i32 { // fn both_parts(input: &Input) -> (Result, Result) {
0 // (0, 0)
} // }
fn part2(input: &str) -> i32 {
0
}
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
@ -23,12 +34,9 @@ mod tests {
const TEST_INPUT: &str = ""; const TEST_INPUT: &str = "";
#[test] #[test]
fn test_part1() { fn test() {
assert_eq!(part1(TEST_INPUT), 0) let input = processed_input(TEST_INPUT);
} assert_eq!(part1(&input), 0);
assert_eq!(part2(&input), 0);
#[test]
fn test_part2() {
assert_eq!(part2(TEST_INPUT), 0)
} }
} }