Harshad or Niven series: Difference between revisions
Content deleted Content added
→Python: Functional: Added a functionally composed alternative to string coercion |
m →Python: Functional: Updated output (more horizontal compression) |
||
Line 2,487: | Line 2,487: | ||
# digitSum :: Int -> Int |
# digitSum :: Int -> Int |
||
def digitSum(n): |
def digitSum(n): |
||
'''The |
'''The Sum of the decimal digits of n.''' |
||
a = 0 |
a = 0 |
||
r = n |
r = n |
||
Line 2,512: | Line 2,512: | ||
fTable(__doc__ + ':\n')( |
fTable(__doc__ + ':\n')( |
||
lambda x: x.__name__ |
lambda x: x.__name__ |
||
)( |
)(showList)(lambda f: f(harshads()))([ |
||
firstTwenty, |
firstTwenty, |
||
firstAbove1000 |
firstAbove1000 |
||
Line 2,552: | Line 2,552: | ||
xShow, fxShow, f, xs |
xShow, fxShow, f, xs |
||
) |
) |
||
# showList :: [a] -> String |
|||
def showList(xs): |
|||
'''Stringification of a list.''' |
|||
return '[' + ','.join(repr(x) for x in xs) + ']' |
|||
Line 2,560: | Line 2,566: | ||
<pre>Harshad or Niven series: |
<pre>Harshad or Niven series: |
||
firstTwenty -> [1, |
firstTwenty -> [1,2,3,4,5,6,7,8,9,10,12,18,20,21,24,27,30,36,40,42] |
||
firstAbove1000 -> [1002]</pre> |
firstAbove1000 -> [1002]</pre> |
||