You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
46 lines
1.1 KiB
46 lines
1.1 KiB
use std::fs::File; |
|
use std::io::BufRead; |
|
use std::io::BufReader; |
|
use std::path::PathBuf; |
|
|
|
use clap::Parser; |
|
|
|
#[derive(Parser)] |
|
struct Cli { |
|
filename: PathBuf, |
|
} |
|
|
|
fn main() { |
|
let cli = Cli::parse(); |
|
let file = File::open(cli.filename).expect("Can't read file"); |
|
let reader = BufReader::new(file); |
|
|
|
let mut score = 0; |
|
for line in reader.lines() { |
|
let line = line.unwrap(); |
|
if line.is_empty() { |
|
continue; |
|
} |
|
let mut play = line.trim().split(" "); |
|
let their_play = play.next().unwrap(); |
|
let my_play = play.next().unwrap(); |
|
|
|
// A/X => Rock |
|
// B/Y => Paper |
|
// C/Z => Scissors |
|
match (their_play, my_play) { |
|
("A", "Y") | ("B", "Z") | ("C", "X") => score += 6, // win |
|
("A", "X") | ("B", "Y") | ("C", "Z") => score += 3, // draw |
|
_ => (), // loss |
|
} |
|
|
|
match my_play { |
|
"Z" => score += 3, |
|
"Y" => score += 2, |
|
"X" => score += 1, |
|
_ => (), |
|
} |
|
} |
|
|
|
println!("Your score: {}", score); |
|
}
|
|
|