problems.rs

View source code here on GitHub!

Includes

pub fn get_problem(n: usize) -> Option<(usize, fn() -> utils::Answer, bool)>

Returns a reference to a specific problem. This reference includes its id, the function, and a boolean indicating whether the function should return in over one minute runtime.

pub fn generate_supported_problems(include_slow: bool) -> Vec<usize>

Generates a vector of the supported problem IDs, optionally excluding slow problems.

 1use seq_macro::seq;
 2
 3use crate::include::utils::Answer;
 4use crate::problems::*;
 5
 6type ProblemType = fn() -> Answer;
 7type ProblemRef<'a> = (&'a usize, ProblemType, bool);
 8
 9seq!(N in 0001..=0020 {
10    pub fn get_problem<'b>(n: usize) -> Option<ProblemRef<'b>> {
11        return match n {
12            #(
13                N => Some(( &N, p~N::p~N, false)),
14            )*
15            21 =>  Some(( &21, p0021::p0021, true)),
16            22 =>  Some(( &22, p0022::p0022, false)),
17            23 =>  Some(( &23, p0023::p0023, false)),
18            24 =>  Some(( &24, p0024::p0024, false)),
19            25 =>  Some(( &25, p0025::p0025, false)),
20            27 =>  Some(( &27, p0027::p0027, true)),
21            28 =>  Some(( &28, p0028::p0028, false)),
22            34 =>  Some(( &34, p0034::p0034, false)),
23            35 =>  Some(( &35, p0035::p0035, true)),
24            36 =>  Some(( &36, p0036::p0036, false)),
25            37 =>  Some(( &37, p0037::p0037, true)),
26            41 =>  Some(( &41, p0041::p0041, false)),
27            43 =>  Some(( &43, p0043::p0043, false)),
28            44 =>  Some(( &44, p0044::p0044, false)),
29            45 =>  Some(( &45, p0045::p0045, false)),
30            53 =>  Some(( &53, p0053::p0053, false)),
31            59 =>  Some(( &59, p0059::p0059, false)),
32            67 =>  Some(( &67, p0067::p0067, false)),
33            69 =>  Some(( &69, p0069::p0069, false)),
34            76 =>  Some(( &76, p0076::p0076, false)),
35            77 =>  Some(( &77, p0077::p0077, false)),
36            87 =>  Some(( &87, p0087::p0087, false)),
37            187 => Some((&187, p0187::p0187, false)),
38            357 => Some((&357, p0357::p0357, true)),
39            836 => Some((&836, p0836::p0836, false)),
40            _ => None,
41        };
42    }
43});
44
45
46pub fn generate_supported_problems(include_slow: bool) -> Vec<usize> {
47    let mut supported_problems = Vec::new();
48    for n in 1..10000 {
49        if let Some((_, _, slow)) = get_problem(n) { 
50            if !slow || include_slow {
51                supported_problems.push(n);
52            }
53        }
54    }
55
56    return supported_problems;
57}