-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathFortran Permutations
37 lines (28 loc) · 926 Bytes
/
Fortran Permutations
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
program permutations
implicit none
integer ia
integer, parameter :: value_min = 1
integer, parameter :: value_max = 5
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
ia=ia+1
if(MOD(ia,2).ne.0) write (21, *) permutation
if (permutation(1).eq.3.and.MOD(ia,2).ne.0) write(22,*) 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