Law of cosines - triples: Difference between revisions
Content deleted Content added
m →Python ver 2: updated zipWith |
|||
Line 883: | Line 883: | ||
A variant Python draft based on dictionaries. |
A variant Python draft based on dictionaries. |
||
(Test functions are passed as parameters to the main function.) |
(Test functions are passed as parameters to the main function.) |
||
<lang python> |
<lang python>from itertools import (starmap) |
||
def f90(dct): |
|||
return lambda x2, ab, a, b: dct.get(x2, None) |
return lambda x2, ab, a, b: dct.get(x2, None) |
||
Line 925: | Line 928: | ||
unlines( |
unlines( |
||
zipWith( |
zipWith( |
||
lambda f |
lambda f, n: ( |
||
lambda ks=triangles(f, 13): ( |
lambda ks=triangles(f, 13): ( |
||
str(len(ks)) + ' solutions for ' + |
str(len(ks)) + ' solutions for ' + |
||
Line 954: | Line 957: | ||
# zipWith :: (a -> b -> c) -> [a] -> [b] -> [c] |
# zipWith :: (a -> b -> c) -> [a] -> [b] -> [c] |
||
def zipWith(f): |
def zipWith(f): |
||
return ( |
return lambda xs: lambda ys: ( |
||
list(starmap(f, zip(xs, ys))) |
|||
[f(a)(b) for (a, b) in zip(xs, ys)] |
|||
) |
) |
||
if __name__ == '__main__': |
|||
main()</lang> |
main()</lang> |
||
{{Out}} |
{{Out}} |
||
<pre>Triangles of maximum side 13 |
<pre>Triangles of maximum side 13 |