TPK algorithm: Difference between revisions

Content deleted Content added
Ricvelozo (talk | contribs)
No edit summary
Ricvelozo (talk | contribs)
No edit summary
Line 62:
</syntaxhighlight>
 
==[[Python (programming language)|Python]] implementation==
This shows a Python implementation.
 
Line 78:
else:
print(i, y)
</syntaxhighlight>
 
==[[Rust (programming language)|Rust]]==
This shows a Rust implementation.
<syntaxhighlight lang="Rust" line>
use std::io::{stdin, BufRead};
 
fn f(t: f64) -> f64 {
t.abs().sqrt() + 5.0 * t.powi(3)
}
 
fn main() {
let mut a = [0f64; 11];
for (t, input) in a.iter_mut().zip(stdin().lock().lines()) {
*t = input.unwrap().parse().unwrap();
}
 
for (i, &t) in a.iter().enumerate().rev() {
match f(t) {
y if y > 400.0 => println!("{} TOO LARGE", i),
y => println!("{} {}", i, y),
}
}
}
</syntaxhighlight>