Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
TPK algorithm
(section)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
=== Implementations in more recent languages === ====[[C (programming language)|C]] implementation==== This shows a C implementation equivalent to the above ALGOL 60. <syntaxhighlight lang="C" line> #include <math.h> #include <stdio.h> double f(double t) { return sqrt(fabs(t)) + 5 * pow(t, 3); } int main(void) { double a[11] = {0}, y; for (int i = 0; i < 11; i++) scanf("%lf", &a[i]); for (int i = 10; i >= 0; i--) { y = f(a[i]); if (y > 400) printf("%d TOO LARGE\n", i); else printf("%d %.16g\n", i, y); } } </syntaxhighlight> ====[[Python (programming language)|Python]] implementation==== This shows a Python implementation. <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> ====[[Rust (programming language)|Rust]] implementation==== This shows a Rust implementation. <syntaxhighlight lang="Rust" line> use std::{io, iter}; 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) { None => println!("{i} TOO LARGE"), Some(y) => println!("{i} {y}"), }); } </syntaxhighlight>
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)