Untitled

mail@pastecode.io avatar
unknown
rust
2 years ago
1.0 kB
8
Indexable
Never
use std::collections::HashMap;
use std::fs;
use std::io::BufRead;
use std::path::PathBuf;
use std::ptr::hash;

fn get_priority(char: char) -> u32 {
    let mut char_as_u32 = char as u32;
    if char.is_ascii_lowercase() {
        char_as_u32 - 96
    } else {
        char_as_u32 + 27 - 65
    }
}

fn get_duplicate_charaters(mut line: String) -> char {
    let second_part = line.split_off(line.len() / 2);
    let first_part = line;

    for x in first_part.chars() {
        for y in second_part.chars() {
            if x == y {
                return x;
            }
        }
    }
    'a'

}

fn main() {
    let data = fs::read(PathBuf::from("data.txt")).unwrap();
    let data_lines = data.lines();
    let mut total_value: u32 = 0;
    let mut duplicates: Vec<char> = Vec::new();
    for line in data_lines {
        let res = get_duplicate_charaters(line.unwrap());
        duplicates.push(res)

    }
    for a in duplicates {
        total_value += get_priority(a);
    }
    println!("{}", total_value)
}