1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
|
use nom::IResult;
use std::{collections::BTreeMap, fs};
fn main() -> Result<(), Box<dyn std::error::Error>> {
let input = fs::read_to_string("inputs/day_19.txt")?;
let parsed = PartSortingMess::parser(&input).unwrap().1;
dbg!(&parsed);
Ok(())
}
#[derive(Debug)]
struct PartSortingMess {
workflows: BTreeMap<String, Workflow>,
parts: Vec<Part>,
}
#[derive(Debug)]
struct Workflow {
id: String,
conditions: WorkflowStep,
if_none_match: WorkflowOutcome,
}
#[derive(Debug)]
struct WorkflowStep {
field: PartField,
condition: WorkflowCondition,
result: WorkflowOutcome,
}
#[derive(Debug)]
enum PartField {
X,
M,
A,
S,
}
#[derive(Debug)]
enum WorkflowCondition {
LessThan(u32),
GreaterThan(u32),
}
#[derive(Debug)]
enum WorkflowOutcome {
Accept,
Reject,
Defer(String),
}
#[derive(Debug)]
struct Part {
x: u32,
m: u32,
a: u32,
s: u32,
}
impl PartSortingMess {
fn parser(input: &str) -> IResult<&str, Self> {
todo!()
}
}
|