Talk:Heronian triangles: Difference between revisions
Dropping the product function and the a <= b <= c test (letting the generator component of the comprehension do that work)
(Perhaps worth dropping the 'product' import from itertools in the Python version ?) |
(Dropping the product function and the a <= b <= c test (letting the generator component of the comprehension do that work)) |
||
Line 8:
::::Thanks – that was fast.
::::On the topic of imports, I wonder if it might make good pedagogic (and perhaps engineering) sense to drop the import of ''product'' from ''itertools'', and let the list comprehension do the generation of cartesian products ?
::::The fact that list monads and list comprehensions yield cartesian products unassisted is one of their most interesting (and arguably central) properties, and perhaps we can demonstrate that more clearly by
:::: (where ''last'' is maxside+1)
::::'''Advantages''':
::::# The filtering happens earlier. Rather than first generating 8 million potential tuples and only then starting to filter, we immediately begin to filter in the inner ''for'' loop (or inner call to ''concat map'') of the process which is generating the cartesian product, and we never create the full oversized set in the first place.
::::#
::::# Apart from
::::[[User:Hout|Hout]] ([[User talk:Hout|talk]]) 10:11, 25 October 2015 (UTC)
|