Forbidden numbers: Difference between revisions

Added XPL0 example.
(Added XPL0 example.)
Line 739:
<pre>
Same as Version 1
</pre>
 
=={{header|XPL0}}==
Runtime is around 7.5 seconds on a Raspberry Pi4.
<syntaxhighlight lang "XPL0">include xpllib; \for RlOutC
 
func Forbidden(N); \Return 'true' if N is a forbidden number
int N;
[while (N&3) = 0 and N do N:= N>>2;
return (N&7) = 7;
];
 
int N, Count, Limit;
[Text(0, "The first 50 forbidden numbers are:^m^j");
Format(4, 0);
N:= 0; Count:= 0;
while Count < 50 do
[if Forbidden(N) then
[RlOut(0, (float(N)));
Count:= Count+1;
if rem(Count/10) = 0 then CrLf(0);
];
N:= N+1;
];
CrLf(0);
Format(9, 0);
N:= 1; Count:= 0; Limit:= 500;
loop [if Forbidden(N) then Count:= Count+1;
if N = Limit then
[Text(0, "Forbidden number count <= ");
RlOutC(0, float(Limit));
RlOutC(0, float(Count));
CrLf(0);
if Limit = 500_000_000 then quit;
Limit:= Limit * 10;
];
N:= N+1;
];
]</syntaxhighlight>
{{out}}
<pre>
The first 50 forbidden numbers are:
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
 
Forbidden number count <= 500 82
Forbidden number count <= 5,000 831
Forbidden number count <= 50,000 8,330
Forbidden number count <= 500,000 83,331
Forbidden number count <= 5,000,000 833,329
Forbidden number count <= 50,000,000 8,333,330
Forbidden number count <= 500,000,000 83,333,328
</pre>
291

edits