+/IBCS

git clone https://git.julia.blue/+/IBCS

Joseph Ryanfinish last acsl4846bce

master
1.6 KiB48 linesraw
1import numpy as np
2from itertools import permutations
3
4#a = raw_input()
5a = "3221, 41, 22, 14, 22, 2313"
6a = "2124, 23, 13, 22, 41, 3321"
7a = "1233, 14, 22, 41, 22, 2312"
8a = "33213, 42, 23 ,15, 22, 21, 22341"
9a = "23312, 22, 15, 33, 41, 23, 21332"
10a = [i.strip() for i in a.split(',')]
11boardSize = len(a[0])
12board = [[0] + [int(i) for i in a[0]] + [0]]
13for i in a[1:-1]:
14    board.append([int(i[0])] + [-1] * boardSize + [int(i[1])])
15board.append([0] + [int(i) for i in a[-1]] + [0])
16board = np.array(board)
17stuff = [board[1:-1], board.T[1:-1]]
18
19isValid = lambda n: [n[i] > max(n[1:i]) if i > 1 else True for i in range(1, boardSize + 1)].count(True) == n[0]
20
21for g in range(2):
22    for i in range(boardSize):
23        if stuff[g][i][0] == 1:
24            stuff[g][i][1] = boardSize
25        elif stuff[g][i][-1] == 1:
26            stuff[g][i][-2] = boardSize
27#while -1 in board:
28for q in range(100):
29    for g in range(2):
30        for i in range(boardSize):
31            possible = set(range(1, boardSize + 1))
32            mightWork = []
33            for j in stuff[g][i][1:-1]:
34                if j in possible:
35                    possible.remove(j)
36            for j in permutations(possible):
37                temp = list(stuff[g][i])
38                t = 0
39                for k in range(1, boardSize + 1):
40                    if temp[k] == -1:
41                        temp[k] = j[t]
42                        t += 1
43                if isValid(temp) and isValid(temp[::-1]):
44                    mightWork.append(temp)
45            if len(mightWork) == 1:
46                stuff[g][i] = mightWork[0]
47
48print board