Created Hashmap for RPS
This commit is contained in:
parent
bd60b0dc5e
commit
b281043fec
4 changed files with 46 additions and 0 deletions
7
rust/day2/Cargo.lock
generated
Normal file
7
rust/day2/Cargo.lock
generated
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
# This file is automatically @generated by Cargo.
|
||||||
|
# It is not intended for manual editing.
|
||||||
|
version = 3
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "aoc-day2"
|
||||||
|
version = "0.1.0"
|
11
rust/day2/Cargo.toml
Normal file
11
rust/day2/Cargo.toml
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
[package]
|
||||||
|
name = "aoc-day2"
|
||||||
|
version = "0.1.0"
|
||||||
|
edition = "2021"
|
||||||
|
authors = ["Yohan Boujon <yoboujon@gmail.com>"]
|
||||||
|
|
||||||
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
|
||||||
|
[workspace]
|
10
rust/day2/src/main.rs
Normal file
10
rust/day2/src/main.rs
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
use crate::rps::get_converter;
|
||||||
|
|
||||||
|
use std::collections::HashMap;
|
||||||
|
mod rps;
|
||||||
|
|
||||||
|
fn main()
|
||||||
|
{
|
||||||
|
let converter : HashMap<char, rps::RockPaperScissors> = rps::get_converter();
|
||||||
|
println!("Hello world!");
|
||||||
|
}
|
18
rust/day2/src/rps.rs
Normal file
18
rust/day2/src/rps.rs
Normal file
|
@ -0,0 +1,18 @@
|
||||||
|
use std::collections::HashMap;
|
||||||
|
|
||||||
|
pub enum RockPaperScissors {
|
||||||
|
Rock,
|
||||||
|
Paper,
|
||||||
|
Scissors
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn get_converter() -> HashMap<char, RockPaperScissors> {
|
||||||
|
HashMap::from([
|
||||||
|
('A', RockPaperScissors::Rock),
|
||||||
|
('B', RockPaperScissors::Paper),
|
||||||
|
('C', RockPaperScissors::Scissors),
|
||||||
|
('X', RockPaperScissors::Rock),
|
||||||
|
('Y', RockPaperScissors::Paper),
|
||||||
|
('Z', RockPaperScissors::Scissors),
|
||||||
|
])
|
||||||
|
}
|
Loading…
Add table
Reference in a new issue