Initial data commit

This commit is contained in:
Ingy döt Net 2023-07-01 11:58:00 -04:00
parent 72d218235f
commit f23f22d71c
199087 changed files with 3378941 additions and 0 deletions

View file

@ -0,0 +1,45 @@
DIM test(9)
test() = 4, 65, 2, 31, 0, 99, 2, 83, 782, 1
perms% = 0
WHILE NOT FNsorted(test())
perms% += 1
PROCnextperm(test())
ENDWHILE
PRINT ;perms% " permutations required to sort "; DIM(test(),1)+1 " items."
END
DEF PROCnextperm(a())
LOCAL last%, maxindex%, p%
maxindex% = DIM(a(),1)
IF maxindex% < 1 THEN ENDPROC
p% = maxindex%-1
WHILE a(p%) >= a(p%+1)
p% -= 1
IF p% < 0 THEN
PROCreverse(a(), 0, maxindex%)
ENDPROC
ENDIF
ENDWHILE
last% = maxindex%
WHILE a(last%) <= a(p%)
last% -= 1
ENDWHILE
SWAP a(p%), a(last%)
PROCreverse(a(), p%+1, maxindex%)
ENDPROC
DEF PROCreverse(a(), first%, last%)
WHILE first% < last%
SWAP a(first%), a(last%)
first% += 1
last% -= 1
ENDWHILE
ENDPROC
DEF FNsorted(d())
LOCAL I%
FOR I% = 1 TO DIM(d(),1)
IF d(I%) < d(I%-1) THEN = FALSE
NEXT
= TRUE