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