TPK algorithm: Difference between revisions

Content deleted Content added
Ricvelozo (talk | contribs)
Ricvelozo (talk | contribs)
 
(One intermediate revision by the same user not shown)
Line 105:
 
<syntaxhighlight lang="Rust" line>
use std::{io, iter::zip};
 
fn f(t: f64) -> Option<f64> {
let y = t.abs().sqrt() + 5.0 * t.powi(3);
(y <= 400.0).then_some(y)
}
 
fn main() {
let mut a = [0f64; 11];
for (t, input) in iter::zip(&mut a, io::stdin().lines()) {
*t = input.unwrap().parse().unwrap();
}
 
a.iter().enumerate().rev().for_each(|(i, &t)| match f(t) {
y if y > 400.0None => println!("{i} TOO LARGE"),
Some(y) => println!("{i} {y}"),
});
}