Quest 1
This commit is contained in:
parent
2043541679
commit
fb57f30ee6
4 changed files with 52 additions and 1 deletions
6
.gitignore
vendored
6
.gitignore
vendored
|
@ -18,4 +18,8 @@ Cargo.lock
|
||||||
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
|
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
|
||||||
# and can be added to the global gitignore or merged into this file. For a more nuclear
|
# and can be added to the global gitignore or merged into this file. For a more nuclear
|
||||||
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
|
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
|
||||||
#.idea/
|
#.idea/
|
||||||
|
|
||||||
|
# Added by cargo
|
||||||
|
|
||||||
|
/target
|
||||||
|
|
6
Cargo.toml
Normal file
6
Cargo.toml
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
[package]
|
||||||
|
name = "ec"
|
||||||
|
version = "0.1.0"
|
||||||
|
edition = "2021"
|
||||||
|
|
||||||
|
[dependencies]
|
1
data/quest-1.txt
Normal file
1
data/quest-1.txt
Normal file
|
@ -0,0 +1 @@
|
||||||
|
CCAAACACAACCAABAACABACBCCBBABBCAABCACBCBCCABAAACBBBCCACCBAACABBBBCBAAAACABACACBACACCCACACABABACCCCAABBABABBCCCBCBCBBCBBCACBBBAACCCBACBAABACABACAAACABCBCBCBCBCCBBAABBABAAABCCAABBCCABCACCCBBBCCAABBBCACACAACABCCACBBBBBCCCABBACCBAACABCAACCCCABBBCCCBCBBBCABACCCCCCACBBBCBACABCABBBCCBBBCCABACCBCCBBAABABBCCBCBABCCCAACAACCBBCCCACACAACAAABABBCBAABABCCCABABCAABABBBCBCCAAABABCAACAABBACCBCBABAABCAAABBBACBCACAACCBAACACABCBABABBAAACBAACCCCBCABAACBBABCBCABCAABABABACBAABCCABCABBCBCABBBBBABBBBAAABBACBAACBCABCCBCBACCBABBCBACCABAAAABCAACAABCABAABCCCAAABBAAABAACCAACCBBCBCBAAAAAABBAAABABBCCCBAACCABACCCBBBBBCBABCACCACBBACBBBBCABBCCCAACBACBAAABACACCABBCBCBACABBCACBABAAAACCCBAACACACBCCBBBAACCAACBBACCCBABACAACBCABBBACBBBBCCBCCBBCBBBBAACAACBBCCCBABBABBBBCAACBBACBACCACAAACCCBBCCABBCABCCBBBCAABBACBCBBAABCACBCBABCBBBACBAAAACBABCBABAACABCCABCBBAABCAACCCCABCBBBCCCBBBCABBBABBCACACCCCCBABCABBCCCAABACBCAAACCCCBBAACABBAACCBBCBBBABBBBAABCBCACABACBACBBBBACACCAACAABACBBBAACCBABBBBABBBBAAACBAAAAABBCCCACCACAACBAABBCAAABCCCCCB
|
40
src/bin/quest-1.rs
Normal file
40
src/bin/quest-1.rs
Normal file
|
@ -0,0 +1,40 @@
|
||||||
|
use std::{collections::HashMap, path::PathBuf};
|
||||||
|
|
||||||
|
type Result<T> = std::result::Result<T, Box<dyn std::error::Error>>;
|
||||||
|
|
||||||
|
fn main() -> Result<()> {
|
||||||
|
println!("Quest 1!");
|
||||||
|
let file_path = PathBuf::from("./data/quest-1.txt");
|
||||||
|
|
||||||
|
let data = std::fs::read_to_string(file_path)?;
|
||||||
|
|
||||||
|
let counter = quest(&data);
|
||||||
|
|
||||||
|
println!("Result: {counter}");
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
fn quest(data: &str) -> i32 {
|
||||||
|
let table = HashMap::from([('A', 0), ('B', 1), ('C', 3)]);
|
||||||
|
|
||||||
|
let mut counter = 0;
|
||||||
|
for beast in data.chars() {
|
||||||
|
if let Some(potions) = table.get(&beast) {
|
||||||
|
counter += potions;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
counter
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod tests {
|
||||||
|
use super::quest;
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn sample() {
|
||||||
|
let data = "ABBAC";
|
||||||
|
let result = quest(data);
|
||||||
|
assert_eq!(result, 5);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue