Content deleted Content added
Loadmaster (talk | contribs) →The algorithm: reformat Algol code |
Quuxplusone (talk | contribs) rv recent changes to formatting, coloring; use <code> tags for formatting for now |
||
Line 9:
<code>
'''begin integer''' i; '''real''' y; '''real array''' a[0:10];
'''real procedure''' f(t); '''real''' t; '''
'''for''' i := 0 '''
'''
'''
▲ '''for''' i := 10 '''step''' -1 '''until''' 0 '''do'''
▲ '''end'''
'''end'''
</code>
Line 34 ⟶ 25:
The problem with the usually specified function is that the term 5*t^3 gives overflows in almost all languages for very large negative values.
==[[Perl golf]]==
The following [[Perl]] implementation is 79 [[byte]]s.
<code>
map print(($_>400?"TOO LARGE":$_).$/),reverse map 5*($x=<>)**3+sqrt abs$x,1..11
</
==Python version==
The following Python version of the algorithm uses the common Python idiom of using a list instead of an array, (although there is an array module available):
<code>
from math import sqrt
def f(t):
return sqrt(abs(t))+5*t**3
a = [int(raw_input()) for i in range(11)]
for i in range(10,-1,-1):
y = f(a[i])
if y > 400:
print i, "TOO LARGE"
else:
print i, y
</
==References==
Line 65 ⟶ 56:
[[Category:Algorithms]]
[[Category:Donald Knuth]]
[[Category:
[[Category:Articles with example ALGOL 60 code]]
[[Category:Articles with example Perl code]]
|