tasks a-s
This commit is contained in:
parent
47bf37c096
commit
b83f433714
12433 changed files with 156208 additions and 123 deletions
33
Task/Permutations/Fortran/permutations-1.f
Normal file
33
Task/Permutations/Fortran/permutations-1.f
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
program permutations
|
||||
|
||||
implicit none
|
||||
integer, parameter :: value_min = 1
|
||||
integer, parameter :: value_max = 3
|
||||
integer, parameter :: position_min = value_min
|
||||
integer, parameter :: position_max = value_max
|
||||
integer, dimension (position_min : position_max) :: permutation
|
||||
|
||||
call generate (position_min)
|
||||
|
||||
contains
|
||||
|
||||
recursive subroutine generate (position)
|
||||
|
||||
implicit none
|
||||
integer, intent (in) :: position
|
||||
integer :: value
|
||||
|
||||
if (position > position_max) then
|
||||
write (*, *) permutation
|
||||
else
|
||||
do value = value_min, value_max
|
||||
if (.not. any (permutation (: position - 1) == value)) then
|
||||
permutation (position) = value
|
||||
call generate (position + 1)
|
||||
end if
|
||||
end do
|
||||
end if
|
||||
|
||||
end subroutine generate
|
||||
|
||||
end program permutations
|
||||
41
Task/Permutations/Fortran/permutations-2.f
Normal file
41
Task/Permutations/Fortran/permutations-2.f
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
program nptest
|
||||
integer n,i,a
|
||||
logical nextp
|
||||
external nextp
|
||||
parameter(n=4)
|
||||
dimension a(n)
|
||||
do i=1,n
|
||||
a(i)=i
|
||||
enddo
|
||||
10 print *,(a(i),i=1,n)
|
||||
if(nextp(n,a)) go to 10
|
||||
end
|
||||
|
||||
function nextp(n,a)
|
||||
integer n,a,i,j,k,t
|
||||
logical nextp
|
||||
dimension a(n)
|
||||
i=n-1
|
||||
10 if(a(i).lt.a(i+1)) go to 20
|
||||
i=i-1
|
||||
if(i.eq.0) go to 20
|
||||
go to 10
|
||||
20 j=i+1
|
||||
k=n
|
||||
30 t=a(j)
|
||||
a(j)=a(k)
|
||||
a(k)=t
|
||||
j=j+1
|
||||
k=k-1
|
||||
if(j.lt.k) go to 30
|
||||
j=i
|
||||
if(j.ne.0) go to 40
|
||||
nextp=.false.
|
||||
return
|
||||
40 j=j+1
|
||||
if(a(j).lt.a(i)) go to 40
|
||||
t=a(i)
|
||||
a(i)=a(j)
|
||||
a(j)=t
|
||||
nextp=.true.
|
||||
end
|
||||
Loading…
Add table
Add a link
Reference in a new issue