Trabb Pardo–Knuth algorithm: Difference between revisions

Content added Content deleted
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: Line 1,910:
=={{header|Nim}}==
=={{header|Nim}}==
{{trans|Python}}
{{trans|Python}}
<lang nim>import math, rdstdin, strutils, algorithm
<lang nim>import math, rdstdin, strutils, algorithm, sequtils


proc f(x): float = x.abs.pow(0.5) + 5 * x.pow(3)
proc f(x: float): float = x.abs.pow(0.5) + 5 * x.pow(3)


proc ask: seq[float] =
proc ask: seq[float] =
readLineFromStdin("\n11 numbers: ").strip.split[0..10].map(parseFloat)
readLineFromStdin("11 numbers: ").strip.split[0..10].map(parseFloat)


var s = ask()
var s = ask()
reverse s
reverse s
for x in s:
for x in s:
let result = f x
let result = f(x)
stdout.write " ",x,":", if result > 400: "TOO LARGE!" else: $result
echo x, ": ", if result > 400: "TOO LARGE!" else: $result</lang>

echo ""</lang>
{{out}}
{{out}}
<pre>11 numbers: 1 2 3 4 5 6 7 8 9 10 11
<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}}==
=={{header|Objective-C}}==