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.

37 lines
810 B

use std::fs::read_to_string;
use std::collections::HashSet;
fn sn(s: &str) -> u32 {
let st = String::from(s);
let mut res = 0;
for c in st.chars() {
if c == '"' {
continue;
}
let d = c as u32 - 64;
res += d;
//println!("{}", d);
}
return res;
}
fn main() {
let mut hs = HashSet::new();
for n in 1..200 {
let tn = (n * (n + 1)) / 2;
hs.insert(tn);
}
let mut count = 0;
for line in read_to_string("0042_words.txt").unwrap().lines() {
let sp = line.split(',');
for s in sp {
let n = sn(&s);
//println!("{} {}", s, n);
if hs.contains(&n) {
count += 1;
}
}
}
//let r = sn("SKY");
println!("{}", count);
}