TPK algorithm: Difference between revisions

Content deleted Content added
Ricvelozo (talk | contribs)
Ricvelozo (talk | contribs)
 
(3 intermediate revisions by 2 users not shown)
Line 89:
<syntaxhighlight lang="python" line>
from math import sqrt
 
 
def f(t):
return sqrt(abs(t)) + 5 * t ** 3
 
 
a = [float(input()) for _ in range(11)]
for i, t in reversed(list(enumerate(a))):
y = f(t)
print(i, '"TOO LARGE'" if y > 400 else y)
</syntaxhighlight>
 
Line 103 ⟶ 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}"),
});
}