You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
53 lines
1.2 KiB
53 lines
1.2 KiB
1 year ago
|
use std::fs::File;
|
||
|
use std::io::prelude::*;
|
||
|
|
||
|
|
||
|
fn ascore(s: &str) -> u32 {
|
||
|
let sr = s.replace("\"","");
|
||
|
let chars = sr.chars();
|
||
|
//println!("------>>>>{}", sr);
|
||
|
let mut sum = 0u32;
|
||
|
for (i, c) in sr.chars().enumerate() {
|
||
|
//println!(":[{}];", c);
|
||
|
let dd = (c as u32) - 64;
|
||
|
sum += dd;
|
||
|
//println!("{} {} {}", i, c, dd);
|
||
|
}
|
||
|
return sum;
|
||
|
}
|
||
|
|
||
|
fn main() {
|
||
|
//let name = "COLIN";
|
||
|
//let score = ascore(name);
|
||
|
|
||
|
let mut file = File::open("names.txt").unwrap();
|
||
|
let mut content = String::new();
|
||
|
file.read_to_string(&mut content).expect("cant read file");
|
||
|
let names_split = content.split(",");
|
||
|
let mut names: Vec<String> = Vec::new();
|
||
|
|
||
|
for name in names_split {
|
||
|
names.push(String::from(name));
|
||
|
}
|
||
|
names.sort();
|
||
|
|
||
|
//println!("{}", content);
|
||
|
|
||
|
let mut i = 1u32;
|
||
|
let mut sum = 0;
|
||
|
for nm in names {
|
||
|
let name = nm.as_str();
|
||
|
let score = ascore(name) * i;
|
||
|
sum += score;
|
||
|
println!("{} [{}, {}, {}]", name, ascore(name), i, ascore(name) * i);
|
||
|
i += 1;
|
||
|
//if i > 10 {
|
||
|
// break;
|
||
|
//}
|
||
|
//println!("{}", name);
|
||
|
}
|
||
|
//println!("len: ", names.len());
|
||
|
|
||
|
println!("score: {}", sum);
|
||
|
}
|