Jump to content

User:StuRat/perm

From Wikipedia, the free encyclopedia
     program perm
     implicit      none
     integer*2     A,B,C,D,E,F,G,H,I,N
     integer       ARRAY(400000),NB_FOUND
     
  • integer*2 bench ! For benchmarking only.
     call system('ECHO. | time | find "urrent time is"')

  • DO bench = 1,100 ! For benchmarking only.
     NB_FOUND = 0
     DO A = 1,9
      DO B = 1,9
       IF (A.ne.B) THEN
        DO C = 1,9
         IF ((A.ne.C) .and.
    +        (B.ne.C)) THEN
          DO D = 1,9
           IF ((A.ne.D) .and.
    +          (B.ne.D) .and.
    +          (C.ne.D)) THEN
            DO E = 1,9
             IF ((A.ne.E) .and.
    +            (B.ne.E) .and.
    +            (C.ne.E) .and.
    +            (D.ne.E)) THEN
              DO F = 1,9
               IF ((A.ne.F) .and.
    +              (B.ne.F) .and.
    +              (C.ne.F) .and.
    +              (D.ne.F) .and.
    +              (E.ne.F)) THEN
                DO G = 1,9
                 IF ((A.ne.G) .and.
    +                (B.ne.G) .and.
    +                (C.ne.G) .and.
    +                (D.ne.G) .and.
    +                (E.ne.G) .and.
    +                (F.ne.G)) THEN
                  DO H = 1,9
                   IF ((A.ne.H) .and.
    +                  (B.ne.H) .and.
    +                  (C.ne.H) .and.
    +                  (D.ne.H) .and.
    +                  (E.ne.H) .and.
    +                  (F.ne.H) .and.
    +                  (G.ne.H)) THEN
                    DO I = 1,9
                     IF ((A.ne.I) .and.
    +                    (B.ne.I) .and.
    +                    (C.ne.I) .and.
    +                    (D.ne.I) .and.
    +                    (E.ne.I) .and.
    +                    (F.ne.I) .and.
    +                    (G.ne.I) .and.
    +                    (H.ne.I)) THEN
                      NB_FOUND = NB_FOUND + 1
                      ARRAY(NB_FOUND) = 100000000*A 
    +                                 + 10000000*B
    +                                 + 1000000*C 
    +                                 + 100000*D 
    +                                 + 10000*E 
    +                                 + 1000*F 
    +                                 + 100*G 
    +                                 + 10*H 
    +                                 +   I
                       goto 100 ! Bypass all prints.
  • if (NB_FOUND .gt. 24) goto 100 ! Bypass all but first 24 prints.
                        print * , 'ARRAY(',NB_FOUND,') =',
    +                              ARRAY(  NB_FOUND  )
 100                   continue
                     ENDIF
                    ENDDO
                   ENDIF
                  ENDDO
                 ENDIF
                ENDDO
               ENDIF
              ENDDO
             ENDIF
            ENDDO
           ENDIF
          ENDDO
         ENDIF
        ENDDO
       ENDIF
      ENDDO
     ENDDO
  • ENDDO ! For benchmarking only.
     print *,'Last item found: ARRAY(',NB_FOUND,') =',
    +                          ARRAY(  NB_FOUND  )
     call system('ECHO. | time | find "urrent time is"')
     end