Есть числа от 1 до 18 и три игральные кости. Обычные кубики с 6 гранями. Эти числа игрок А должен нанести на грани кубиков, причём так, что числа не будут дублироваться. Грубо говоря сочетания или перестановки. Потом игрок Б берёт один из этих кубиков и кидает его. Игрок А знает, какой кубик кинул Б, берёт любой кубик из двух оставшихся и тоже кидает его. Выигрывает тот, у кого больше очков выпало. победу отмечают. И нужно игроку А, который наносит числа на кубики нанести их таким образом, чтобы он при достаточно большом числе бросков кубиков всегда выигрывал. Как раз прога и должна вернуть все такие беспроигрышные расстановки чисел на трёх кубиках.
Last active
September 13, 2015 09:10
-
-
Save morontt/465caf3d67850885a34a to your computer and use it in GitHub Desktop.
Битва прог, часть вторая
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# author: Dmitriy Belyaev | |
# https://github.com/dimka2014 | |
import itertools | |
numbers = set([x for x in range(1, 19)]) | |
sequences = [x for x in itertools.combinations(numbers, 6)] | |
def first_win_numbers(first, second): | |
result = 0 | |
for x in first: | |
for y in second: | |
if x > y: | |
result += 1 | |
return result | |
def is_wins(cubes): | |
if first_win_numbers(cubes[0], cubes[1]) == 21 and first_win_numbers(cubes[1], cubes[2]) == 21 and first_win_numbers(cubes[2], cubes[0]) == 21: | |
return True | |
if first_win_numbers(cubes[2], cubes[0]) == 21 and first_win_numbers(cubes[0], cubes[2]) == 21 and first_win_numbers(cubes[2], cubes[1]) == 21: | |
return True | |
if first_win_numbers(cubes[2], cubes[1]) == 21 and first_win_numbers(cubes[1], cubes[0]) == 21 and first_win_numbers(cubes[0], cubes[2]) == 21: | |
return True | |
return False | |
combinations = set([]) | |
for sequence in sequences: | |
for x in itertools.combinations(numbers - set(sequence), 6): | |
cubes = [set(sequence), set(x), numbers - set(sequence) - set(x)] | |
if is_wins(cubes): | |
combinations.add(frozenset([frozenset(x) for x in cubes])) | |
for x in combinations: | |
print x |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# author: Dmitriy Belyaev | |
# https://github.com/dimka2014 | |
# | |
# optimization: Alexander Harchenko | |
# https://github.com/morontt | |
import itertools | |
numbers = set([x for x in range(1, 19)]) | |
subnumbers = set([x for x in range(2, 19)]) | |
sequences = [set([1]) | set(x) for x in itertools.combinations(subnumbers, 5)] | |
def first_win_numbers(first, second): | |
result = 0 | |
for x in first: | |
for y in second: | |
if x > y: | |
result += 1 | |
return result | |
def is_wins(cubes): | |
ab = first_win_numbers(cubes[0], cubes[1]) | |
if ab == 21 or ab == 15: | |
bc = first_win_numbers(cubes[1], cubes[2]) | |
if bc == ab: | |
ca = first_win_numbers(cubes[2], cubes[0]) | |
if ca == ab: | |
return True | |
return False | |
combinations = set([]) | |
for sequence in sequences: | |
if sum(sequence) == 57: | |
for x in itertools.combinations(numbers - sequence, 6): | |
z = set(x) | |
if sum(z) == 57: | |
w = numbers - sequence - z | |
if max(z) > max(w): | |
cubes = [sequence, z, w] | |
if is_wins(cubes): | |
combinations.add(frozenset([frozenset(x) for x in cubes])) | |
for x in combinations: | |
print x |
Игроки то пусть бухают или кидают кубики. Дело за прогой, которая числа на кубики расставит максимально быстро.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Я думаю, нет я почти уверен 🎯 если они каждую победу будут отмечать, то игроки бросят это гиблое дело кидаться кубиками и начнуть просто отмечать 🍻