Inventory sequence: Difference between revisions
Content added Content deleted
(→{{header|Ruby}}: Add Ruby) |
(Added Algol 68) |
||
Line 27: | Line 27: | ||
=={{header|ALGOL 68}}== |
|||
Calculates the sequenceelements without storing them. |
|||
<syntaxhighlight lang="algol68"> |
|||
BEGIN # find elements of the inventory sequence # |
|||
INT next to show := 1 000; # next value to show first element > # |
|||
INT max to show = 10 000; # last value to show first element > # |
|||
INT max number = max to show + 1 000; # max. element value to consider # |
|||
[ 0 : max number ]INT occurs; # number of times each number occurs # |
|||
FOR i FROM LWB occurs TO UPB occurs DO occurs[ i ] := 0 OD; |
|||
INT seq pos := 0; # current end of the sequence # |
|||
WHILE next to show <= max to show DO |
|||
FOR n FROM 0 WHILE next to show <= max to show |
|||
AND BEGIN |
|||
INT element := occurs[ n ]; |
|||
seq pos +:= 1; |
|||
IF seq pos <= 100 THEN |
|||
print( ( " ", whole( element, -4 ) ) ); |
|||
IF seq pos MOD 10 = 0 THEN print( ( newline ) ) FI |
|||
ELIF element > next to show THEN |
|||
print( ( "Element ", whole( seq pos, -8 ) |
|||
, " (", whole( element, -8 ) |
|||
, ") is first > ", whole( next to show, -6 ) |
|||
, newline |
|||
) |
|||
); |
|||
next to show +:= 1 000 |
|||
FI; |
|||
IF element < max number THEN |
|||
occurs[ element ] +:= 1 |
|||
FI; |
|||
element /= 0 |
|||
END |
|||
DO SKIP OD |
|||
OD |
|||
END |
|||
</syntaxhighlight> |
|||
{{out}} |
|||
<pre> |
|||
0 1 1 0 2 2 2 0 3 2 |
|||
4 1 1 0 4 4 4 1 4 0 |
|||
5 5 4 1 6 2 1 0 6 7 |
|||
5 1 6 3 3 1 0 7 9 5 |
|||
3 6 4 4 2 0 8 9 6 4 |
|||
9 4 5 2 1 3 0 9 10 7 |
|||
5 10 6 6 3 1 4 2 0 10 |
|||
11 8 6 11 6 9 3 2 5 3 |
|||
2 0 11 11 10 8 11 7 9 4 |
|||
3 6 4 5 0 12 11 10 9 13 |
|||
Element 24256 ( 1001) is first > 1000 |
|||
Element 43302 ( 2009) is first > 2000 |
|||
Element 61709 ( 3001) is first > 3000 |
|||
Element 81457 ( 4003) is first > 4000 |
|||
Element 98705 ( 5021) is first > 5000 |
|||
Element 121343 ( 6009) is first > 6000 |
|||
Element 151757 ( 7035) is first > 7000 |
|||
Element 168805 ( 8036) is first > 8000 |
|||
Element 184429 ( 9014) is first > 9000 |
|||
Element 201789 ( 10007) is first > 10000 |
|||
</pre> |
|||
=={{header|FreeBASIC}}== |
=={{header|FreeBASIC}}== |