Skip to content

Instantly share code, notes, and snippets.

@seven0525
Last active June 7, 2018 14:12
Show Gist options
  • Save seven0525/324dd7812f6514d479274847c4cb5afd to your computer and use it in GitHub Desktop.
Save seven0525/324dd7812f6514d479274847c4cb5afd to your computer and use it in GitHub Desktop.
「自作Python100本ノック」14日目(91本〜95本目) ref: https://qiita.com/ahpjop/items/dc68cc02bc2b2ac30669
def count_one(n):
counts = 0
for i in range(1,n+1):
str_i = str(i)
count = str_i.count("1")
counts += count
return counts
count_one(100)
def remocon(a,b):
target = b - a
min_count = 100
for o in range(100):
for f in range(100):
for t in range(100):
if o + 5 * f + 10 * t == target or -1 * o + -5 * f + -10 * t == target:
count = o + f + t
if min_count > count:
min_count = count
a_o = o
a_f = f
a_t = t
print(a_o, a_f, a_t)
remocon(10,5)
ans = set([])
for i in l:
while i % 2 == 0:
i = i // 2
  ans.add(i)
print(len(ans))
def substract_game(n, ng_words):
count = 0
flag = 0
a = ng_words[0]
b = ng_words[1]
c = ng_words[2]
while count < 100 and n != (a or b or c) and n >=4:
if not (n-3 in ng_words):
count += 1
n = n-3
elif not (n-2 in ng_words):
count += 1
n = n-2
elif not (n-1 in ng_words):
count += 1
n = n-1
else:
flag = 0
break
if (n == 1 or n == 2 or n ==3) and count<=99:
n = 0
flag = 1
if n > 0:
flag = 0
if flag == 1:
print('YES')
else:
print('NO')
substract_game(100, [29,54,43])
from datetime import date, timedelta
def check_date(today):
Y, M, D = [int(n) for n in today.split('/')]
dt = date(Y, M, D)
while True:
if Y % M == 0 and (Y / M) % D == 0:
break
dt += timedelta(days=1)
Y = dt.year
M = dt.month
D = dt.day
print(dt.strftime('%Y/%m/%d'))
check_date("2017/05/11")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment