Last active
January 4, 2020 14:14
-
-
Save U007D/f0466e4b9dca1376a80737f46eef2118 to your computer and use it in GitHub Desktop.
Code Golf Bowling Game
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fn main() { | |
let game = "X 7/ 9- X F8 ⑧/ F6 X X X8/" | |
.chars() | |
.filter(|c| !c.is_whitespace()) | |
.fold(Vec::new(), |mut rolls, roll| { | |
match roll { | |
'X' => rolls.push(10_u8), | |
'/' => rolls.push(10 - rolls.last().expect("invalid game score")), | |
c if c >= '0' && c <= '9' => rolls.push((u32::from(c) - 0x30) as u8), | |
c if c >= '⑤' && c <= '⑧' => rolls.push((u32::from(c) - 0x245f) as u8), | |
_ => rolls.push(0), | |
}; | |
rolls | |
}); | |
dbg!(game); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment