First class environments: Difference between revisions

no edit summary
(Added Perl Implementation)
No edit summary
Line 616:
<lang>(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) Counts:(0,1,7,2,5,8,16,3,19,6,14,9)</lang>
The C preprocessor cannot output newlines, so the output is all on one line, but easily parsable.
 
=={{header|PicoLisp}}==
Runtime environments can be controlled with the '[http://software-lab.de/doc/refJ.html#job job]' function:
<lang PicoLisp>(let Envs
(mapcar
'((N) (list (cons 'N N) (cons 'Cnt 0))) # Build environments
(range 1 12) )
(while (find '((E) (job E (> N 1))) Envs) # Until all values are 1:
(for E Envs
(job E # Use environment 'E'
(prin (align 4 N))
(unless (= 1 N)
(inc 'Cnt) # Increment step count
(setq N
(if (bit? 1 N) # Calculate next hailstone value
(inc (* N 3))
(/ N 2) ) ) ) ) )
(prinl) )
(prinl (need 48 '=))
(for E Envs # For each environment 'E'
(job E
(prin (align 4 Cnt)) ) ) # print the step count
(prinl) )</lang>
{{out}}
<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
================================================
0 1 7 2 5 8 16 3 19 6 14 9</pre>
 
=={{header|Perl}}==
Line 789 ⟶ 744:
</pre>
 
=={{header|PicoLisp}}==
 
Runtime environments can be controlled with the '[http://software-lab.de/doc/refJ.html#job job]' function:
<lang PicoLisp>(let Envs
(mapcar
'((N) (list (cons 'N N) (cons 'Cnt 0))) # Build environments
(range 1 12) )
(while (find '((E) (job E (> N 1))) Envs) # Until all values are 1:
(for E Envs
(job E # Use environment 'E'
(prin (align 4 N))
(unless (= 1 N)
(inc 'Cnt) # Increment step count
(setq N
(if (bit? 1 N) # Calculate next hailstone value
(inc (* N 3))
(/ N 2) ) ) ) ) )
(prinl) )
(prinl (need 48 '=))
(for E Envs # For each environment 'E'
(job E
(prin (align 4 Cnt)) ) ) # print the step count
(prinl) )</lang>
{{out}}
<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
================================================
0 1 7 2 5 8 16 3 19 6 14 9</pre>
 
=={{header|Python}}==
Anonymous user