Code Comments
Programming Forum and web based access to our favorite programming groups.Hello!
I'm trying to write a program that outputs the possible combinations of a se
t of numbers, but I can't seem to get it right..
In a list of 1-2-3, the program only outputs 1-2-3.
It should be
1-2-3
1-3-2
2-1-3
2-3-1 etc...
Any suggestions? The code:
MODULE div
INTEGER, PARAMETER :: usedmax = 3
LOGICAL, DIMENSION(usedmax) :: used
INTEGER, DIMENSION(usedmax) :: choice
CONTAINS
RECURSIVE SUBROUTINE Useit()
INTEGER :: i, j
DO i = 1, usedmax, 1
IF (.NOT. used(i)) then
used(i) = .TRUE.
WRITE (*,*) 'made choice', choice(i)
CALL UseIt()
RETURN
ENDIF
ENDDO
RETURN
END SUBROUTINE UseIt
SUBROUTINE Init
IMPLICIT NONE
INTEGER :: i
DO i = 1, usedmax, 1
used(i) = .false.
choice(i) = i
ENDDO
RETURN
END SUBROUTINE init
END MODULE
PROGRAM main
USE div
IMPLICIT NONE
CALL Init
CALL UseIt()
STOP
END PROGRAM main
Post Follow-up to this messagePowered by vBulletin
Copyright 2000-2006 Jelsoft Enterprises Limited.