Je n'ai pas participé hors ligne, mais je l'ai implémenté en Python. Puis-je m'amuser plus avec numpy?
Addendum: Les données de test ajoutées sont NG, elles ont donc été corrigées.
Problème: http://mtsmfm.github.io/2017/06/03/doukaku-e14.html Liens de réponse: http://qiita.com/mtsmfm/items/89b6634f363bbf5b47f5 Événement: https://yhpg.doorkeeper.jp/events/59397
#!/usr/bin/env python
# -*- coding:utf-8 -*-
patterns = [ # dice patterns and the opposite surface pair numbers
"1000,2323,1000", "1000,2323,0100", "1000,2323,0010", "1000,2323,0001",
"0100,2323,0100", "0100,2323,0010", "1200,0313,0020", "1200,0313,0200",
"1200,0310,0023", "1200,0313,0002", "12100,00323"]
patterns = [[list(map(int, row)) for row in p.split(',')] for p in patterns]
patterns += [[row[::-1] for row in p] for p in patterns] # flip horizontal
patterns += [p[::-1] for p in patterns] # flip vertical
patterns += [list(zip(*p)) for p in patterns] # transpose
def solve(data):
dice = [list(map(int, row)) for row in data.split(',')]
for dy in range(len(dice)):
for dx in range(len(dice[dy])):
for pattern in patterns:
try:
pickup = {dice[dy + py][dx + px] : pair
for py, row in enumerate(pattern)
for px, pair in enumerate(row)
if pair != 0}
if (sorted(pickup) == [1, 2, 3, 4, 5, 6] and
sum(d * (10 ** p) for d, p in pickup.items()) == 7770):
return "true" # sum of each pair 3,2,1,0 is 7,7,7,0
except IndexError: # a index of the dice array is out of range
pass # so, the pattern didn't match
return "false"
class Result:
correct = 0
wrong = 0
def test(data, correct):
answer = solve(data)
if answer == correct:
Result.correct += 1
else:
print("%s, %s != %s" % (data, correct, answer))
Result.wrong += 1
if __name__ == '__main__':
test("44165,44516", "false");
test("26265,31436", "true");
test("46345,54215", "true");
test("62143,11152", "false");
test("4242,4314,1562", "false");
test("5612,3656,4523", "false");
test("5514,1311,5252", "false");
test("5262,4631,2644", "true");
test("6626,3324,2644", "false");
test("4645,6314,2564", "true");
test("54,65,23,21,14", "true");
test("5325,3641,1335", "true");
test("4163,2156,2553", "true");
test("3126,6543,4352", "false");
test("4464,5423,5216", "true");
test("3564,3634,5631", "false");
test("4363,3454,2126", "true");
test("25,25,33,12,52", "false");
test("1551,4542,3624", "true");
test("6623,4126,6331", "false");
test("2432,6215,1623", "true");
test("1151,6555,3616", "false");
test("2466,1242,4444", "false");
test("5646,1463,4244", "true");
test("1255,6413,4534", "true");
test("1325,2312,2425", "false");
test("2544,6413,4656", "true");
test("1656,4131,3235", "true");
test("6332,3631,4113", "false");
test("4525,2151,2336", "true");
test("1645,2356,4314", "true");
test("3334,6215,1553", "true");
test("2622,5251,5165", "false");
test("1111,5613,3451", "false");
test("6146,4512,6353", "true");
test("2455,3312,6461", "false");
test("1221,1325,1422", "false");
test("1562,2236,5212", "false");
test("6622,3324,5155", "true");
test("2352,4631,1236", "true");
test("4645,2252,6554", "false");
test("3542,6515,1231", "true");
test("12,61,56,45,23", "false");
test("4643,6522,3625", "false");
test("1151,1642,4512", "false");
test("5423,5146,2212", "false");
test("6224,3412,5653", "true");
test("3122,5423,6231", "true");
test("5421,2351,6513", "false");
test("5652,3542,3313", "true");
test("5524,3335,1146", "false");
test("5311,4126,6425", "true");
test("15,43,62,42,14", "true");
test("3631,3542,3265", "true");
test("1232,5364,6135", "true");
test("2441,4644,5433", "false");
test("2213,5621,3412", "true");
test("6644,1264,1235", "true");
test("5613,1423,6315", "true");
test("6552,1546,2141", "false");
test("5623,1461,5645", "true");
test("1442,1436,6362", "false");
test("3443,5145,4546", "false");
test("1244,1313,2316", "false");
test("2152,1463,2114", "true");
test("1211,6234,5561", "false");
test("4152,1252,3142", "false");
test("6645,1231,6122", "false");
test("353,241,121,536", "true");
test("224,444,651,234", "true");
test("643,214,244,343", "false");
test("624,542,214,333", "true");
test("441,426,536,656", "true");
test("564,642,513,364", "true");
test("422,136,414,416", "false");
test("463,356,113,662", "true");
test("464,515,435,462", "true");
test("531,145,364,525", "false");
test("623,564,153,633", "false");
test("335,462,531,424", "false");
test("131,111,535,436", "false");
test("435,414,423,365", "true");
test("144,512,332,346", "true");
test("342,246,342,634", "false");
test("246,566,431,415", "true");
test("444,554,234,621", "true");
test("313,624,165,652", "true");
test("563,262,545,315", "true");
test("213,264,154,264", "false");
test("364,434,246,113", "false");
test("411,656,325,225", "false");
test("624,234,115,443", "true");
test("252,214,635,154", "false");
test("146,213,525,164", "false");
test("456,423,112,352", "true");
test("253,156,111,355", "false");
test("252,161,562,365", "false");
test("136,553,544,524", "true");
test("414,351,161,525", "true");
test("261,442,111,531", "true");
test("323,664,454,133", "true");
test("213,415,225,165", "false");
test("363,162,165,533", "false");
test("346,441,315,241", "false");
test("121,312,155,164", "true");
test("123,311,452,365", "true");
test("361,145,212,431", "true");
test("451,264,412,513", "false");
test("311,456,263,226", "true");
test("343,442,624,635", "false");
test("534,644,234,251", "false");
test("515,346,462,435", "true");
test("445,126,165,636", "false");
test("343,355,126,353", "false");
test("623,533,256,144", "true");
test("125,341,566,416", "false");
test("354,434,621,411", "true");
test("356,435,253,114", "false");
test("141,265,533,514", "true");
test("613,426,142,535", "true");
test("366,322,413,325", "true");
test("331,542,343,545", "false");
test("261,512,563,123", "false");
test("242,132,656,164", "true");
test("133,545,441,665", "false");
test("111,151,621,545", "false");
test("132,154,234,653", "false");
test("114,455,635,511", "false");
test("14366,64254,66664,42611,41245", "false");
test("41114,53116,13122,66613,35111", "false");
test("22146,34244,16154,62531,51426", "true");
test("464316,136563,136326,535655,641161,252655", "true");
test("166255,615452,261224,533566,323335,556213", "false");
test("126665,245653,343553,254661,365415,361154", "false");
test("1512663,1525531,5456426,6336325,4324465,6512242,4112466", "true");
test("2236563,6644542,4425515,6641142,4214543,1156426,3225413", "false");
test("5545354,6566343,3525411,5356165,4625265,1535435,5522665", "false");
test("16161,61616,16161", "false");
test("2431,6354,2341", "false");
print("OK:%s, NG:%s" % (Result.correct, Result.wrong))
Résultat d'exécution
OK:139, NG:0