fork download
  1. def plus(arr, n):
  2.  
  3. return list(map(lambda x: x + 1, arr))
  4.  
  5. def func():
  6. # we have 7 countries to color
  7. n = 7
  8. matrix = [[0,1,1,1,0,0,1],
  9. [1,0,1,1,0,0,0],
  10. [1,1,0,1,1,0,1],
  11. [1,1,1,0,1,0,1],
  12. [0,0,1,1,0,1,1],
  13. [0,0,0,0,1,0,1],
  14. [1,0,1,1,1,1,0]]
  15.  
  16. mapColors = []
  17.  
  18. mapColors = [0] * (n)
  19.  
  20. color = -1
  21.  
  22. ok = True
  23.  
  24. mapColors[0] = 0
  25.  
  26. for i in range(1, n):
  27.  
  28. ok = False
  29.  
  30. color = -1
  31.  
  32. while ok is not True:
  33.  
  34. color += 1
  35.  
  36. ok = True
  37.  
  38. for j in range(0, i):
  39.  
  40. if 1 == matrix[j][i] and mapColors[j] == color:
  41.  
  42. ok = False
  43. mapColors[i] = color
  44.  
  45. mapColors = plus(mapColors, 1)
  46.  
  47. print(mapColors)
  48.  
  49. func()
  50.  
Success #stdin #stdout 0.03s 9588KB
stdin
Standard input is empty
stdout
[1, 2, 3, 4, 1, 2, 5]