Frobenius numbers: Difference between revisions
Content added Content deleted
Not a robot (talk | contribs) (Add J) |
m (→{{header|REXX}}: changed some comments, simplified some code.) |
||
Line 234: | Line 234: | ||
if cols>0 then say ' index │'center(@Frob, 1 + cols*(w+1) ) |
if cols>0 then say ' index │'center(@Frob, 1 + cols*(w+1) ) |
||
if cols>0 then say '───────┼'center("" , 1 + cols*(w+1), '─') |
if cols>0 then say '───────┼'center("" , 1 + cols*(w+1), '─') |
||
$=; idx= 1 /*list of Frobenius #s (so far); index.*/ |
|||
do j=1; jp= j+1; y= @.j*@.jp - @.j - @.jp /*calculate a Frobenius number. */ |
|||
$= /*a list of Frobenius numbers (so far)*/ |
|||
if y>= hi then leave /*Is Y too high? Yes, then leave. */ |
|||
⚫ | |||
y= @.j * @.jp - @.j - @.jp |
|||
if y>= hi then leave |
|||
⚫ | |||
c= commas(y) /*maybe add commas to the number. */ |
c= commas(y) /*maybe add commas to the number. */ |
||
$= $ right(c, max(w, length(c) ) ) /*add a Frobenius #──►list, allow big #*/ |
$= $ right(c, max(w, length(c) ) ) /*add a Frobenius #──►list, allow big #*/ |
||
if j//cols\==0 |
if j//cols\==0 then iterate /*have we populated a line of output? */ |
||
say center(idx, 7)'│' substr($, 2); $= /*display what we have so far (cols). */ |
say center(idx, 7)'│' substr($, 2); $= /*display what we have so far (cols). */ |
||
idx= idx + cols /*bump the index count for the output*/ |
idx= idx + cols /*bump the index count for the output*/ |
||
Line 248: | Line 246: | ||
if $\=='' then say center(idx, 7)"│" substr($, 2) /*possible display residual output.*/ |
if $\=='' then say center(idx, 7)"│" substr($, 2) /*possible display residual output.*/ |
||
if cols>0 then say '───────┴'center("" , 1 + cols*(w+1), '─') |
|||
say |
say |
||
say 'Found ' commas(j-1) @FROB |
say 'Found ' commas(j-1) @FROB |
||
Line 254: | Line 253: | ||
commas: parse arg ?; do jc=length(?)-3 to 1 by -3; ?=insert(',', ?, jc); end; return ? |
commas: parse arg ?; do jc=length(?)-3 to 1 by -3; ?=insert(',', ?, jc); end; return ? |
||
/*──────────────────────────────────────────────────────────────────────────────────────*/ |
/*──────────────────────────────────────────────────────────────────────────────────────*/ |
||
genP: @.1=2; @.2=3; @.3=5; @.4=7; @.5=11 |
genP: @.1=2; @.2=3; @.3=5; @.4=7; @.5=11; @.6= 13 /*define some low primes. */ |
||
#= |
#=6; s.#= @.# **2 /*number of primes so far; prime²*/ |
||
/* [↓] generate more primes ≤ high.*/ |
/* [↓] generate more primes ≤ high.*/ |
||
do j=@.#+ |
do j=@.#+4 by 2 to hi+1 /*find odd primes from here on. */ |
||
parse var j '' -1 _; if _==5 then iterate /*J divisible by 5? |
parse var j '' -1 _; if _==5 then iterate /*J divisible by 5? (right dig)*/ |
||
if j// 3==0 then iterate /*" " " 3? |
if j// 3==0 then iterate /*" " " 3? */ |
||
if j// 7==0 then iterate /*" " " 7? |
if j// 7==0 then iterate /*" " " 7? */ |
||
if j//11==0 then iterate /*" " " 11? */ |
|||
/* [↑] the above four lines saves time*/ |
|||
do k=6 while s.k<=j /* [↓] divide by the known odd primes.*/ |
|||
if j // @.k == 0 then iterate j /*Is J ÷ X? Then not prime. ___ */ |
if j // @.k == 0 then iterate j /*Is J ÷ X? Then not prime. ___ */ |
||
end /*k*/ /* [↑] only process numbers ≤ √ J */ |
end /*k*/ /* [↑] only process numbers ≤ √ J */ |
||
Line 274: | Line 274: | ||
11 │ 1,079 1,439 1,679 1,931 2,391 3,015 3,479 3,959 4,619 5,039 |
11 │ 1,079 1,439 1,679 1,931 2,391 3,015 3,479 3,959 4,619 5,039 |
||
21 │ 5,615 6,395 7,215 8,447 9,599 |
21 │ 5,615 6,395 7,215 8,447 9,599 |
||
───────┴─────────────────────────────────────────────────────────────────────────────────────────────────────────────── |
|||
Found 25 Frobenius numbers that are < 10,000 |
Found 25 Frobenius numbers that are < 10,000 |