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

Function check

project_euler/problem_104/sol1.py:21–67  ·  view source on GitHub ↗

Takes a number and checks if it is pandigital both from start and end >>> check(123456789987654321) True >>> check(120000987654321) False >>> check(1234567895765677987654321) True

(number: int)

Source from the content-addressed store, hash-verified

19
20
21def check(number: int) -> bool:
22 """
23 Takes a number and checks if it is pandigital both from start and end
24
25
26 >>> check(123456789987654321)
27 True
28
29 >>> check(120000987654321)
30 False
31
32 >>> check(1234567895765677987654321)
33 True
34
35 """
36
37 check_last = [0] * 11
38 check_front = [0] * 11
39
40 # mark last 9 numbers
41 for _ in range(9):
42 check_last[int(number % 10)] = 1
43 number = number // 10
44 # flag
45 f = True
46
47 # check last 9 numbers for pandigitality
48
49 for x in range(9):
50 if not check_last[x + 1]:
51 f = False
52 if not f:
53 return f
54
55 # mark first 9 numbers
56 number = int(str(number)[:9])
57
58 for _ in range(9):
59 check_front[int(number % 10)] = 1
60 number = number // 10
61
62 # check first 9 numbers for pandigitality
63
64 for x in range(9):
65 if not check_front[x + 1]:
66 f = False
67 return f
68
69
70def check1(number: int) -> bool:

Callers 1

solutionFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected