Numbers which are not the sum of distinct squares: Difference between revisions

m
→‎{{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].
that is guaranteed to become at least twice that length in the next step, and it will (eventually) overwrite any
subsequent holes, since it is longer than and overlaps the 2*n+1 gap between squares, at least that's my thinking...
 
Actually, a 2*n+1 (or maybe 2*n+3) block should be enough, and that works fine too.
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: #000080;font-style:italic;">-- -- (next works too, but I'm not sure that's "proof")
-- integer r = match(repeat(true,sq),summable)</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>
7,803

edits