Compare commits
2 Commits
00000360a0
...
000003806f
Author | SHA1 | Date |
---|---|---|
Matej Janezic | 000003806f | |
Matej Janezic | 000003708f |
|
@ -11,6 +11,6 @@ target/
|
||||||
.env
|
.env
|
||||||
|
|
||||||
# downloaded inputs
|
# downloaded inputs
|
||||||
/src/inputs/*
|
/data/inputs/*
|
||||||
!/src/inputs/.keep
|
!/data/inputs/.keep
|
||||||
|
|
||||||
|
|
|
@ -19,7 +19,7 @@ checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "aoc"
|
name = "aoc"
|
||||||
version = "36.0.0"
|
version = "38.0.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"itertools",
|
"itertools",
|
||||||
]
|
]
|
||||||
|
@ -105,7 +105,7 @@ checksum = "03d8c417d7a8cb362e0c37e5d815f5eb7c37f79ff93707329d5a194e42e54ca0"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "download"
|
name = "download"
|
||||||
version = "36.0.0"
|
version = "38.0.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"dotenvy",
|
"dotenvy",
|
||||||
"pico-args",
|
"pico-args",
|
||||||
|
@ -643,7 +643,7 @@ checksum = "7b4b9743ed687d4b4bcedf9ff5eaa7398495ae14e61cba0a295704edbc7decde"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "scaffold"
|
name = "scaffold"
|
||||||
version = "36.0.0"
|
version = "38.0.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"dotenvy",
|
"dotenvy",
|
||||||
"pico-args",
|
"pico-args",
|
||||||
|
|
|
@ -19,7 +19,7 @@ members = ["utils/download", "utils/scaffold"]
|
||||||
[workspace.package]
|
[workspace.package]
|
||||||
description = "template for advent of code"
|
description = "template for advent of code"
|
||||||
readme = "README.md"
|
readme = "README.md"
|
||||||
version = "36.0.0"
|
version = "38.0.0"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
license = "MIT"
|
license = "MIT"
|
||||||
authors = ["Matej Janežič <janezic.mj@gmail.com>"]
|
authors = ["Matej Janežič <janezic.mj@gmail.com>"]
|
||||||
|
|
20
src/lib.rs
20
src/lib.rs
|
@ -11,8 +11,8 @@ pub const ANSI_BOLD: &str = "\x1b[1m";
|
||||||
pub const ANSI_RESET: &str = "\x1b[0m";
|
pub const ANSI_RESET: &str = "\x1b[0m";
|
||||||
|
|
||||||
#[macro_export]
|
#[macro_export]
|
||||||
macro_rules! solve {
|
macro_rules! solution {
|
||||||
($part:expr, $solver:ident, $input:expr) => {{
|
($day:expr) => {
|
||||||
use aoc::{ANSI_BOLD, ANSI_ITALIC, ANSI_RESET};
|
use aoc::{ANSI_BOLD, ANSI_ITALIC, ANSI_RESET};
|
||||||
use std::fmt::Display;
|
use std::fmt::Display;
|
||||||
use std::time::Instant;
|
use std::time::Instant;
|
||||||
|
@ -34,16 +34,20 @@ macro_rules! solve {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
println!("🎄 {}Part {}{} 🎄", ANSI_BOLD, $part, ANSI_RESET);
|
fn main() {
|
||||||
print_result($solver, $input);
|
let input = aoc::read_file("inputs", 1);
|
||||||
}};
|
println!("{}Part {}{}", ANSI_BOLD, 1, ANSI_RESET);
|
||||||
|
print_result(part_one, &input);
|
||||||
|
println!("{}Part {}{}", ANSI_BOLD, 1, ANSI_RESET);
|
||||||
|
print_result(part_two, &input);
|
||||||
|
}
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[must_use]
|
||||||
pub fn read_file(folder: &str, day: u8) -> String {
|
pub fn read_file(folder: &str, day: u8) -> String {
|
||||||
let cwd = env::current_dir().unwrap();
|
let cwd = env::current_dir().unwrap();
|
||||||
|
let filepath = cwd.join("data").join(folder).join(format!("{day:02}.txt"));
|
||||||
let filepath = cwd.join("src").join(folder).join(format!("{day:02}.txt"));
|
|
||||||
|
|
||||||
let f = fs::read_to_string(filepath);
|
let f = fs::read_to_string(filepath);
|
||||||
f.expect("could not open input file").trim().to_string()
|
f.expect("could not open input file").trim().to_string()
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,26 +11,23 @@ use std::{
|
||||||
const MODULE_TEMPLATE: &str = r#"pub fn part_one(input: &str) -> Option<u32> {
|
const MODULE_TEMPLATE: &str = r#"pub fn part_one(input: &str) -> Option<u32> {
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn part_two(input: &str) -> Option<u32> {
|
pub fn part_two(input: &str) -> Option<u32> {
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
fn main() {
|
|
||||||
let input = &aoc::read_file("inputs", DAY);
|
aoc::solution!(DAY);
|
||||||
aoc::solve!(1, part_one, input);
|
|
||||||
aoc::solve!(2, part_two, input);
|
|
||||||
}
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
#[test]
|
#[test]
|
||||||
fn test_part_one() {
|
fn test_part_one() {
|
||||||
let input = aoc::read_file("examples", DAY);
|
assert_eq!(part_one(&aoc::read_file("examples", DAY)), None);
|
||||||
assert_eq!(part_one(&input), None);
|
|
||||||
}
|
}
|
||||||
#[test]
|
#[test]
|
||||||
fn test_part_two() {
|
fn test_part_two() {
|
||||||
let input = aoc::read_file("examples", DAY);
|
assert_eq!(part_two(&aoc::read_file("examples", DAY)), None);
|
||||||
assert_eq!(part_two(&input), None);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
"#;
|
"#;
|
||||||
|
@ -59,8 +56,8 @@ fn main() {
|
||||||
|
|
||||||
let day_padded = format!("{day:02}");
|
let day_padded = format!("{day:02}");
|
||||||
|
|
||||||
let input_path = format!("src/inputs/{day_padded}.txt");
|
let input_path = format!("data/inputs/{day_padded}.txt");
|
||||||
let example_path = format!("src/examples/{day_padded}.txt");
|
let example_path = format!("data/examples/{day_padded}.txt");
|
||||||
let module_path = format!("src/bin/{day_padded}.rs");
|
let module_path = format!("src/bin/{day_padded}.rs");
|
||||||
|
|
||||||
let mut file = match safe_create_file(&module_path) {
|
let mut file = match safe_create_file(&module_path) {
|
||||||
|
@ -103,7 +100,7 @@ fn main() {
|
||||||
|
|
||||||
println!("---");
|
println!("---");
|
||||||
println!(
|
println!(
|
||||||
"🎄 Type `cargo solve {}` to run your solution.",
|
"Type `cargo solve {}` to run your solution.",
|
||||||
&day_padded
|
&day_padded
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue