Pythagorean triples: Difference between revisions
Content added Content deleted
(It's been a week and the only thing that changed doesn't really affect anything. We're good to go to a full task.) |
(Added PicoLisp) |
||
Line 740: | Line 740: | ||
In practice, this solution runs considerably slower than the previous one, due primarily to passing <tt>gather</tt>/<tt>take</tt> values up many levels of dynamic scope. Eventually this may be optimized. Also, this solution currently chews up gigabytes of memory, while the previous solution stays at a quarter gig or so. This likely indicates a memory leak somewhere in [[niecza]]. |
In practice, this solution runs considerably slower than the previous one, due primarily to passing <tt>gather</tt>/<tt>take</tt> values up many levels of dynamic scope. Eventually this may be optimized. Also, this solution currently chews up gigabytes of memory, while the previous solution stays at a quarter gig or so. This likely indicates a memory leak somewhere in [[niecza]]. |
||
=={{header|PicoLisp}}== |
|||
{{trans|C}} |
|||
<lang PicoLisp>(for (Max 10 (>= 100000000 Max) (* Max 10)) |
|||
(let (Total 0 Prim 0 In (3 4 5)) |
|||
(recur (In) |
|||
(let P (apply + In) |
|||
(when (>= Max P) |
|||
(inc 'Prim) |
|||
(inc 'Total (/ Max P)) |
|||
(for Row |
|||
(quote |
|||
(( 1 -2 2) ( 2 -1 2) ( 2 -2 3)) |
|||
(( 1 2 2) ( 2 1 2) ( 2 2 3)) |
|||
((-1 2 2) (-2 1 2) (-2 2 3)) ) |
|||
(recurse |
|||
(mapcar '((U) (sum * U In)) Row) ) ) ) ) ) |
|||
(prinl "Up to " Max ": " Total " triples, " Prim " primitives.") ) )</lang> |
|||
Output: |
|||
<pre>Up to 10: 0 triples, 0 primitives. |
|||
Up to 100: 17 triples, 7 primitives. |
|||
Up to 1000: 325 triples, 70 primitives. |
|||
Up to 10000: 4858 triples, 703 primitives. |
|||
Up to 100000: 64741 triples, 7026 primitives. |
|||
Up to 1000000: 808950 triples, 70229 primitives. |
|||
Up to 10000000: 9706567 triples, 702309 primitives. |
|||
Up to 100000000: 113236940 triples, 7023027 primitives.</pre> |
|||
=={{header|Python}}== |
=={{header|Python}}== |