I need to find the number of five-digit octal numbers in which all digits are different and no two odd or even digits are adjacent.
My code below gives the correct answer, but I'm not satisfied. Can you help me improve it or how would you solve this task?
from itertools import product
c = 0
for args in product((0, 1, 2, 3, 4, 5, 6, 7), repeat=5):
n1, n2, n3, n4, n5 = args
# no zero start
if n1 == 0: continue
if (n1 + n2) == 0: continue
if (n1 + n2 + n3) == 0: continue
if (n1 + n2 + n3 + n4) == 0: continue
if (n1 + n2 + n3 + n4 + n5) == 0: continue
# different digits
if (args.count(0) > 1 or args.count(1) > 1 or args.count(2) > 1
or args.count(3) > 1 or args.count(4) > 1 or args.count(5) > 1 or
args.count(6) > 1 or args.count(7) > 1): continue
# even odd even odd even or odd even odd even odd
if ((n1 % 2 == 0 and n2 % 2 != 0 and n3 % 2 == 0 and n4 % 2 != 0 and n5 % 2 == 0) or
(n1 % 2 != 0 and n2 % 2 == 0 and n3 % 2 != 0 and n4 % 2 == 0 and n5 % 2 != 0)):
c+=1
print(c) # 504 (correct)