Skip to content

Instantly share code, notes, and snippets.

@roger35972134
Created May 18, 2015 07:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save roger35972134/b99fb58f658c10fbb637 to your computer and use it in GitHub Desktop.
Save roger35972134/b99fb58f658c10fbb637 to your computer and use it in GitHub Desktop.
import itertools
def main():
print(__doc__)
排假(1, True)
排假(2, True)
排假(3)
排假(4)
排假(5)
def 排假(可休假天數= 4, 是否列出排假方式= False):
S= [d for d in range(1,30+1)]
k= 可休假天數
C= itertools.combinations(S, k)
周末= [6,7, 13,14, 20,21, 27,28]
初一十五= [1, 16, 30]
def 休假有連續(days):
答案= False
for n in range(len(days)-1):
d0= days[n]
d1= days[n+1]
if d1-d0==1:
答案= True
break
return 答案
def 休假在周末的天數大於2(days):
答案= False
天數= 0
for d in days:
if d in 周末:
天數 +=1
if 天數 >2: 答案= True
return 答案
def 休假在初一十五(days):
答案= False
for d in days:
if d in 初一十五:
答案= True
break
return 答案
D= []
for c in C:
if not any([
休假有連續(c),
休假在周末的天數大於2(c),
休假在初一十五(c)]):
D += [c]
print('可休假天數=%d, 排假方式總數= %5d'%(可休假天數,len(D)))
if 是否列出排假方式==True:
for n,d in enumerate(D):
print(d, end=', ')
if (n+1)%100==0:
print('')
print('...排假方式[',n+1,']...')
print('\n')
else:
print('(...省略...)\n')
if __name__== '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment