Casting out nines: Difference between revisions

Added ABC
(Added ABC)
Line 142:
451 459 460 468 469 477 478 486 487 495 496
</pre>
=={{header|ABC}}==
<syntaxhighlight lang="abc">
\ casting out nines - based on the Action! sample
 
HOW TO ADD v TO n: PUT n + v IN n
 
PUT 10, 2, 0, 0 IN base, n, count, total
FOR i IN { 1 .. base ** n }:
ADD 1 TO total
IF i mod ( base - 1 ) = ( i * i ) mod ( base - 1 ):
ADD 1 TO count
WRITE i
WRITE // "Trying", count, "numbers instead of", total, "numbers saves"
WRITE 100 - ( ( 100 * count ) / total ), "%" /
</syntaxhighlight>
{{out}}
<pre>
1 9 10 18 19 27 28 36 37 45 46 54 55 63 64 72 73 81 82 90 91 99 100
 
Trying 23 numbers instead of 100 numbers saves 77 %
</pre>
 
=={{header|Action!}}==
<syntaxhighlight lang="action!">INT FUNC Power(INT a,b)
Line 178 ⟶ 200:
Trying 23 numbers instead of 100 numbers saves 77%
</pre>
 
=={{header|ALGOL 68}}==
{{Trans|Action!}}
3,044

edits