Forbidden numbers: Difference between revisions

Added Algol 68
m (reference)
(Added Algol 68)
Line 32:
;* [[oeis:A004215|OEIS A004215 - Numbers that are the sum of 4 but no fewer nonzero squares]]
 
 
=={{header|ALGOL 68}}==
Uses the algorithm from the OEIS page, as used by the Wren, Python, etc. samples.
<syntaxhighlight lang="algol68">
BEGIN # find some forbidden numbers: numbers that cannot be formed by #
# fewer than four squares #
# returns TRUE if n is a Forbidden numbr, FALSE otherwise #
# based on the Wren version of the example at oeis.org/A004215 #
PROC is forbidden = ( INT n )BOOL:
BEGIN
INT m := n;
INT p4 := 1;
WHILE m > 1 AND m MOD 4 = 0 DO
m OVERAB 4;
p4 *:= 4
OD;
( n OVER p4 ) MOD 8 = 7
END # is forbidden # ;
# show the first 50 forbidden numbers and counts of Forbidden numbers #
INT f count := 0;
INT next to show := 500;
FOR i TO 50 000 000 DO
IF is forbidden( i ) THEN
f count +:= 1;
IF f count <= 50 THEN
print( ( " ", whole( i, -4 ) ) );
IF f count MOD 10 = 0 THEN print( ( newline ) ) FI
FI
FI;
IF i = next to show THEN
print( ( "There are ", whole( f count, -8 )
, " Forbidden numbers up to ", whole( i, 0 )
, newline
)
);
next to show *:= 10
FI
OD
END
</syntaxhighlight>
{{out}}
<pre>
7 15 23 28 31 39 47 55 60 63
71 79 87 92 95 103 111 112 119 124
127 135 143 151 156 159 167 175 183 188
191 199 207 215 220 223 231 239 240 247
252 255 263 271 279 284 287 295 303 311
There are 82 Forbidden numbers up to 500
There are 831 Forbidden numbers up to 5000
There are 8330 Forbidden numbers up to 50000
There are 83331 Forbidden numbers up to 500000
There are 833329 Forbidden numbers up to 5000000
There are 8333330 Forbidden numbers up to 50000000
</pre>
 
=={{header|C}}==
3,022

edits