Guest User

Untitled

a guest
Feb 18th, 2018
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.97 KB | None | 0 0
  1. -- Select the first cell in the set {A1 : I9}.
  2. -- Check if the cell is free.
  3. -- If that cell is not free, chose the next cell in the set {A1 : I9}.
  4. -- Repeat until you find an available cell.
  5. -- Set the available cell to be the active cell.
  6. -- Select with the lowest number if the set {1 : 9}.
  7. -- Check if that number is used in the current “row”, “column” or “3 x 3 cell”.
  8. -- If the number is used, chose the next lowest number and see if that is available.
  9. -- Repeat until you find an available number.
  10. -- Once you find an available number, check if there is more than one available number.
  11. -- If there is, populate the active cell with the lowest of them.
  12. -- If there is not, populate the active cell with the available number.
  13. -- If there is no available number, backtrack to the last place where you have more than 1 available number and use the next highest number.
  14. -- Repeat until there are no available cells.
  15.  
  16.  
  17. with ada.text_io, ada.integer_text_io, ada.command_line;
  18. use ada.text_io, ada.integer_text_io, ada.command_line;
  19.  
  20.  
  21.  
  22. procedure sudoku is
  23.  
  24. subtype row is integer range 1..9;
  25. subtype col is integer range 1..9;
  26. type board is array (row, col) of integer;
  27. input_file: file_type;
  28. placeholder: character;
  29.  
  30. puzzle: board;
  31.  
  32.  
  33. function handle_arguments return boolean is
  34. begin
  35. if argument_count <1 then
  36. put("Please enter in atleast one argument into Cmd line!");
  37. return false;
  38. end if;
  39. if argument_count =1 then
  40. begin
  41. open(file=>input_file, name=>argument(1), mode=>in_file);
  42. set_input(input_file);
  43. exception when name_error=>
  44. put("File name provided will not open..");
  45. end;
  46. end if;
  47. return true;
  48. end handle_arguments;
  49.  
  50. --Check each row
  51. function check_row (data: in board; target_row: in row)
  52. return boolean is
  53. seen: array (row) of boolean :=(others=> false);
  54. current_value: integer;
  55. begin
  56. for column in Data'range loop
  57. current_value := data(target_row, column);
  58. if current_value in row then
  59. if seen(current_value) then
  60. return false;
  61. end if;
  62. seen(current_value) := true;
  63. end if;
  64. end loop;
  65. return true;
  66. end check_row;
  67.  
  68. --Check each col
  69. --function check_col (data: in board; target_col: in col);
  70.  
  71. --Check each box
  72.  
  73. --Check to make sure each value is valid
  74.  
  75. --Solve
  76.  
  77. --Ouput board
  78. procedure output_board (data: in board) is
  79. begin
  80. for r in data'range (1) loop
  81. for c in data'range (2) loop
  82. put(data(r,c));
  83. end loop;
  84. new_line;
  85. end loop;
  86. end output_board;
  87.  
  88. begin
  89. --Handling the input arguments and opening
  90. if handle_arguments then
  91. put("Original puzzle: ");
  92. new_line;
  93. -- for r in row loop
  94. put("|");
  95. -- for c in column loop
  96. -- get(input_file, placeholder);
  97. -- if placeholder not in 1..9 then
  98. -- puzzle(r,c):= ' ';
  99. -- else
  100. -- puzzle(r,c) := placeholder;
  101. --end if;
  102. output_board(board);
  103. -- end loop;
  104. put("|");
  105. -- new_line;
  106. -- end loop;
  107.  
  108. end if;
  109. end sudoku;
Add Comment
Please, Sign In to add comment