Skip to content

Instantly share code, notes, and snippets.

@puma314
Created June 23, 2016 18:38
Show Gist options
  • Save puma314/f3c1af84c0b91e088abd0962ce3ddf1e to your computer and use it in GitHub Desktop.
Save puma314/f3c1af84c0b91e088abd0962ce3ddf1e to your computer and use it in GitHub Desktop.
import itertools
# line = map(int, raw_input().split(" "))
# n = line[0]
# m = line[1]
n = 8
m = 3
hplaces = 0
mplaces = 0
i = 0
while 7**i < n or 7**i < m:
if 7**i < n:
hplaces += 1
if 7**i < m:
mplaces += 1
i += 1
def base7(li):
res = 0
j = 0
for i in reversed(li):
res += i*(7**j)
j += 1
return res
li = range(7)
perms = itertools.permutations(li)
dis = set()
if hplaces + mplaces > 7:
print 0
else:
for perm in perms:
perm = list(perm)
hours = perm[:hplaces]
minutes = perm[hplaces: hplaces+mplaces]
b7hours = base7(hours)
b7mins = base7(minutes)
if b7hours < n and b7mins < m:
t = (b7hours, b7mins)
dis.add(t)
print len(dis)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment