Facebook
From Wiktor, 3 Years ago, written in Python.
Embed
Download Paste or View Raw
Hits: 89
  1. def check(nums_string):
  2.     check_dict = {'1': 1, '2': 1, '3': 1,
  3.                   '4': 1, '5': 1, '6': 1,
  4.                   '7': 1, '8': 1, '9': 1}
  5.     nums_dict = {}
  6.     for i in nums_string:
  7.         nums_dict[i] = nums_string.count(i)
  8.     if nums_dict == check_dict:
  9.         return True
  10.     else:
  11.         return False
  12.  
  13.  
  14. def get_columns(list):
  15.     columns = ['' for x in range(9)]
  16.     num = 0
  17.     for k in range(9):
  18.         for i in list:
  19.             columns[k] += i[num]
  20.         num += 1
  21.  
  22.     return columns
  23.  
  24. def get_squares(list):
  25.     squares = ['' for x in range(9)]    # TDODO: musi być lepszy sposób żeby to napisać
  26.    
  27.     num = 0
  28.     for m in range(3):    
  29.         for k in range(3):
  30.             for i in range(3):  
  31.                 squares[m] = squares[m] + list[num][i]
  32.             num+=1
  33.  
  34.     num = 0
  35.     for m in range(3,6):    
  36.         for k in range(3):
  37.             for i in range(3,6):  
  38.                 squares[m] = squares[m] + list[num][i]
  39.             num+=1
  40.  
  41.     num = 0
  42.     for m in range(6,9):
  43.         for k in range(3):
  44.             for i in range(6,9):
  45.                 squares[m] = squares[m] + list[num][i]
  46.             num+=1
  47.  
  48.  
  49.     return squares
  50.  
  51. list_of_lines = []
  52.  
  53. print("Enter each line!: ")
  54. for i in range(9):
  55.     line = input()
  56.     list_of_lines.append(line)
  57.  
  58. list_of_columns = get_columns(list_of_lines)
  59. list_of_squares = get_squares(list_of_lines)
  60.  
  61. statement = True
  62.  
  63. for i in list_of_lines:                 # pętla for x3 - zamiana na jedną
  64.     statement = statement and check(i)
  65. print(statement)
  66.  
  67. for i in list_of_columns:
  68.     statement = statement and check(i)
  69. print(statement)
  70.  
  71. for i in list_of_squares:
  72.     statement = statement and check(i)
  73. print(statement)
  74.  
  75. if statement:
  76.     print("That's sudocu!")
  77. else:
  78.     print("That's not sudocu... :(")