Jump to content

Trabb Pardo–Knuth algorithm: Difference between revisions

Updated to work with Nim 1.4: added missing parameter type; added "import "sequtils". Also changed output to print a result per line.
m (→‎{{header|Julia}}: Updated to Julia 1)
(Updated to work with Nim 1.4: added missing parameter type; added "import "sequtils". Also changed output to print a result per line.)
Line 1,910:
=={{header|Nim}}==
{{trans|Python}}
<lang nim>import math, rdstdin, strutils, algorithm, sequtils
 
proc f(x: float): float = x.abs.pow(0.5) + 5 * x.pow(3)
 
proc ask: seq[float] =
readLineFromStdin("\n1111 numbers: ").strip.split[0..10].map(parseFloat)
 
var s = ask()
reverse s
for x in s:
let result = f (x)
stdout.writeecho " ",x, ": ", if result > 400: "TOO LARGE!" else: $result</lang>
 
echo ""</lang>
{{out}}
<pre>11 numbers: 1 2 3 4 5 6 7 8 9 10 11
11 numbers: 1 2 3 4 5 6 7 8 9 10 11
11.0:TOO LARGE! 10.0:TOO LARGE! 9.0:TOO LARGE! 8.0:TOO LARGE! 7.0:TOO LARGE! 6.0:TOO LARGE! 5.0:TOO LARGE! 4.0:322.0 3.0:136.7320508075689 2.0:41.41421356237309 1.0:6.0</pre>
11.0: TOO LARGE!
10.0: TOO LARGE!
9.0: TOO LARGE!
8.0: TOO LARGE!
7.0: TOO LARGE!
6.0: TOO LARGE!
5.0: TOO LARGE!
4.0: 322.0
3.0: 136.7320508075689
2.0: 41.41421356237309
1.0: 6.0</pre>
 
=={{header|Objective-C}}==
Anonymous user
Cookies help us deliver our services. By using our services, you agree to our use of cookies.