Harshad or Niven series: Difference between revisions
Content deleted Content added
m →Python: Functional: Updated primitives |
m →Python: Functional: Pruned out one import. |
||
Line 3,217: | Line 3,217: | ||
>>> </lang> |
>>> </lang> |
||
And we |
And we could also sum digits more directly (without string coercion) while still preserving functional composition: |
||
{{Works with|Python|3.7}} |
{{Works with|Python|3.7}} |
||
<lang python>'''Harshad or Niven series''' |
<lang python>'''Harshad or Niven series''' |
||
from itertools import |
from itertools import count, dropwhile, islice |
||
Line 3,228: | Line 3,228: | ||
def harshads(): |
def harshads(): |
||
'''Harshad series''' |
'''Harshad series''' |
||
return ( |
|||
x for x in count(1) |
|||
if 0 == x % digitSum(x) |
|||
return chain.from_iterable( |
|||
map(go, count(1)) |
|||
) |
) |
||
Line 3,333: | Line 3,332: | ||
# MAIN --- |
# MAIN --- |
||
if __name__ == '__main__': |
if __name__ == '__main__': |
||
main() |
main()</lang> |
||
</lang> |
|||
{{Out}} |
{{Out}} |
||
<pre>Harshad or Niven series: |
<pre>Harshad or Niven series: |