dailyprogrammer 390
This commit is contained in:
parent
d23a41f711
commit
19e92d4115
2 changed files with 19 additions and 0 deletions
16
python/dailyprogrammer/#390 - Number of 1s.py
Normal file
16
python/dailyprogrammer/#390 - Number of 1s.py
Normal file
|
@ -0,0 +1,16 @@
|
||||||
|
def count1(n):
|
||||||
|
x = str(n)
|
||||||
|
count = 0
|
||||||
|
for index, digit in enumerate(x[::-1]):
|
||||||
|
digit = int(digit)
|
||||||
|
if digit != 0:
|
||||||
|
if digit == 1:
|
||||||
|
numberAfter = x[len(x) - index:] or '0'
|
||||||
|
count += int(numberAfter) + 1
|
||||||
|
else:
|
||||||
|
count += 10 ** index
|
||||||
|
count += int(10 ** (index - 1) * index * digit)
|
||||||
|
return count
|
||||||
|
|
||||||
|
|
||||||
|
print(count1(3**35))
|
|
@ -5,6 +5,9 @@
|
||||||
|
|
||||||
[The Subreddit](https://reddit.com/r/dailyprogrammer)
|
[The Subreddit](https://reddit.com/r/dailyprogrammer)
|
||||||
|
|
||||||
|
- #390 - Number of 1s
|
||||||
|
- [Solution](%23390%20-%20Number%20of%201s.py)
|
||||||
|
- [Reddit Post](https://www.reddit.com/r/dailyprogrammer/comments/neg49j/20210517_challenge_390_difficult_number_of_1s/)
|
||||||
- #391 - ABACABA
|
- #391 - ABACABA
|
||||||
- [Solution](%23391%20-%20ABACABA.py)
|
- [Solution](%23391%20-%20ABACABA.py)
|
||||||
- [Reddit Post](https://www.reddit.com/r/dailyprogrammer/comments/njxq95/20210524_challenge_391_easy_the_abacaba_sequence/)
|
- [Reddit Post](https://www.reddit.com/r/dailyprogrammer/comments/njxq95/20210524_challenge_391_easy_the_abacaba_sequence/)
|
||||||
|
|
Loading…
Reference in a new issue