Casting out nines: Difference between revisions

Rename Perl 6 -> Raku, alphabetize, minor clean-up
(Rename Perl 6 -> Raku, alphabetize, minor clean-up)
Line 28:
* [[Kaprekar numbers]]
<br>
 
=={{header|360 Assembly}}==
{{trans|REXX}}
Line 105 ⟶ 106:
451 459 460 468 469 477 478 486 487 495 496
</pre>
 
=={{header|AWK}}==
<lang AWK>
Line 427 ⟶ 429:
Trying 223 numbers instead of 1000 saves 77.70,%.
</pre>
 
=={{header|Go}}==
<lang go>package main
Line 1,172 ⟶ 1,175:
In base 17, trying 36 numbers instead of 288 saves 87.5000%
</pre>
 
=={{header|Perl 6}}==
{{trans|Python}}
{{works with|Rakudo|2015.12}}
<lang perl6>sub cast-out(\BASE = 10, \MIN = 1, \MAX = BASE**2 - 1) {
my \B9 = BASE - 1;
my @ran = ($_ if $_ % B9 == $_**2 % B9 for ^B9);
my $x = MIN div B9;
gather loop {
for @ran -> \n {
my \k = B9 * $x + n;
take k if k >= MIN;
}
$x++;
} ...^ * > MAX;
 
say cast-out;
say cast-out 16;
say cast-out 17;</lang>
{{out}}
<pre>(1 9 10 18 19 27 28 36 37 45 46 54 55 63 64 72 73 81 82 90 91 99)
(1 6 10 15 16 21 25 30 31 36 40 45 46 51 55 60 61 66 70 75 76 81 85 90 91 96 100 105 106 111 115 120 121 126 130 135 136 141 145 150 151 156 160 165 166 171 175 180 181 186 190 195 196 201 205 210 211 216 220 225 226 231 235 240 241 246 250 255)
(1 16 17 32 33 48 49 64 65 80 81 96 97 112 113 128 129 144 145 160 161 176 177 192 193 208 209 224 225 240 241 256 257 272 273 288)</pre>
 
=={{header|Phix}}==
Line 1,340 ⟶ 1,319:
(for/fold ([sum 0]) ([d (digits n)])
(mod+ sum d))))</lang>
 
=={{header|Perl 6Raku}}==
(formerly Perl 6)
{{trans|Python}}
{{works with|Rakudo|2015.12}}
<lang perl6>sub cast-out(\BASE = 10, \MIN = 1, \MAX = BASE**2 - 1) {
my \B9 = BASE - 1;
my @ran = ($_ if $_ % B9 == $_**2 % B9 for ^B9);
my $x = MIN div B9;
gather loop {
for @ran -> \n {
my \k = B9 * $x + n;
take k if k >= MIN;
}
$x++;
} ...^ * > MAX;
 
say cast-out;
say cast-out 16;
say cast-out 17;</lang>
{{out}}
<pre>(1 9 10 18 19 27 28 36 37 45 46 54 55 63 64 72 73 81 82 90 91 99)
(1 6 10 15 16 21 25 30 31 36 40 45 46 51 55 60 61 66 70 75 76 81 85 90 91 96 100 105 106 111 115 120 121 126 130 135 136 141 145 150 151 156 160 165 166 171 175 180 181 186 190 195 196 201 205 210 211 216 220 225 226 231 235 240 241 246 250 255)
(1 16 17 32 33 48 49 64 65 80 81 96 97 112 113 128 129 144 145 160 161 176 177 192 193 208 209 224 225 240 241 256 257 272 273 288)</pre>
 
=={{header|REXX}}==
Line 1,489 ⟶ 1,493:
1 6 10 15 16 21 25 30 31 36 40 45 46 51 55 60 61 66 70 75 76 81 85 90 91 96 100 105 106 111 115 120 121 126 130 135 136 141 145 150 151 156 160 165 166 171 175 180 181 186 190 195 196 201 205 210 211 216 220 225 226 231 235 240 241 246 250 255
Trying 68 numbers instead of 255 saves 73.33%</pre>
 
 
=={{header|Scala}}==
Line 1,521 ⟶ 1,524:
List(993, 992, 977, 976, 961, 960, 945, 944, 929, 928, 913, 912, 897, 896, 881, 880, 865, 864, 849, 848, 833, 832, 817, 816, 801, 800, 785, 784, 769, 768, 753, 752, 737, 736, 721, 720, 705, 704, 689, 688, 673, 672, 657, 656, 641, 640, 625, 624, 609, 608, 593, 592, 577, 576, 561, 560, 545, 544, 529, 528, 513, 512, 497, 496, 481, 480, 465, 464, 449, 448, 433, 432, 417, 416, 401, 400, 385, 384, 369, 368, 353, 352, 337, 336, 321, 320, 305, 304, 289, 288, 273, 272, 257, 256, 241, 240, 225, 224, 209, 208, 193, 192, 177, 176, 161, 160, 145, 144, 129, 128, 113, 112, 97, 96, 81, 80, 65, 64, 49, 48, 33, 32, 17, 16)
</pre>
 
 
=={{header|Seed7}}==
10,333

edits