lots of stuff ive done.
maybe a status would be good?
This commit is contained in:
@@ -0,0 +1,117 @@
|
||||
use aoc::read_data;
|
||||
use crate::RPSOutcome::{Loss, Tie, Win};
|
||||
use crate::RPSPlays::{Paper, Rock, Scissors};
|
||||
|
||||
#[derive(Debug)]
|
||||
enum RPSOutcome {
|
||||
Win,
|
||||
Loss,
|
||||
Tie,
|
||||
}
|
||||
#[derive(Debug, Clone)]
|
||||
enum RPSPlays {
|
||||
Rock,
|
||||
Paper,
|
||||
Scissors,
|
||||
}
|
||||
|
||||
fn str_to_rps(input: &str) -> RPSPlays {
|
||||
println!("STR_TO_RPS -> {input}");
|
||||
match input {
|
||||
"A" => { Rock }
|
||||
"B" => { Paper }
|
||||
"C" => { Scissors }
|
||||
_ => { unreachable!("Invalid Conversion"); }
|
||||
}
|
||||
}
|
||||
|
||||
fn play_to_score(input: &str) -> u32 {
|
||||
match str_to_rps(input) {
|
||||
Rock => 1,
|
||||
Paper => 2,
|
||||
Scissors => 3
|
||||
}
|
||||
}
|
||||
|
||||
fn need_to_loose(them: RPSPlays) -> RPSPlays {
|
||||
match them {
|
||||
Rock => { Scissors }
|
||||
Paper => { Rock }
|
||||
Scissors => { Paper }
|
||||
}
|
||||
}
|
||||
|
||||
fn need_to_tie(them: RPSPlays) -> RPSPlays {
|
||||
them
|
||||
}
|
||||
|
||||
fn need_to_win(them: RPSPlays) -> RPSPlays {
|
||||
let result = match them {
|
||||
Rock => { Paper }
|
||||
Paper => { Scissors }
|
||||
Scissors => { Rock }
|
||||
};
|
||||
println!("Checking on {them:?} to win / {result:?}");
|
||||
result
|
||||
}
|
||||
|
||||
fn str_to_desired_outcome(input: &str) -> RPSOutcome {
|
||||
match input {
|
||||
"X" => { Loss }
|
||||
"Y" => { Tie }
|
||||
"Z" => { Win }
|
||||
_ => { unreachable!("Invalid Requested outcome {}", input); }
|
||||
}
|
||||
}
|
||||
|
||||
fn win_loose_tie_score(them: RPSPlays, me: RPSPlays) -> u32 {
|
||||
match (them, me) {
|
||||
(Rock, Rock) | (Paper, Paper) | (Scissors, Scissors) => 3,
|
||||
(Rock, Scissors) | (Paper, Rock) | (Scissors, Paper) => 0,
|
||||
_ => 6
|
||||
}
|
||||
}
|
||||
|
||||
fn points_for_play(to_score: RPSPlays) -> u32 {
|
||||
match to_score {
|
||||
Rock => { 1 }
|
||||
Paper => { 2 }
|
||||
Scissors => { 3 }
|
||||
}
|
||||
}
|
||||
|
||||
fn score_game(them: RPSPlays, me: RPSPlays) -> u32 {
|
||||
win_loose_tie_score(them, me.clone()) + points_for_play(me)
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let binding = read_data("2022_02_data.txt");
|
||||
let mut running_total = 0;
|
||||
let mut goal = Win;
|
||||
let lines = binding.lines();
|
||||
for line in lines {
|
||||
println!("__________STARTING TO PROCESS ||[{line}]||");
|
||||
let (them, me) = line.split_once(" ").unwrap();
|
||||
let them_rps = str_to_rps(them);
|
||||
println!("MATCHED OUT TO ||{:?}||{:?}", them_rps, str_to_desired_outcome(me));
|
||||
let my_play = match str_to_desired_outcome(me) {
|
||||
Win => {
|
||||
need_to_win(them_rps.clone())
|
||||
}
|
||||
Loss => {
|
||||
goal = Loss;
|
||||
need_to_loose(them_rps.clone())
|
||||
}
|
||||
Tie => {
|
||||
goal = Tie;
|
||||
need_to_tie(them_rps.clone())
|
||||
}
|
||||
};
|
||||
let game_score = score_game(them_rps.clone(), my_play.clone());
|
||||
println!("They play {:?} I play {:?} to {:?}", them_rps, my_play, goal);
|
||||
println!("SCORE = {}", game_score);
|
||||
running_total += game_score;
|
||||
}
|
||||
println!("Total = {running_total}");
|
||||
}
|
||||
// 11258
|
||||
Reference in New Issue
Block a user