+/IBCS
git clone https://git.julia.blue/+/IBCS
4846bce
master
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 ]: 14board .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 ): 22for i in range (boardSize ): 23if stuff [g ][i ][0 ]== 1 : 24stuff [g ][i ][1 ]= boardSize 25elif stuff [g ][i ][- 1 ]== 1 : 26stuff [g ][i ][- 2 ]= boardSize 27#while -1 in board: 28for q in range (100 ): 29for g in range (2 ): 30for i in range (boardSize ): 31possible = set (range (1 ,boardSize + 1 )) 32mightWork = [] 33for j in stuff [g ][i ][1 :- 1 ]: 34if j in possible : 35possible .remove (j ) 36for j in permutations (possible ): 37temp = list (stuff [g ][i ]) 38t = 0 39for k in range (1 ,boardSize + 1 ): 40if temp [k ]== - 1 : 41temp [k ]= j [t ] 42t += 1 43if isValid (temp )and isValid (temp [::- 1 ]): 44mightWork .append (temp ) 45if len (mightWork )== 1 : 46stuff [g ][i ]= mightWork [0 ] 47 48board