Browse Source

042 ok

master
Coin de Gamma 1 year ago
parent
commit
a1fc0152ef
  1. 1
      042/0042_words.txt
  2. 37
      042/main.rs

1
042/0042_words.txt

File diff suppressed because one or more lines are too long

37
042/main.rs

@ -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…
Cancel
Save