Skip to content

Commit

Permalink
Allow for unimplemented solutions
Browse files Browse the repository at this point in the history
  • Loading branch information
connorslade committed Nov 26, 2023
1 parent 49c7427 commit 0ad9e14
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 3 deletions.
5 changes: 3 additions & 2 deletions aoc_2022/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use common as problem;
use common::Solution;
use problem::DummySolution;

mod aoc_lib;
mod day_01;
Expand Down Expand Up @@ -47,11 +48,11 @@ pub const ALL: [&dyn Solution; 25] = [
&day_16::Day16,
&day_17::Day17,
&day_18::Day18,
&day_19::Day19,
&DummySolution,
&day_20::Day20,
&day_21::Day21,
&day_22::Day22,
&day_23::Day23,
&day_24::Day24,
&DummySolution,
&day_25::Day25,
];
24 changes: 24 additions & 0 deletions common/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ pub trait Solution {
fn name(&self) -> &'static str;
fn part_a(&self) -> String;
fn part_b(&self) -> String;

fn is_dummy(&self) -> bool {
false
}
}

pub fn load(year: u32, day: u32) -> String {
Expand All @@ -14,3 +18,23 @@ pub fn load_raw(year: u32, day: u32) -> String {
let file = format!("data/{year}/{:02}.txt", day);
fs::read_to_string(&file).unwrap_or_else(|_| panic!("Error reading file {}", file))
}

pub struct DummySolution;

impl Solution for DummySolution {
fn name(&self) -> &'static str {
unimplemented!()
}

fn part_a(&self) -> String {
unimplemented!()
}

fn part_b(&self) -> String {
unimplemented!()
}

fn is_dummy(&self) -> bool {
true
}
}
2 changes: 1 addition & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ fn main() {
let solutions = get_year(year);
println!("[*] Solutions for {year}:");

for (i, e) in solutions.iter().enumerate() {
for (i, e) in solutions.iter().enumerate().filter(|(_, e)| !e.is_dummy()) {
println!(
" {} Day {}: {}",
if i + 1 == solutions.len() {
Expand Down

0 comments on commit 0ad9e14

Please sign in to comment.