Idoneal numbers: Difference between revisions
Content added Content deleted
(→{{header|Action!}}: Slight simplification) |
(→{{header|ALGOL 68}}: Further simplification - don't need a loop to find c) |
||
Line 84: | Line 84: | ||
=={{header|ALGOL 68}}== |
=={{header|ALGOL 68}}== |
||
Note, AND does not shortcut in Algol 68. |
|||
<syntaxhighlight lang="algol68"> |
<syntaxhighlight lang="algol68"> |
||
BEGIN # find idoneal numbers - numbers that cannot be written as ab + bc + ac # |
BEGIN # find idoneal numbers - numbers that cannot be written as ab + bc + ac # |
||
Line 95: | Line 96: | ||
FOR b FROM a + 1 TO n - 1 |
FOR b FROM a + 1 TO n - 1 |
||
WHILE INT ab = a * b; |
WHILE INT ab = a * b; |
||
( ab |
INT c = ( n - ab ) OVER ( a + b ); |
||
INT sum = ab + ( c * ( b + a ) ); |
|||
sum <= n |
|||
AND ( idoneal := c <= b OR sum /= n ) |
|||
DO SKIP OD |
|||
AND ( idoneal := sum /= n ) |
|||
DO SKIP OD |
|||
OD |
|||
OD; |
OD; |
||
IF idoneal THEN |
IF idoneal THEN |