-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbogosort.bas
46 lines (42 loc) · 1.06 KB
/
bogosort.bas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
REM bogosort written in Decimal Basic
LET arraysize = 10
LET status$ = "false"
LET trial = 1
DIM originalarray(arraysize)
DIM shufflearray(arraysize)
FOR count = 1 TO arraysize !initialize original array
LET originalarray(count)=count
LET shufflearray(count) = originalarray(count)
PRINT count;
NEXT COUNT
PRINT
SUB shuffle
RANDOMIZE
LET msize = arraysize
FOR count = msize TO 1 STEP -1
LET randomnumber = 1+INT(count*RND)
LET preshuffle = shufflearray(count)
LET shufflearray(count) = shufflearray(randomnumber)
LET shufflearray(randomnumber) = preshuffle
NEXT count
FOR count = 1 TO arraysize
PRINT shufflearray(count);
NEXT count
PRINT
END SUB
SUB compare
LET status$ = "true"
FOR count = 1 TO arraysize
IF originalarray(count)<> shufflearray(count) THEN
LET status$ = "false"
EXIT FOR
END IF
NEXT count
END SUB
DO WHILE status$ = "false"
CALL shuffle
CALL compare
PRINT "Trial"; trial
LET trial = trial +1
LOOP
END