Lachlan Jacob пре 5 година
родитељ
комит
0eaabc9478
3 измењених фајлова са 35 додато и 0 уклоњено
  1. 16
    0
      728/main.py
  2. 16
    0
      728/problem.txt
  3. 3
    0
      728/run.sh

+ 16
- 0
728/main.py Прегледај датотеку

@@ -0,0 +1,16 @@
class Solution:
def selfDividingNumbers(self, left, right):
result = []
for x in range(left, right + 1):
ok = True
for c in str(x):
if c == '0' or x % int(c) != 0:
ok = False
break
if ok:
result.append(x)
return result

s = Solution()
print("Expected: [1, 2, 3, 4, 5, 6, 7, 8, 9, 11, 12, 15, 22]")
print("Got:", str(s.selfDividingNumbers(1, 22)))

+ 16
- 0
728/problem.txt Прегледај датотеку

@@ -0,0 +1,16 @@
A self-dividing number is a number that is divisible by every digit it contains.

For example, 128 is a self-dividing number because 128 % 1 == 0, 128 % 2 == 0, and 128 % 8 == 0.

Also, a self-dividing number is not allowed to contain the digit zero.

Given a lower and upper number bound, output a list of every possible self dividing number, including the bounds if possible.

Example 1:

Input:
left = 1, right = 22
Output: [1, 2, 3, 4, 5, 6, 7, 8, 9, 11, 12, 15, 22]

Note:
The boundaries of each input argument are 1 <= left <= right <= 10000.

+ 3
- 0
728/run.sh Прегледај датотеку

@@ -0,0 +1,3 @@
#!/bin/bash

python3 main.py

Loading…
Откажи
Сачувај