Jump to content

User:StuRat/perm4

From Wikipedia, the free encyclopedia
     program perm4
  10 INTEGER*2 x,p,z
  12 INTEGER*4 t
  20 INTEGER*2 a(9),c(9)
  22 INTEGER*4 n(362880)
  • integer*2 bench ! For benchmarking only.
     call system('ECHO. | time | find "urrent time is"')
  • DO bench = 1,100 ! For benchmarking only.
  25 t=1
  30 do x=1,9
  40   a(x)=x
  50   c(x)=x
  60 enddo
  70 p=1
 100 z=a(c(p))
 102 a(c(p))=a(p)
 104 a(p)=z
 110 p=p+1
 120 if (p.le.9) goto 100
 150 n(t)=100000000*a(1) + 
    +      10000000*a(2) + 
    +       1000000*a(3) + 
    +        100000*a(4) + 
    +         10000*a(5) + 
    +          1000*a(6) + 
    +           100*a(7) + 
    +            10*a(8) + 
    +               a(9)
 160 t=t+1
 170 goto 200 ! Bypass all prints.
  • if (t-1 .gt. 24) goto 200 ! Bypass all but first 24 prints.
 180   print *,'n(',t-1,') = ',n(t-1)
 200 p=p-1
 210 if (p.eq.0) goto 270
 220 z=a(c(p))
 222 a(c(p))=a(p)
 224 a(p)=z
 230 c(p)=c(p)+1
 240 if (c(p).le.9) goto 100
 250 c(p)=p
 260 goto 200
 270 continue
  
  • enddo ! For benchmarking only.
     print *,'Last item found: n(',t-1,') = ',
    +                          n(  t-1  )
     call system('ECHO. | time | find "urrent time is"')
     end