Skip to content

Instantly share code, notes, and snippets.

@U007D
Last active January 4, 2020 14:14
Show Gist options
  • Save U007D/f0466e4b9dca1376a80737f46eef2118 to your computer and use it in GitHub Desktop.
Save U007D/f0466e4b9dca1376a80737f46eef2118 to your computer and use it in GitHub Desktop.
Code Golf Bowling Game
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