First class environments: Difference between revisions

Added BBC BASIC
m (→‎{{header|REXX}}: changed indentation, added whitespace. -- ~~~~)
(Added BBC BASIC)
Line 17:
 
When all hailstone values dropped to 1, processing stops, and the total number of hailstone steps for each environment is printed.
=={{header|BBC BASIC}}==
{{works with|BBC BASIC for Windows}}
Here the 'environment' consists of all the dynamic variables; the static integer variables (A%-Z%) are not affected.
<lang bbcbasic> DIM @environ$(12)
@% = 4 : REM Column width
REM Initialise:
FOR E% = 1 TO 12
PROCsetenvironment(@environ$(E%))
seq% = E%
cnt% = 0
@environ$(E%) = FNgetenvironment
NEXT
REM Run hailstone sequences:
REPEAT
T% = 0
FOR E% = 1 TO 12
PROCsetenvironment(@environ$(E%))
PRINT seq% ;
IF seq% <> 1 THEN
T% += 1
cnt% += 1
IF seq% AND 1 seq% = 3 * seq% + 1 ELSE seq% DIV= 2
ENDIF
@environ$(E%) = FNgetenvironment
NEXT
PRINT
UNTIL T% = 0
REM Print counts:
PRINT "Counts:"
FOR E% = 1 TO 12
PROCsetenvironment(@environ$(E%))
PRINT cnt% ;
@environ$(E%) = FNgetenvironment
NEXT
PRINT
END
DEF FNgetenvironment
LOCAL e$ : e$ = STRING$(216, CHR$0)
SYS "RtlMoveMemory", !^e$, ^@%+108, 216
= e$
DEF PROCsetenvironment(e$)
IF LEN(e$) < 216 e$ = STRING$(216, CHR$0)
SYS "RtlMoveMemory", ^@%+108, !^e$, 216
ENDPROC</lang>
'''Output:'''
<pre>
1 2 3 4 5 6 7 8 9 10 11 12
1 1 10 2 16 3 22 4 28 5 34 6
1 1 5 1 8 10 11 2 14 16 17 3
1 1 16 1 4 5 34 1 7 8 52 10
1 1 8 1 2 16 17 1 22 4 26 5
1 1 4 1 1 8 52 1 11 2 13 16
1 1 2 1 1 4 26 1 34 1 40 8
1 1 1 1 1 2 13 1 17 1 20 4
1 1 1 1 1 1 40 1 52 1 10 2
1 1 1 1 1 1 20 1 26 1 5 1
1 1 1 1 1 1 10 1 13 1 16 1
1 1 1 1 1 1 5 1 40 1 8 1
1 1 1 1 1 1 16 1 20 1 4 1
1 1 1 1 1 1 8 1 10 1 2 1
1 1 1 1 1 1 4 1 5 1 1 1
1 1 1 1 1 1 2 1 16 1 1 1
1 1 1 1 1 1 1 1 8 1 1 1
1 1 1 1 1 1 1 1 4 1 1 1
1 1 1 1 1 1 1 1 2 1 1 1
1 1 1 1 1 1 1 1 1 1 1 1
Counts:
0 1 7 2 5 8 16 3 19 6 14 9
</pre>
 
=={{header|Bracmat}}==
<lang bracmat>( (environment=(cnt=0) (seq=))
Line 98 ⟶ 173:
(=(cnt=14) (seq=1))
(=(cnt=9) (seq=1))</pre>
 
=={{header|C}}==
Well, this fits the semantics, not sure about the spirit…