Skip to content

Commit

Permalink
application of fprettify ruled reformat
Browse files Browse the repository at this point in the history
This commit combines the application of the fprettify rule
based reformat with additional manual edits (truncation of
long lines, etc.) to eventually ease reading of git's reflogs
and diff views.
Reference arrays in check.f90 were protected by "fprettify
fences" to retain some visual guide which does not affect the
result of fpm test, nor the diff test launched by the Makefile.
For the present project, with editors with syntax highlighting,
I'm not sure if an horizontal alignment of variable declarations
(and not only around `::`, as discussed on fprettify[1]) is of
significant advantage here.

[1] fortran-lang/fprettify#157

Signed-off-by: Norwid Behrnd <[email protected]>
  • Loading branch information
nbehrnd committed Sep 19, 2023
1 parent f00a2fb commit 48ca57c
Show file tree
Hide file tree
Showing 3 changed files with 739 additions and 742 deletions.
244 changes: 122 additions & 122 deletions app/main.f90
Original file line number Diff line number Diff line change
Expand Up @@ -16,147 +16,147 @@
! If not, see <http://www.gnu.org/licenses/>.
!------------------------------------------------------------------------------
! Contributed by Vincent Magnin, 2006-11-27; Norwid Behrnd, 2023
! Last modifications: 2023-09-05
! Last modifications: 2023-09-12
!------------------------------------------------------------------------------

program main
use iso_fortran_env, only: dp => real64
use sudoku
use iso_fortran_env, only: dp => real64
use sudoku

implicit none
! Variables locales :
integer, dimension(9, 9) :: grid ! (line, column)
real(kind=dp) :: Start,End ! monitor the duration of computation
integer :: choice
integer :: n_empty ! number of cells to clear
character(50) :: file ! file name (including extension .txt)
implicit none
! Variables locales :
integer, dimension(9, 9) :: grid
real(kind=dp) :: Start, End ! monitor the duration of computation
integer :: choice
integer :: n_empty ! number of cells to clear
character(50) :: file ! file name (including extension .txt)

select case (command_argument_count())
case (0) ! the typical invocation with `fpm run`
select case (command_argument_count())
case (0) ! the typical invocation with `fpm run`

! initialize the pseudorandom number generator
call Initialize_Random
! initialize an explicitly empty grid
grid = 0

print *,"sudoku.f90, version 0.8.1, copyright (C) 2006 Vincent MAGNIN"
! provide a user menue
print *, "sudoku.f90, version 0.8.1, copyright (C) 2006 Vincent MAGNIN"
! provide a user menu
do
print *
print *,"*************************** MENU *****************************************"
print *,"1) Manual input (lines of comma separated 1 - 9, or 0 (empty cell).)"
print *,"2) Input from a text file. For permitted patterns, see the documentation."
print *,"3) Save the currently processed grid as a text file."
print *,"4) Check the validity of the grid currently stored in memory."
print *,"5) Display the grid currently stored in memory."
print *,"6) Create a random, already filled Sudoku grid."
print *,"7) Solve the Sudoku grid currently stored in memory."
print *,"8) Create a partially allocated grid (conjecture of a likely unique solution)."
print *,"9) Quit."
print *,"Select one of them and click `Enter`:"
READ *,choice
print *
print *, "*************************** MENU *****************************************"
print *, "1) Manual input (lines of comma separated 1 - 9, or 0 (empty cell).)"
print *, "2) Input from a text file. For permitted patterns, see the documentation."
print *, "3) Save the currently processed grid as a text file."
print *, "4) Check the validity of the grid currently stored in memory."
print *, "5) Display the grid currently stored in memory."
print *, "6) Create a random, already filled Sudoku grid."
print *, "7) Solve the Sudoku grid currently stored in memory."
print *, "8) Create a partially allocated grid (conjecture of a likely unique solution)."
print *, "9) Quit."
print *, "Select one of them and click `Enter`:"
READ *, choice

