subroutine i4_to_bvec ( i4, n, bvec ) c*********************************************************************72 c cc i4_to_bvec() converts an integer into a binary vector. c c Licensing: c c This code is distributed under the MIT license. c c Modified: c c 20 March 2009 c c Author: c c John Burkardt c c Input: c c integer I4, the integer. c c integer N, the dimension of the vector. c c Output: c c integer BVEC(N), the vector of binary remainders. c implicit none integer n integer bvec(n) integer i integer i4 integer i4_copy i4_copy = i4 do i = n, 1, -1 bvec(i) = mod ( i4_copy, 2 ) i4_copy = i4_copy / 2 end do return end subroutine satisfy_brute ( n, formula ) c*********************************************************************72 c cc satisfy_brute() solves the satisfy problem using brute force. c c Licensing: c c This code is distributed under the MIT license. c c Modified: c c 27 October 2022 c c Author: c c John Burkardt c c Reference: c c Michael Quinn, c Parallel Programming in C with MPI and OpenMP, c McGraw-Hill, 2004, c ISBN13: 978-0071232654, c LC: QA76.73.C15.Q55. c c Input: c c integer n: the number of variables in the formula. c c integer formula ( integer bvec[] ): a function which evaluates the formula. c implicit none integer n integer bvec(n) external formula integer formula integer i integer ihi integer j integer solution_num integer value write ( *, '(a)' ) ' ' write ( *, '(a)' ) 'satisfy_brute()' write ( *, '(a)' ) & ' We have a logical function of N logical arguments.' write ( *, '(a)' ) & ' We do an exhaustive search of all 2^N possibilities,' write ( *, '(a)' ) & ' seeking those inputs that make the function TRUE.' c c Compute the number of binary vectors to check. c ihi = 2**n write ( *, '(a)' ) ' ' write ( *, '(a,i8)' ) & ' The number of logical variables is N = ', n write ( *, '(a,i8)' ) & ' The number of input vectors to check is ', ihi write ( *, '(a)' ) ' ' write ( *, '(a)' ) & ' # Index ' // & '---------Input Values------------------------' write ( *, '(a)' ) ' ' c c Check every possible input vector. c solution_num = 0 do i = 0, ihi - 1 call i4_to_bvec ( i, n, bvec ) value = formula ( bvec ) if ( value == 1 ) then solution_num = solution_num + 1 write ( *, '(2x,i2,2x,i10,3x,23i2)' ) & solution_num, i, ( bvec(j), j = 1, n ) end if end do c c Report. c write ( *, '(a)' ) ' ' write ( *, '(a,i8)' ) & ' Number of solutions found was ', solution_num return end