mirror of
https://github.com/bvanroll/advent_of_code_2022.git
synced 2025-08-29 11:42:39 +00:00
i'm taking a break
This commit is contained in:
@@ -7,5 +7,3 @@ edition = "2021"
|
|||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
rfd = "0.10.0"
|
rfd = "0.10.0"
|
||||||
|
|
||||||
phf = { version = "0.11", default-features = false }
|
|
||||||
|
@@ -56,3 +56,28 @@ static COUNTRIES: phf::Map<&'static str, &'static str> = phf_map! {
|
|||||||
"UK" => "United Kingdom",
|
"UK" => "United Kingdom",
|
||||||
};
|
};
|
||||||
```
|
```
|
||||||
|
|
||||||
|
this gave some issues when trying to import the crate (something with the macro's).
|
||||||
|
I couldn't find the fix for this in the documentation so i decided in the end to go back to the ugly but native solution
|
||||||
|
|
||||||
|
example of the errors:
|
||||||
|
|
||||||
|
```
|
||||||
|
error[E0432]: unresolved import `phf::phf_map`
|
||||||
|
--> src\main.rs:5:5
|
||||||
|
|
|
||||||
|
5 | use phf::phf_map;
|
||||||
|
| ^^^^^^^^^^^^ no `phf_map` in the root
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
```
|
||||||
|
error: cannot determine resolution for the macro `phf_map`
|
||||||
|
--> src\main.rs:7:49
|
||||||
|
|
|
||||||
|
7 | pub static scores: phf::Map<&'static str, u8> = phf_map! (
|
||||||
|
| ^^^^^^^
|
||||||
|
|
|
||||||
|
= note: import resolution is stuck, try simplifying macro imports
|
||||||
|
```
|
||||||
|
|
||||||
|
@@ -1,14 +1,14 @@
|
|||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
use std::fs::File;
|
use std::fs::File;
|
||||||
use std::io::{BufRead, BufReader};
|
use std::io::{BufRead, BufReader};
|
||||||
use phf::phf_map;
|
use std::iter::Iterator;
|
||||||
|
|
||||||
|
|
||||||
static scores: phf::Map<&'static str, u8> = phf_map! (
|
pub const scores:HashMap<&str, u32> = HashMap::from([
|
||||||
"A" => 1, //rock
|
("A",1), //rock
|
||||||
"B" => 2, //paper
|
("B",2), //paper
|
||||||
"C" => 3, //scizzors
|
("C",3) //scizzors
|
||||||
);
|
]);
|
||||||
|
|
||||||
// figuring out a way to do this :/
|
// figuring out a way to do this :/
|
||||||
// 1 2 = lose
|
// 1 2 = lose
|
||||||
@@ -18,27 +18,27 @@ static scores: phf::Map<&'static str, u8> = phf_map! (
|
|||||||
// 3 1 = lose
|
// 3 1 = lose
|
||||||
// 3 2 = win
|
// 3 2 = win
|
||||||
|
|
||||||
static possibilities: phf::Map<&'static u8, &'static u8> = phf_map! {
|
static possibilities: HashMap<u32,u32> = HashMap::from([
|
||||||
12 => 0,
|
(12,0),
|
||||||
13 => 6,
|
(13,6),
|
||||||
21 => 6,
|
(21,6),
|
||||||
23 => 0,
|
(23,0),
|
||||||
31 => 0,
|
(31,0),
|
||||||
32 => 6,
|
(32,6),
|
||||||
11 => 3,
|
(11,3),
|
||||||
22 => 3,
|
(22,3),
|
||||||
33 => 3,
|
(33,3)
|
||||||
};
|
]);
|
||||||
|
|
||||||
static shape_map: phf::Map<&'static String, &'static String> = phf_map! {
|
static shape_map: HashMap<&str, &str> = [
|
||||||
"X" => "A",
|
("X","A"),
|
||||||
"Y" => "B",
|
("Y","B"),
|
||||||
"Z" => "C",
|
("Z","C")
|
||||||
};
|
].iter().cloned().collect();
|
||||||
|
|
||||||
struct Play {
|
struct Play {
|
||||||
them: u8,
|
them: u32,
|
||||||
you: u8
|
you: u32
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -63,9 +63,9 @@ fn main() {
|
|||||||
|
|
||||||
fn parse_line(line: String) -> Play {
|
fn parse_line(line: String) -> Play {
|
||||||
let mut temp = line.split(' ').collect::<Vec<&str>>();
|
let mut temp = line.split(' ').collect::<Vec<&str>>();
|
||||||
return Play {them: scores[temp[0].parse().unwrap()], you: scores[temp[1].parse().unwrap()] }
|
return Play {them: scores[temp[0]].clone(), you: scores[temp[1]].clone() }
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_score(p: Play) -> u8 {
|
fn get_score(p: Play) -> u32 {
|
||||||
return possibilities[p.you*10+p.them]+scores[p.you];
|
return possibilities[&(p.you*10+p.them)]+&p.you;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user