Coin de Gamma
1 year ago
2 changed files with 53 additions and 0 deletions
@ -0,0 +1,52 @@
|
||||
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); |
||||
} |
File diff suppressed because one or more lines are too long
Loading…
Reference in new issue