MCPcopy Create free account
hub / github.com/TheAlgorithms/Python / list_truncated_nums

Function list_truncated_nums

project_euler/problem_037/sol1.py:59–74  ·  view source on GitHub ↗

Returns a list of all left and right truncated numbers of n >>> list_truncated_nums(927628) [927628, 27628, 92762, 7628, 9276, 628, 927, 28, 92, 8, 9] >>> list_truncated_nums(467) [467, 67, 46, 7, 4] >>> list_truncated_nums(58) [58, 8, 5]

(n: int)

Source from the content-addressed store, hash-verified

57
58
59def list_truncated_nums(n: int) -> list[int]:
60 """
61 Returns a list of all left and right truncated numbers of n
62 >>> list_truncated_nums(927628)
63 [927628, 27628, 92762, 7628, 9276, 628, 927, 28, 92, 8, 9]
64 >>> list_truncated_nums(467)
65 [467, 67, 46, 7, 4]
66 >>> list_truncated_nums(58)
67 [58, 8, 5]
68 """
69 str_num = str(n)
70 list_nums = [n]
71 for i in range(1, len(str_num)):
72 list_nums.append(int(str_num[i:]))
73 list_nums.append(int(str_num[:-i]))
74 return list_nums
75
76
77def validate(n: int) -> bool:

Callers 1

compute_truncated_primesFunction · 0.85

Calls 1

appendMethod · 0.45

Tested by

no test coverage detected