Initial data commit
This commit is contained in:
parent
72d218235f
commit
f23f22d71c
199087 changed files with 3378941 additions and 0 deletions
54
Task/Knuths-algorithm-S/BBC-BASIC/knuths-algorithm-s.basic
Normal file
54
Task/Knuths-algorithm-S/BBC-BASIC/knuths-algorithm-s.basic
Normal file
|
|
@ -0,0 +1,54 @@
|
|||
HIMEM = PAGE + 20000000
|
||||
|
||||
PRINT "Single run samples for n = 3:"
|
||||
SofN% = FNs_of_n_creator(3)
|
||||
FOR I% = 0 TO 9
|
||||
!^a%() = FN(SofN%)(I%)
|
||||
PRINT " For item " ; I% " sample(s) = " FNshowarray(a%(), I%+1)
|
||||
NEXT
|
||||
|
||||
DIM cnt%(9)
|
||||
PRINT '"Digit counts after 100000 runs:"
|
||||
FOR rep% = 1 TO 100000
|
||||
IF (rep% MOD 1000) = 0 PRINT ; rep% ; CHR$(13) ;
|
||||
F% = FNs_of_n_creator(3)
|
||||
FOR I% = 0 TO 9
|
||||
!^a%() = FN(F%)(I%)
|
||||
NEXT
|
||||
cnt%(a%(1)) += 1 : cnt%(a%(2)) += 1 : cnt%(a%(3)) += 1
|
||||
NEXT
|
||||
FOR digit% = 0 TO 9
|
||||
PRINT " " ; digit% " : " ; cnt%(digit%)
|
||||
NEXT
|
||||
END
|
||||
|
||||
REM Dynamically creates this function:
|
||||
REM DEF FNfunction(item%) : PRIVATE samples%(), index%
|
||||
REM DIM samples%(n%) : = FNs_of_n(item%, samples%(), index%)
|
||||
DEF FNs_of_n_creator(n%)
|
||||
LOCAL p%, f$
|
||||
f$ = "(item%) : " + CHR$&0E + " samples%(), index% : " + \
|
||||
\ CHR$&DE + " samples%(" + STR$(n%) + ") : = " + \
|
||||
\ CHR$&A4 + "s_of_n(item%, samples%(), index%)"
|
||||
DIM p% LEN(f$) + 4 : $(p%+4) = f$ : !p% = p%+4
|
||||
= p%
|
||||
|
||||
DEF FNs_of_n(D%, s%(), RETURN I%)
|
||||
LOCAL N%
|
||||
N% = DIM(s%(),1)
|
||||
I% += 1
|
||||
IF I% <= N% THEN
|
||||
s%(I%) = D%
|
||||
ELSE
|
||||
IF RND(I%) <= N% s%(RND(N%)) = D%
|
||||
ENDIF
|
||||
= !^s%()
|
||||
|
||||
DEF FNshowarray(a%(), n%)
|
||||
LOCAL i%, a$
|
||||
a$ = "["
|
||||
IF n% > DIM(a%(),1) n% = DIM(a%(),1)
|
||||
FOR i% = 1 TO n%
|
||||
a$ += STR$(a%(i%)) + ", "
|
||||
NEXT
|
||||
= LEFT$(LEFT$(a$)) + "]"
|
||||
Loading…
Add table
Add a link
Reference in a new issue