solutions: 42

This commit is contained in:
Muhammad Nauman Raza 2024-12-06 13:39:44 +00:00
parent 48fe778c50
commit 93c73bb132
Signed by: devraza
GPG key ID: 91EAD6081011574B
2 changed files with 31 additions and 0 deletions

1
assets/input Normal file

File diff suppressed because one or more lines are too long

View file

@ -0,0 +1,30 @@
use std::fs;
fn main() {
let alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
let mut characters = vec![];
for c in alphabet.chars() {
characters.push(c);
}
let contents = fs::read_to_string("assets/input")
.expect("Could not read the input file").replace("\"\n", "");
let words = contents.split("\",\"").collect::<Vec<&str>>();
let mut triangles = 0;
for word in &words {
let mut total_index = 0;
for character in word.chars() {
let index = characters.iter().position(|c| *c == character).unwrap()+1;
total_index += index;
}
let position: f64 = ((-1 as f64)+(((1+8*total_index) as f64).sqrt() as f64))/2.;
if position.fract() == 0. {
triangles += 1;
}
}
println!("{}", triangles);
}