Practical numbers: Difference between revisions

→‎Composition of pure functions: Add Python types. Remove wrong and misleading Haskell type-comments.
mNo edit summary
(→‎Composition of pure functions: Add Python types. Remove wrong and misleading Haskell type-comments.)
Line 186:
from operator import mul
from functools import reduce
from typing import Any, List, Callable
 
 
#def isPractical :(n: Intint) -> Boolbool:
def isPractical(n):
'''True if n is a Practical number
(a member of OEIS A005153)
Line 200:
 
 
#def sumOfAnySubset :(xs: List[Intint]) -> IntCallable[[Any], -> BoolAny]:
def sumOfAnySubset(xs):
'''True if any subset of xs sums to n.
'''
Line 223 ⟶ 222:
 
# ------------------------- TEST -------------------------
#def main() -> None:: IO ()
def main():
'''Practical numbers in the range [1..333],
and the OEIS A005153 membership of 666.
Line 248 ⟶ 246:
# ----------------------- GENERIC ------------------------
 
#def chunksOf :(n: Intint) -> Callable[a[Any], -> [[a]Any]:
def chunksOf(n):
'''A series of lists of length n, subdividing the
contents of xs. Where the length of xs is not evenly
Line 261 ⟶ 258:
 
 
#def primeFactors :(n: Intint) -> List[Intint]:
def primeFactors(n):
'''A list of the prime factors of n.
'''
Line 287 ⟶ 283:
 
 
#def properDivisors :(n: Intint) -> List[Intint]:
def properDivisors(n):
'''The ordered divisors of n, excluding n itself.
'''
Line 303 ⟶ 298:
 
 
#def listTranspose :(xss: List[List[aint]]) -> List[List[aint]]:
def listTranspose(xss):
'''Transposed matrix'''
def go(xss):
Line 319 ⟶ 313:
 
 
#def until (p:: (a -> Boolbool) -> (a -> a) -> a -> aAny:
def until(p):
'''The result of repeatedly applying f until p holds.
The initial seed value is x.
Line 336 ⟶ 329:
# ---------------------- FORMATTING ----------------------
 
#def spacedTable :(rows: List[List[Stringint]]) -> Stringstr:
def spacedTable(rows):
'''Tabulation with right-aligned cells'''
columnWidths = [
Line 356 ⟶ 348:
if __name__ == '__main__':
main()</lang>
 
{{Out}}
<pre>77 OEIS A005153 numbers in [1..333]
Anonymous user