select case (choice)
case (1)
call Request_grid(grid)
print *,"You entered the following Sudoku:"
call Display_grid(grid)
if (ValidGrid(grid)) then
print *, "The Sudoku is valid."
else
print *, "The Sudoku is invalid."
end if
case(2)
print *,"Enter complete file name of the file to read (including .txt extension):"
call SYSTEM("dir *.txt")
READ *,file
call Read_grid(grid,trim(file))
call Display_grid(grid)
if (ValidGrid(grid)) then
print *, "The Sudoku is valid."
else
print *, "The Sudoku is invalid."
end if
case(3)
print *,"Enter complete file name of the file to save (incl. .txt):"
READ *,file
call Save_grid(grid,trim(file))
print *,"File saved."
case(4)
if (ValidGrid(grid)) then
print *, "The grid to process is valid."
else
print *, "The grid to process is invalid."
end if
case(5)
print *,"Below, the grid to process:"
call Display_grid(grid)
if (ValidGrid(grid)) then
print *, "The grid is valid."
else
print *, "The grid is invalid."
end if
case(6)
Start = Time()
call CreateFilledGrid(grid)
call Display_grid(grid)
! grid validation:
if (ValidGrid(grid)) then
print *, "The grid is valid."
else
print *, "Computational error: the grid is invalid!"
end if
End = Time()
write (*, "(A, F12.3, A)") " computing time: ", End - Start, " s."
case(7)
print *,"Below, the grid submitted:"
call Display_grid(grid)
Start = Time()
call Solve_grid(grid)
if (ValidGrid(grid)) then
print *, "Below, the solved grid (validity was verified):"
else
print *, "The initial grid was invalid, impossible to solve …"
end if
call Display_grid(grid)
End = Time()
write (*, "(A, F12.3, A)") " computing time: ", End - Start, " s."
case(8)
print *,"How many numbers should be assigned in advance [17,81]?"
print *,"Note: with less than 35 preallocated fields, the computation rapidly takes longer!"
READ *,n_empty
call CreateFilledGrid(grid)
print *,"Below, a filled grid:"
call Display_grid(grid)
! grid validation:
if (ValidGrid(grid)) then
print *, "The grid is valid."
else
print *, "The grid is invalid: problem to compute a solution!"
end if
select case (choice)
case (1)
call Request_grid(grid)
print *, "You entered the following Sudoku:"
call Display_grid(grid)
if (ValidGrid(grid)) then
print *, "The Sudoku is valid."
else
print *, "The Sudoku is invalid."
end if
case (2)
print *, "Enter complete file name of the file to read (including .txt extension):"
call SYSTEM("dir *.txt")
READ *, file
call Read_grid(grid, trim(file))
call Display_grid(grid)
if (ValidGrid(grid)) then
print *, "The Sudoku is valid."
else
print *, "The Sudoku is invalid."
end if
case (3)
print *, "Enter complete file name of the file to save (incl. .txt):"
READ *, file
call Save_grid(grid, trim(file))
print *, "File saved."
case (4)
if (ValidGrid(grid)) then
print *, "The grid to process is valid."
else
print *, "The grid to process is invalid."
end if
case (5)
print *, "Below, the grid to process:"
call Display_grid(grid)
if (ValidGrid(grid)) then
print *, "The grid is valid."
else
print *, "The grid is invalid."
end if
case (6)
Start = Time()
call CreateFilledGrid(grid)
call Display_grid(grid)
! grid validation:
if (ValidGrid(grid)) then
print *, "The grid is valid."
else
print *, "Computational error: the grid is invalid!"
end if
End = Time()
write (*, "(A, F12.3, A)") " computing time: ", End - Start, " s."
case (7)
print *, "Below, the grid submitted:"
call Display_grid(grid)
Start = Time()
call Solve_grid(grid)
if (ValidGrid(grid)) then
print *, "Below, the solved grid (validity was verified):"
else
print *, "The initial grid was invalid, impossible to solve …"
end if
call Display_grid(grid)
End = Time()
write (*, "(A, F12.3, A)") " computing time: ", End - Start, " s."
case (8)
print *, "How many numbers should be assigned in advance [17,81]?"
print *, "Note: with less than 35 preallocated fields, the computation rapidly takes longer!"
READ *, n_empty
call CreateFilledGrid(grid)
print *, "Below, a filled grid:"
call Display_grid(grid)
! grid validation:
if (ValidGrid(grid)) then
print *, "The grid is valid."
else
print *, "The grid is invalid: problem to compute a solution!"
end if

Start = Time()
call CreateSudokuGrid(grid,n_empty)
print *,"Below a Sudoku grid (assuming a likely unique solution):"
call Display_grid(grid)
if (ValidGrid(grid)) then
print *, "valid grid"
else
print *, "Invalid grid: problem to compute a solution!"
end if
End = Time()
write (*, "(A, F12.3, A)") " computing time: ", End - Start, " s."
case(9)
stop
end select
Start = Time()
call CreateSudokuGrid(grid, n_empty)
print *, "Below a Sudoku grid (assuming a likely unique solution):"
call Display_grid(grid)
if (ValidGrid(grid)) then
print *, "valid grid"
else
print *, "Invalid grid: problem to compute a solution!"
end if
End = Time()
write (*, "(A, F12.3, A)") " computing time: ", End - Start, " s."
case (9)
stop
end select
end do

case (1) ! accessible only by direct invocation of the executable
case (1) ! accessible only by direct invocation of the executable
call get_command_argument(1, file)
call solver(grid, file)

case default
case default
print *, "Parameters: enter either one, or none."

end select
end select
end program main
Loading

0 comments on commit 48ca57c

Please sign in to comment.