Skip to content

Instantly share code, notes, and snippets.

@crissilvaeng
Created October 24, 2022 18:38
Show Gist options
  • Save crissilvaeng/a89b42a038891bcb71bd7c9ddaf9ef77 to your computer and use it in GitHub Desktop.
Save crissilvaeng/a89b42a038891bcb71bd7c9ddaf9ef77 to your computer and use it in GitHub Desktop.
Exercism Poker Card to Cactus Kev's Poker Card
let mut chars = val.chars();
let suit = chars.next_back().unwrap().to_string();
let rank = chars.as_str();
let mut card: u32 = 0;
card |= match rank {
"2" => 1 << 16 ^ (0 << 8) + 2,
"3" => 1 << 17 ^ (1 << 8) + 3,
"4" => 1 << 18 ^ (2 << 8) + 5,
"5" => 1 << 19 ^ (3 << 8) + 7,
"6" => 1 << 20 ^ (4 << 8) + 11,
"7" => 1 << 21 ^ (5 << 8) + 13,
"8" => 1 << 22 ^ (6 << 8) + 17,
"9" => 1 << 23 ^ (7 << 8) + 19,
"T" => 1 << 24 ^ (8 << 8) + 23,
"J" => 1 << 25 ^ (9 << 8) + 29,
"Q" => 1 << 26 ^ (10 << 8) + 31,
"K" => (1 << 27) ^ (11 << 8) + 37,
"A" => 1 << 28 ^ (12 << 8) + 41,
_ => 0,
};
card |= match suit.as_str() {
"C" => 1 << 15, "D" => 1 << 14, "H" => 1 << 13, "S" => 1 << 12, _ => 0,
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment