Add exercise 212, 258, fix clippy warnings
This commit is contained in:
parent
c5aa3d4abf
commit
6ff23340af
6 changed files with 260 additions and 4 deletions
|
@ -116,7 +116,7 @@ impl FromStr for Dice {
|
|||
fn from_str(s: &str) -> Result<Dice, Self::Err> {
|
||||
// Split string at "d" delimeter, parse elements into Dice struct containing u32s
|
||||
let dice = s
|
||||
.split("d")
|
||||
.split('d')
|
||||
.map(|x| x.parse::<u32>())
|
||||
.collect::<Result<Vec<u32>, ParseIntError>>();
|
||||
let dice = match dice {
|
||||
|
@ -149,7 +149,7 @@ fn main() {
|
|||
/// Main exercise loop
|
||||
fn e_364() {
|
||||
let input = fs::read_to_string("input.txt").unwrap();
|
||||
let dice: Result<Vec<Dice>, DiceError> = input.split("\n").map(|x| x.parse()).collect();
|
||||
let dice: Result<Vec<Dice>, DiceError> = input.split('\n').map(|x| x.parse()).collect();
|
||||
match dice {
|
||||
Ok(d) => d.iter().for_each(|x| println!("{}", x.roll_dice())),
|
||||
Err(DiceError::ParseInt(e)) => eprintln!("Could not parse integer: {:?}", e),
|
||||
|
@ -169,7 +169,7 @@ mod tests {
|
|||
Dice { count: 16, die: 2 }
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_error_handling() {
|
||||
assert!(matches!("3dx".parse::<Dice>(), Err(DiceError::ParseInt(_))));
|
||||
assert_eq!("3d3d3".parse::<Dice>(), Err(DiceError::ParseFields));
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue