Numbers which are not the sum of distinct squares: Difference between revisions
Numbers which are not the sum of distinct squares (view source)
Revision as of 20:04, 26 November 2021
, 2 years ago→{{header|Phix}}: clarified my thinking
(Added C# version, re-purposed C# code from practical numbers) |
m (→{{header|Phix}}: clarified my thinking) |
||
Line 220:
=={{header|Phix}}==
As per Raku (but possibly using slightly different logic, and this is using a simple flag array), if we find there will be a block of n<sup><small>2</small></sup> summables,
and we are going to mark every one of those entries plus n<sup><small>2</small></sup> as summable, those regions will marry up or overlap and it is guaranteed to become at least twice that length in the next step, and all subsequent steps since 2*n<sup><small>2</small></sup> is also going to be longer than (n+1)<sup><small>2</small></sup> for all n>1, hence it will (eventually) mark everything beyond that point as summable. You can run this online [http://phix.x10.mx/p2js/nsods.htm here].
<!--<lang Phix>(phixonline)-->
<span style="color: #008080;">with</span> <span style="color: #008080;">javascript_semantics</span>
Line 241 ⟶ 237:
<span style="color: #000000;">summable</span><span style="color: #0000FF;">[</span><span style="color: #000000;">sq</span><span style="color: #0000FF;">]</span> <span style="color: #0000FF;">=</span> <span style="color: #004600;">true</span>
<span style="color: #004080;">integer</span> <span style="color: #000000;">r</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">match</span><span style="color: #0000FF;">(</span><span style="color: #7060A8;">repeat</span><span style="color: #0000FF;">(</span><span style="color: #004600;">true</span><span style="color: #0000FF;">,(</span><span style="color: #000000;">n</span><span style="color: #0000FF;">+</span><span style="color: #000000;">1</span><span style="color: #0000FF;">)*(</span><span style="color: #000000;">n</span><span style="color: #0000FF;">+</span><span style="color: #000000;">1</span><span style="color: #0000FF;">)),</span><span style="color: #000000;">summable</span><span style="color: #0000FF;">)</span>
<span style="color: #008080;">if</span> <span style="color: #000000;">r</span> <span style="color: #008080;">then</span>
<span style="color: #000000;">summable</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">summable</span><span style="color: #0000FF;">[</span><span style="color: #000000;">1</span><span style="color: #0000FF;">..</span><span style="color: #000000;">r</span><span style="color: #0000FF;">-</span><span style="color: #000000;">1</span><span style="color: #0000FF;">]</span>
|