Skip to content

Instantly share code, notes, and snippets.

@cacapon
Last active October 25, 2019 07:12
Show Gist options
  • Save cacapon/4390164a4f39d7c444df307e7997b35a to your computer and use it in GitHub Desktop.
Save cacapon/4390164a4f39d7c444df307e7997b35a to your computer and use it in GitHub Desktop.
麻雀の組み合わせを調べるプログラム(頭は考慮してません)
import itertools
import collections
from copy import deepcopy
pai = [
'mauzu_1','sozu_1','pinzu_1',
'mauzu_2','sozu_2','pinzu_2',
'mauzu_3','sozu_3','pinzu_3',
'mauzu_4','sozu_4','pinzu_4',
'mauzu_5','sozu_5','pinzu_5',
'mauzu_6','sozu_6','pinzu_6',
'mauzu_7','sozu_7','pinzu_7',
'mauzu_8','sozu_8','pinzu_8',
'mauzu_9','sozu_9','pinzu_9',
'ton','nan','sha','pei',
'haku','hatsu','tyun',
]
shuntsu_and_kohtsu = []
# 単体の組み合わせ
for p1 in pai:
for p2 in pai:
# 1番目と図柄が違ったらパス
if p1[:-1] != p2[:-1]:
continue
for p3 in pai:
# 2番目と図柄が違ったらパス
if p2[:-1] != p3[:-1]:
continue
# 数が同じか
if p1 == p2 and p2 == p3:
shuntsu_and_kohtsu.append('{},{},{}'.format(p1,p2,p3))
# もしくは数が連番か
elif int(p1[-1]) == int(p2[-1]) -1 and int(p2[-1]) == int(p3[-1]) -1:
shuntsu_and_kohtsu.append('{},{},{}'.format(p1,p2,p3))
l = list(itertools.combinations_with_replacement(shuntsu_and_kohtsu, 4))
pop_index = []
# 同じ要素が5個以上のものは取り除く
for index,data in enumerate(l):
tmp_data = str('{},{},{},{}'.format(data[0],data[1],data[2],data[3]))
tmp_data = tmp_data.split(',')
c = collections.Counter(tmp_data)
c = list(c.values())
if len([c for i in c if i > 4]) !=0:
pop_index.append(index)
for i in pop_index[::-1]:
l.pop(i)
with open('marjang_combination.csv',mode='w') as f:
for row in l:
print(*row, sep=',', file=f)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment