Sum of the digits of n is substring of n: Difference between revisions
Sum of the digits of n is substring of n (view source)
Revision as of 19:43, 14 April 2021
, 3 years ago→{{header|Python}}: (abstracted out the formatting of the full script version)
m (→{{header|Python}}: (abstracted out the formatting of the full script version)) |
|||
Line 207:
from functools import reduce
from itertools import chain
Line 223 ⟶ 224:
def main():
'''Matches in [0..999]'''
print(▼
xs = list(▼
▲ digitSumIsSubString,
(str(n) for n in range(0, limit))▼
)▼
)
print(f'{len(xs)} matches < {limit}:\n')▼
# ----------------------- DISPLAY ------------------------
▲ print(
'\n'.join(▼
# showMatches :: (String -> Bool) -> Int -> String
' '.join(cell.rjust(w, ' ') for cell in row)▼
def showMatches(p):
for row in chunksOf(10)(xs)▼
'''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 []
▲ xs = list(
chain.from_iterable(
)
)
w = len(xs[-1])
▲ '\n'.join(
▲ ' '.join(cell.rjust(w, ' ') for cell in row)
▲ for row in chunksOf(10)(xs)
)
▲ )
return go
|