Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Select the first cell in the set {A1 : I9}.
- -- Check if the cell is free.
- -- If that cell is not free, chose the next cell in the set {A1 : I9}.
- -- Repeat until you find an available cell.
- -- Set the available cell to be the active cell.
- -- Select with the lowest number if the set {1 : 9}.
- -- Check if that number is used in the current “row”, “column” or “3 x 3 cell”.
- -- If the number is used, chose the next lowest number and see if that is available.
- -- Repeat until you find an available number.
- -- Once you find an available number, check if there is more than one available number.
- -- If there is, populate the active cell with the lowest of them.
- -- If there is not, populate the active cell with the available number.
- -- 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.
- -- Repeat until there are no available cells.
- with ada.text_io, ada.integer_text_io, ada.command_line;
- use ada.text_io, ada.integer_text_io, ada.command_line;
- procedure sudoku is
- subtype row is integer range 1..9;
- subtype col is integer range 1..9;
- type board is array (row, col) of integer;
- input_file: file_type;
- placeholder: character;
- puzzle: board;
- function handle_arguments return boolean is
- begin
- if argument_count <1 then
- put("Please enter in atleast one argument into Cmd line!");
- return false;
- end if;
- if argument_count =1 then
- begin
- open(file=>input_file, name=>argument(1), mode=>in_file);
- set_input(input_file);
- exception when name_error=>
- put("File name provided will not open..");
- end;
- end if;
- return true;
- end handle_arguments;
- --Check each row
- function check_row (data: in board; target_row: in row)
- return boolean is
- seen: array (row) of boolean :=(others=> false);
- current_value: integer;
- begin
- for column in Data'range loop
- current_value := data(target_row, column);
- if current_value in row then
- if seen(current_value) then
- return false;
- end if;
- seen(current_value) := true;
- end if;
- end loop;
- return true;
- end check_row;
- --Check each col
- --function check_col (data: in board; target_col: in col);
- --Check each box
- --Check to make sure each value is valid
- --Solve
- --Ouput board
- procedure output_board (data: in board) is
- begin
- for r in data'range (1) loop
- for c in data'range (2) loop
- put(data(r,c));
- end loop;
- new_line;
- end loop;
- end output_board;
- begin
- --Handling the input arguments and opening
- if handle_arguments then
- put("Original puzzle: ");
- new_line;
- -- for r in row loop
- put("|");
- -- for c in column loop
- -- get(input_file, placeholder);
- -- if placeholder not in 1..9 then
- -- puzzle(r,c):= ' ';
- -- else
- -- puzzle(r,c) := placeholder;
- --end if;
- output_board(board);
- -- end loop;
- put("|");
- -- new_line;
- -- end loop;
- end if;
- end sudoku;
Add Comment
Please, Sign In to add comment