Sum of the digits of n is substring of n: Difference between revisions
Content added Content deleted
m (→{{header|Python}}: (abstracted out the formatting of the full script version)) |
|||
Line 207: | Line 207: | ||
from functools import reduce |
from functools import reduce |
||
from itertools import chain |
|||
Line 223: | Line 224: | ||
def main(): |
def main(): |
||
'''Matches in [0..999]''' |
'''Matches in [0..999]''' |
||
⚫ | |||
showMatches( |
|||
⚫ | |||
⚫ | |||
)(999) |
|||
⚫ | |||
⚫ | |||
⚫ | |||
) |
) |
||
w = len(xs[-1]) |
|||
⚫ | |||
# ----------------------- DISPLAY ------------------------ |
|||
⚫ | |||
⚫ | |||
# showMatches :: (String -> Bool) -> Int -> String |
|||
⚫ | |||
def showMatches(p): |
|||
⚫ | |||
'''A listing of the integer strings [0..limit] |
|||
which match the predicate p. |
|||
''' |
|||
def go(limit): |
|||
def triage(n): |
|||
s = str(n) |
|||
return [s] if p(s) else [] |
|||
⚫ | |||
chain.from_iterable( |
|||
⚫ | |||
) |
|||
) |
) |
||
) |
w = len(xs[-1]) |
||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
) |
|||
⚫ | |||
return go |
|||