@@ -11,8 +11,8 @@ const_assert!(i128::MAX > 4 * PART2_SHIFT as CalcInt * PART2_SHIFT as CalcInt);
11
11
12
12
pub fn solve ( input : & str ) -> ( usize , usize ) {
13
13
let machines = Machine :: parse_all ( input)
14
- . filter_map ( |m| m . ok ( ) )
15
- . collect :: < Vec < _ > > ( ) ;
14
+ . collect :: < Result < Vec < _ > , _ > > ( )
15
+ . unwrap ( ) ;
16
16
17
17
( part1 ( & machines) , part2 ( & machines) )
18
18
}
@@ -45,16 +45,6 @@ struct Machine {
45
45
b_action : [ StoreInt ; 2 ] ,
46
46
}
47
47
48
- #[ derive( Error , Debug ) ]
49
- enum MachineParseError {
50
- #[ error( "Wrong Format" ) ]
51
- WrongNumberFormat ( #[ from] ParseIntError ) ,
52
- #[ error( "Wrong Format" ) ]
53
- WrongFormat ,
54
- #[ error( "Not enough Data" ) ]
55
- NotEnoughData ,
56
- }
57
-
58
48
impl Machine {
59
49
fn solve ( & self ) -> Option < Solution > {
60
50
// prize = a_presses * a_action + b_presses * b_action
@@ -86,14 +76,24 @@ impl Machine {
86
76
}
87
77
}
88
78
79
+ #[ derive( Error , Debug ) ]
80
+ enum MachineParseError {
81
+ #[ error( "Wrong Format" ) ]
82
+ WrongNumberFormat ( #[ from] ParseIntError ) ,
83
+ #[ error( "Wrong Format" ) ]
84
+ WrongFormat ,
85
+ #[ error( "Not enough Data" ) ]
86
+ NotEnoughData ,
87
+ }
88
+
89
89
impl FromStr for Machine {
90
90
type Err = MachineParseError ;
91
91
92
92
fn from_str ( s : & str ) -> Result < Self , Self :: Err > {
93
93
fn parse_button ( line : & str , name : & str ) -> Result < ( StoreInt , StoreInt ) , MachineParseError > {
94
94
line. strip_prefix ( & format ! ( "Button {}: X+" , name) )
95
95
. and_then ( |rest| rest. split_once ( ", Y+" ) )
96
- . ok_or ( MachineParseError :: WrongFormat ) // Would want WrongFormat, but then the typechecker gets confused
96
+ . ok_or ( MachineParseError :: WrongFormat )
97
97
. and_then ( |( x, y) | Ok ( ( x. parse ( ) ?, y. parse ( ) ?) ) )
98
98
}
99
99
0 commit comments