Magnanimous numbers: Difference between revisions

Content added Content deleted
No edit summary
m (syntax highlighting fixup automation)
Line 33: Line 33:


=={{header|ALGOL 68}}==
=={{header|ALGOL 68}}==
<lang algol68>BEGIN # find some magnanimous numbers - numbers where inserting a + between any #
<syntaxhighlight lang="algol68">BEGIN # find some magnanimous numbers - numbers where inserting a + between any #
# digits ab=nd evaluatinf the sum results in a prime in all cases #
# digits ab=nd evaluatinf the sum results in a prime in all cases #
# returns the first n magnanimous numbers #
# returns the first n magnanimous numbers #
Line 78: Line 78:
print magnanimous( m, 241, 250, "Magnanimous numbers 241-250" );
print magnanimous( m, 241, 250, "Magnanimous numbers 241-250" );
print magnanimous( m, 391, 400, "Magnanimous numbers 391-400" )
print magnanimous( m, 391, 400, "Magnanimous numbers 391-400" )
END</lang>
END</syntaxhighlight>
{{out}}
{{out}}
<pre>
<pre>
Line 90: Line 90:


=={{header|ALGOL W}}==
=={{header|ALGOL W}}==
<lang algolw>begin
<syntaxhighlight lang="algolw">begin
% find some Magnanimous numbers - numbers where inserting a "+" between %
% find some Magnanimous numbers - numbers where inserting a "+" between %
% any two of the digits and evaluating the sum results in a prime number %
% any two of the digits and evaluating the sum results in a prime number %
Line 228: Line 228:
write( "Last magnanimous number found: ", mPos, " = ", lastM )
write( "Last magnanimous number found: ", mPos, " = ", lastM )
end
end
end.</lang>
end.</syntaxhighlight>
{{out}}
{{out}}
<pre>
<pre>
Line 243: Line 243:


=={{header|AWK}}==
=={{header|AWK}}==
<syntaxhighlight lang="awk">
<lang AWK>
# syntax: GAWK -f MAGNANIMOUS_NUMBERS.AWK
# syntax: GAWK -f MAGNANIMOUS_NUMBERS.AWK
# converted from C
# converted from C
Line 286: Line 286:
printf("\n")
printf("\n")
}
}
</syntaxhighlight>
</lang>
{{out}}
{{out}}
<pre>
<pre>
Line 296: Line 296:
=={{header|C}}==
=={{header|C}}==
{{trans|Go}}
{{trans|Go}}
<lang c>#include <stdio.h>
<syntaxhighlight lang="c">#include <stdio.h>
#include <string.h>
#include <string.h>


Line 383: Line 383:
list_mags(391, 400, 1, 10);
list_mags(391, 400, 1, 10);
return 0;
return 0;
}</lang>
}</syntaxhighlight>


{{out}}
{{out}}
Line 400: Line 400:


=={{header|C#|CSharp}}==
=={{header|C#|CSharp}}==
<lang csharp>using System; using static System.Console;
<syntaxhighlight lang="csharp">using System; using static System.Console;


class Program {
class Program {
Line 424: Line 424:
if (c == 240) WriteLine ("\n\n241st through 250th{0}", mn);
if (c == 240) WriteLine ("\n\n241st through 250th{0}", mn);
if (c == 390) WriteLine ("\n\n391st through 400th{0}", mn); } }
if (c == 390) WriteLine ("\n\n391st through 400th{0}", mn); } }
}</lang>
}</syntaxhighlight>


{{out}}
{{out}}
Line 439: Line 439:


=={{header|C++}}==
=={{header|C++}}==
<lang cpp>#include <iomanip>
<syntaxhighlight lang="cpp">#include <iomanip>
#include <iostream>
#include <iostream>


Line 500: Line 500:
std::cout << '\n';
std::cout << '\n';
return 0;
return 0;
}</lang>
}</syntaxhighlight>


{{out}}
{{out}}
Line 519: Line 519:
===The function===
===The function===
This task uses [http://www.rosettacode.org/wiki/Extensible_prime_generator#The_function Extensible Prime Generator (F#)]
This task uses [http://www.rosettacode.org/wiki/Extensible_prime_generator#The_function Extensible Prime Generator (F#)]
<lang fsharp>
<syntaxhighlight lang="fsharp">
// Generate Magnanimous numbers. Nigel Galloway: March 20th., 2020
// Generate Magnanimous numbers. Nigel Galloway: March 20th., 2020
let rec fN n g = match (g/n,g%n) with
let rec fN n g = match (g/n,g%n) with
Line 526: Line 526:
|_ -> false
|_ -> false
let Magnanimous = let Magnanimous = fN 10 in seq{yield! {0..9}; yield! Seq.initInfinite id |> Seq.skip 10 |> Seq.filter Magnanimous}
let Magnanimous = let Magnanimous = fN 10 in seq{yield! {0..9}; yield! Seq.initInfinite id |> Seq.skip 10 |> Seq.filter Magnanimous}
</syntaxhighlight>
</lang>
===The Tasks===
===The Tasks===
;First 45
;First 45


<lang fsharp>
<syntaxhighlight lang="fsharp">
Magnanimous |> Seq.take 45 |> Seq.iter (printf "%d "); printfn ""
Magnanimous |> Seq.take 45 |> Seq.iter (printf "%d "); printfn ""
</syntaxhighlight>
</lang>
{{out}}
{{out}}
<pre>
<pre>
Line 539: Line 539:
;Magnanimous[241] to Magnanimous[250]
;Magnanimous[241] to Magnanimous[250]


<lang fsharp>
<syntaxhighlight lang="fsharp">
Magnanimous |> Seq.skip 240 |> Seq.take 10 |> Seq.iter (printf "%d "); printfn "";;
Magnanimous |> Seq.skip 240 |> Seq.take 10 |> Seq.iter (printf "%d "); printfn "";;
</syntaxhighlight>
</lang>
{{out}}
{{out}}
<pre>
<pre>
Line 548: Line 548:
;Magnanimous[391] to Magnanimous[400]
;Magnanimous[391] to Magnanimous[400]


<lang fsharp>
<syntaxhighlight lang="fsharp">
Magnanimous |> Seq.skip 390 |> Seq.take 10 |> Seq.iter (printf "%d "); printfn "";;
Magnanimous |> Seq.skip 390 |> Seq.take 10 |> Seq.iter (printf "%d "); printfn "";;
</syntaxhighlight>
</lang>
{{out}}
{{out}}
<pre>
<pre>
Line 558: Line 558:
{{trans|Julia}}
{{trans|Julia}}
{{works with|Factor|0.99 2020-01-23}}
{{works with|Factor|0.99 2020-01-23}}
<lang factor>USING: grouping io kernel lists lists.lazy math math.functions
<syntaxhighlight lang="factor">USING: grouping io kernel lists lists.lazy math math.functions
math.primes math.ranges prettyprint sequences ;
math.primes math.ranges prettyprint sequences ;


Line 576: Line 576:
[ "241st through 250th magnanimous numbers" print 240 250 show ]
[ "241st through 250th magnanimous numbers" print 240 250 show ]
[ "391st through 400th magnanimous numbers" print 390 400 show ]
[ "391st through 400th magnanimous numbers" print 390 400 show ]
tri</lang>
tri</syntaxhighlight>
{{out}}
{{out}}
<pre>
<pre>
Line 592: Line 592:


=={{header|FreeBASIC}}==
=={{header|FreeBASIC}}==
<lang freebasic>
<syntaxhighlight lang="freebasic">
#include "isprime.bas"
#include "isprime.bas"


Line 624: Line 624:
print i+1,magn(i)
print i+1,magn(i)
next i
next i
</syntaxhighlight>
</lang>
{{out}}
{{out}}
<pre>1 0
<pre>1 0
Line 693: Line 693:


=={{header|Go}}==
=={{header|Go}}==
<lang go>package main
<syntaxhighlight lang="go">package main


import "fmt"
import "fmt"
Line 782: Line 782:
listMags(241, 250, 1, 10)
listMags(241, 250, 1, 10)
listMags(391, 400, 1, 10)
listMags(391, 400, 1, 10)
}</lang>
}</syntaxhighlight>


{{out}}
{{out}}
Line 799: Line 799:


=={{header|Haskell}}==
=={{header|Haskell}}==
<lang haskell>import Data.List.Split ( chunksOf )
<syntaxhighlight lang="haskell">import Data.List.Split ( chunksOf )
import Data.List ( (!!) )
import Data.List ( (!!) )


Line 845: Line 845:
putStrLn "391'st to 400th magnanimous numbers:"
putStrLn "391'st to 400th magnanimous numbers:"
putStr $ show ( numbers !! 390 )
putStr $ show ( numbers !! 390 )
putStrLn ( foldl1 ( ++ ) $ map(\n -> printInWidth n 8 ) $ drop 391 numbers)</lang>
putStrLn ( foldl1 ( ++ ) $ map(\n -> printInWidth n 8 ) $ drop 391 numbers)</syntaxhighlight>
{{out}}
{{out}}
<pre>First 45 magnanimous numbers:
<pre>First 45 magnanimous numbers:
Line 860: Line 860:


=={{header|Java}}==
=={{header|Java}}==
<lang java>
<syntaxhighlight lang="java">
import java.util.ArrayList;
import java.util.ArrayList;
import java.util.List;
import java.util.List;
Line 1,046: Line 1,046:


}
}
</syntaxhighlight>
</lang>


{{out}}
{{out}}
Line 1,085: Line 1,085:


'''Preliminaries'''
'''Preliminaries'''
<lang jq># To take advantage of gojq's arbitrary-precision integer arithmetic:
<syntaxhighlight lang="jq"># To take advantage of gojq's arbitrary-precision integer arithmetic:
def power($b): . as $in | reduce range(0;$b) as $i (1; . * $in);
def power($b): . as $in | reduce range(0;$b) as $i (1; . * $in);


def divrem($x; $y):
def divrem($x; $y):
[$x/$y|floor, $x % $y];
[$x/$y|floor, $x % $y];
</syntaxhighlight>
</lang>
'''The Task'''
'''The Task'''
<syntaxhighlight lang="jq">
<lang jq>
def ismagnanimous:
def ismagnanimous:
. as $n
. as $n
Line 1,111: Line 1,111:
| "First 45 magnanimous numbers:", .[:45],
| "First 45 magnanimous numbers:", .[:45],
"\n241st through 250th magnanimous numbers:", .[241:251],
"\n241st through 250th magnanimous numbers:", .[241:251],
"\n391st through 400th magnanimous numbers:", .[391:]</lang>
"\n391st through 400th magnanimous numbers:", .[391:]</syntaxhighlight>
{{out}}
{{out}}
<pre>
<pre>
Line 1,126: Line 1,126:


=={{header|Julia}}==
=={{header|Julia}}==
<lang julia>using Primes
<syntaxhighlight lang="julia">using Primes


function ismagnanimous(n)
function ismagnanimous(n)
Line 1,152: Line 1,152:
println("\n241st through 250th magnanimous numbers:\n", mag400[241:250])
println("\n241st through 250th magnanimous numbers:\n", mag400[241:250])
println("\n391st through 400th magnanimous numbers:\n", mag400[391:400])
println("\n391st through 400th magnanimous numbers:\n", mag400[391:400])
</lang>{{out}}
</syntaxhighlight>{{out}}
<pre>
<pre>
First 45 magnanimous numbers:
First 45 magnanimous numbers:
Line 1,166: Line 1,166:


=={{header|Mathematica}}/{{header|Wolfram Language}}==
=={{header|Mathematica}}/{{header|Wolfram Language}}==
<lang Mathematica>Clear[MagnanimousNumberQ]
<syntaxhighlight lang="mathematica">Clear[MagnanimousNumberQ]
MagnanimousNumberQ[Alternatives @@ Range[0, 9]] = True;
MagnanimousNumberQ[Alternatives @@ Range[0, 9]] = True;
MagnanimousNumberQ[n_Integer] := AllTrue[Range[IntegerLength[n] - 1], PrimeQ[Total[FromDigits /@ TakeDrop[IntegerDigits[n], #]]] &]
MagnanimousNumberQ[n_Integer] := AllTrue[Range[IntegerLength[n] - 1], PrimeQ[Total[FromDigits /@ TakeDrop[IntegerDigits[n], #]]] &]
Line 1,172: Line 1,172:
sel[[;; 45]]
sel[[;; 45]]
sel[[241 ;; 250]]
sel[[241 ;; 250]]
sel[[391 ;; 400]]</lang>
sel[[391 ;; 400]]</syntaxhighlight>
{{out}}
{{out}}
<pre>{0,1,2,3,4,5,6,7,8,9,11,12,14,16,20,21,23,25,29,30,32,34,38,41,43,47,49,50,52,56,58,61,65,67,70,74,76,83,85,89,92,94,98,101,110}
<pre>{0,1,2,3,4,5,6,7,8,9,11,12,14,16,20,21,23,25,29,30,32,34,38,41,43,47,49,50,52,56,58,61,65,67,70,74,76,83,85,89,92,94,98,101,110}
Line 1,179: Line 1,179:


=={{header|Nim}}==
=={{header|Nim}}==
<lang Nim>func isPrime(n: Natural): bool =
<syntaxhighlight lang="nim">func isPrime(n: Natural): bool =
if n < 2: return
if n < 2: return
if n mod 2 == 0: return n == 2
if n mod 2 == 0: return n == 2
Line 1,226: Line 1,226:


elif i > 400:
elif i > 400:
break</lang>
break</syntaxhighlight>


{{out}}
{{out}}
Line 1,242: Line 1,242:
Eliminating all numbers, which would sum to 5 in the last digit.<br>
Eliminating all numbers, which would sum to 5 in the last digit.<br>
On TIO.RUN found all til 569 84448000009 0.715 s
On TIO.RUN found all til 569 84448000009 0.715 s
<lang pascal>program Magnanimous;
<syntaxhighlight lang="pascal">program Magnanimous;
//Magnanimous Numbers
//Magnanimous Numbers
//algorithm find only numbers where all digits are even except the last
//algorithm find only numbers where all digits are even except the last
Line 1,624: Line 1,624:
readln;
readln;
{$ENDIF}
{$ENDIF}
end.</lang>
end.</syntaxhighlight>
{{out}}
{{out}}
<pre style="height:180px">
<pre style="height:180px">
Line 2,209: Line 2,209:
{{trans|Raku}}
{{trans|Raku}}
{{libheader|ntheory}}
{{libheader|ntheory}}
<lang perl>use strict;
<syntaxhighlight lang="perl">use strict;
use warnings;
use warnings;
use feature 'say';
use feature 'say';
Line 2,235: Line 2,235:


say "\n391st through 400th magnanimous numbers\n".
say "\n391st through 400th magnanimous numbers\n".
join ' ', @M[390..399];</lang>
join ' ', @M[390..399];</syntaxhighlight>
{{out}}
{{out}}
<pre>First 45 magnanimous numbers
<pre>First 45 magnanimous numbers
Line 2,249: Line 2,249:


=={{header|Phix}}==
=={{header|Phix}}==
<!--<lang Phix>(phixonline)-->
<!--<syntaxhighlight lang="phix">(phixonline)-->
<span style="color: #008080;">with</span> <span style="color: #008080;">javascript_semantics</span>
<span style="color: #008080;">with</span> <span style="color: #008080;">javascript_semantics</span>
<span style="color: #008080;">function</span> <span style="color: #000000;">magnanimous</span><span style="color: #0000FF;">(</span><span style="color: #004080;">integer</span> <span style="color: #000000;">n</span><span style="color: #0000FF;">)</span>
<span style="color: #008080;">function</span> <span style="color: #000000;">magnanimous</span><span style="color: #0000FF;">(</span><span style="color: #004080;">integer</span> <span style="color: #000000;">n</span><span style="color: #0000FF;">)</span>
Line 2,271: Line 2,271:
<span style="color: #7060A8;">printf</span><span style="color: #0000FF;">(</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"magnanimous numbers[241..250]: %v\n"</span><span style="color: #0000FF;">,</span> <span style="color: #0000FF;">{</span><span style="color: #000000;">mag</span><span style="color: #0000FF;">[</span><span style="color: #000000;">241</span><span style="color: #0000FF;">..</span><span style="color: #000000;">250</span><span style="color: #0000FF;">]})</span>
<span style="color: #7060A8;">printf</span><span style="color: #0000FF;">(</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"magnanimous numbers[241..250]: %v\n"</span><span style="color: #0000FF;">,</span> <span style="color: #0000FF;">{</span><span style="color: #000000;">mag</span><span style="color: #0000FF;">[</span><span style="color: #000000;">241</span><span style="color: #0000FF;">..</span><span style="color: #000000;">250</span><span style="color: #0000FF;">]})</span>
<span style="color: #7060A8;">printf</span><span style="color: #0000FF;">(</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"magnanimous numbers[391..400]: %v\n"</span><span style="color: #0000FF;">,</span> <span style="color: #0000FF;">{</span><span style="color: #000000;">mag</span><span style="color: #0000FF;">[</span><span style="color: #000000;">391</span><span style="color: #0000FF;">..</span><span style="color: #000000;">400</span><span style="color: #0000FF;">]})</span>
<span style="color: #7060A8;">printf</span><span style="color: #0000FF;">(</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"magnanimous numbers[391..400]: %v\n"</span><span style="color: #0000FF;">,</span> <span style="color: #0000FF;">{</span><span style="color: #000000;">mag</span><span style="color: #0000FF;">[</span><span style="color: #000000;">391</span><span style="color: #0000FF;">..</span><span style="color: #000000;">400</span><span style="color: #0000FF;">]})</span>
<!--</lang>-->
<!--</syntaxhighlight>-->
{{out}}
{{out}}
<pre>
<pre>
Line 2,281: Line 2,281:


=={{header|PicoLisp}}==
=={{header|PicoLisp}}==
<lang PicoLisp>(de **Mod (X Y N)
<syntaxhighlight lang="picolisp">(de **Mod (X Y N)
(let M 1
(let M 1
(loop
(loop
Line 2,340: Line 2,340:
(println (head 45 Lst))
(println (head 45 Lst))
(println (head 10 (nth Lst 241)))
(println (head 10 (nth Lst 241)))
(println (head 10 (nth Lst 391))) )</lang>
(println (head 10 (nth Lst 391))) )</syntaxhighlight>
{{out}}
{{out}}
<pre>
<pre>
Line 2,351: Line 2,351:
This sample can be compiled with the original 8080 PL/M compiler and run under CP/M (or a clone/emulator).
This sample can be compiled with the original 8080 PL/M compiler and run under CP/M (or a clone/emulator).
<br>THe original 8080 PL/M only supports 8 and 16 bit quantities, so this only shows magnanimous numbers up to the 250th.
<br>THe original 8080 PL/M only supports 8 and 16 bit quantities, so this only shows magnanimous numbers up to the 250th.
<lang plm>100H: /* FIND SOME MAGNANIMOUS NUMBERS - THOSE WHERE INSERTING '+' BETWEEN */
<syntaxhighlight lang="plm">100H: /* FIND SOME MAGNANIMOUS NUMBERS - THOSE WHERE INSERTING '+' BETWEEN */
/* ANY TWO OF THE DIGITS AND EVALUATING THE SUM RESULTS IN A PRIME */
/* ANY TWO OF THE DIGITS AND EVALUATING THE SUM RESULTS IN A PRIME */
BDOS: PROCEDURE( FN, ARG ); /* CP/M BDOS SYSTEM CALL */
BDOS: PROCEDURE( FN, ARG ); /* CP/M BDOS SYSTEM CALL */
Line 2,509: Line 2,509:
END;
END;
CALL PRINT$NL;
CALL PRINT$NL;
EOF</lang>
EOF</syntaxhighlight>
{{out}}
{{out}}
<pre>
<pre>
Line 2,523: Line 2,523:
{{works with|Rakudo|2020.02}}
{{works with|Rakudo|2020.02}}


<lang perl6>my @magnanimous = lazy flat ^10, (10 .. 1001).map( {
<syntaxhighlight lang="raku" line>my @magnanimous = lazy flat ^10, (10 .. 1001).map( {
my int $last;
my int $last;
(1 ..^ .chars).map: -> \c { $last = 1 and last unless (.substr(0,c) + .substr(c)).is-prime }
(1 ..^ .chars).map: -> \c { $last = 1 and last unless (.substr(0,c) + .substr(c)).is-prime }
Line 2,546: Line 2,546:


put "\n391st through 400th magnanimous numbers";
put "\n391st through 400th magnanimous numbers";
put @magnanimous[390..399];</lang>
put @magnanimous[390..399];</syntaxhighlight>
{{out}}
{{out}}
<pre>First 45 magnanimous numbers
<pre>First 45 magnanimous numbers
Line 2,563: Line 2,563:
<br>The '''magna''' function (magnanimous) was quite simple to code and pretty fast, it includes the 1<sup>st</sup> and last digit parity test.
<br>The '''magna''' function (magnanimous) was quite simple to code and pretty fast, it includes the 1<sup>st</sup> and last digit parity test.
<br>By far, the most CPU time was in the generation of primes.
<br>By far, the most CPU time was in the generation of primes.
<lang REXX>/*REXX pgm finds/displays magnanimous #s (#s with a inserted + sign to sum to a prime).*/
<syntaxhighlight lang="rexx">/*REXX pgm finds/displays magnanimous #s (#s with a inserted + sign to sum to a prime).*/
parse arg bet.1 bet.2 bet.3 highP . /*obtain optional arguments from the CL*/
parse arg bet.1 bet.2 bet.3 highP . /*obtain optional arguments from the CL*/
if bet.1=='' | bet.1=="," then bet.1= 1..45 /* " " " " " " */
if bet.1=='' | bet.1=="," then bet.1= 1..45 /* " " " " " " */
Line 2,607: Line 2,607:
end /*k*/ /* [↓] a prime (J) has been found. */
end /*k*/ /* [↓] a prime (J) has been found. */
#= #+1; @.#= j; sq.#= j*j; !.j= 1 /*bump #Ps; P──►@.assign P; P^2; P flag*/
#= #+1; @.#= j; sq.#= j*j; !.j= 1 /*bump #Ps; P──►@.assign P; P^2; P flag*/
end /*j*/; return</lang>
end /*j*/; return</syntaxhighlight>
{{out|output|text=&nbsp; when using the default inputs:}}
{{out|output|text=&nbsp; when using the default inputs:}}
<pre>
<pre>
Line 2,625: Line 2,625:


=={{header|Ring}}==
=={{header|Ring}}==
<lang ring>
<syntaxhighlight lang="ring">
load "stdlib.ring"
load "stdlib.ring"
n = -1
n = -1
Line 2,698: Line 2,698:
txt = txt + "]"
txt = txt + "]"
see txt
see txt
</syntaxhighlight>
</lang>
<pre>
<pre>
Magnanimous numbers 1-45:
Magnanimous numbers 1-45:
Line 2,708: Line 2,708:
=={{header|Ruby}}==
=={{header|Ruby}}==
{{trans|Sidef}}
{{trans|Sidef}}
<lang ruby>require "prime"
<syntaxhighlight lang="ruby">require "prime"


magnanimouses = Enumerator.new do |y|
magnanimouses = Enumerator.new do |y|
Line 2,722: Line 2,722:
puts "\n391st through 400th magnanimous numbers:"
puts "\n391st through 400th magnanimous numbers:"
puts magnanimouses.first(400).last(10).join(' ')
puts magnanimouses.first(400).last(10).join(' ')
</syntaxhighlight>
</lang>
{{out}}
{{out}}
<pre>First 45 magnanimous numbers:
<pre>First 45 magnanimous numbers:
Line 2,735: Line 2,735:


=={{header|Rust}}==
=={{header|Rust}}==
<lang rust>fn is_prime(n: u32) -> bool {
<syntaxhighlight lang="rust">fn is_prime(n: u32) -> bool {
if n < 2 {
if n < 2 {
return false;
return false;
Line 2,788: Line 2,788:
}
}
println!();
println!();
}</lang>
}</syntaxhighlight>


{{out}}
{{out}}
Line 2,805: Line 2,805:


=={{header|Sidef}}==
=={{header|Sidef}}==
<lang ruby>func is_magnanimous(n) {
<syntaxhighlight lang="ruby">func is_magnanimous(n) {
1..n.ilog10 -> all {|k|
1..n.ilog10 -> all {|k|
sum(divmod(n, k.ipow10)).is_prime
sum(divmod(n, k.ipow10)).is_prime
Line 2,818: Line 2,818:


say "\n391st through 400th magnanimous numbers:"
say "\n391st through 400th magnanimous numbers:"
say is_magnanimous.first(400).last(10).join(' ')</lang>
say is_magnanimous.first(400).last(10).join(' ')</syntaxhighlight>
{{out}}
{{out}}
<pre>
<pre>
Line 2,833: Line 2,833:
=={{header|Swift}}==
=={{header|Swift}}==
{{trans|Rust}}
{{trans|Rust}}
<lang swift>import Foundation
<syntaxhighlight lang="swift">import Foundation


func isPrime(_ n: Int) -> Bool {
func isPrime(_ n: Int) -> Bool {
Line 2,886: Line 2,886:
print(n, terminator: " ")
print(n, terminator: " ")
}
}
print()</lang>
print()</syntaxhighlight>


{{out}}
{{out}}
Line 2,904: Line 2,904:
=={{header|Visual Basic .NET}}==
=={{header|Visual Basic .NET}}==
{{trans|C#}}
{{trans|C#}}
<lang vbnet>Imports System, System.Console
<syntaxhighlight lang="vbnet">Imports System, System.Console


Module Module1
Module Module1
Line 2,937: Line 2,937:
End If : l += 1 : End While
End If : l += 1 : End While
End Sub
End Sub
End Module</lang>
End Module</syntaxhighlight>
{{out}}
{{out}}
<pre>First 45 magnanimous numbers:
<pre>First 45 magnanimous numbers:
Line 2,954: Line 2,954:
{{libheader|Wren-math}}
{{libheader|Wren-math}}
{{trans|Go}}
{{trans|Go}}
<lang ecmascript>import "/fmt" for Conv, Fmt
<syntaxhighlight lang="ecmascript">import "/fmt" for Conv, Fmt
import "/math" for Int
import "/math" for Int
Line 2,992: Line 2,992:
listMags.call(1, 45, 3, 15)
listMags.call(1, 45, 3, 15)
listMags.call(241, 250, 1, 10)
listMags.call(241, 250, 1, 10)
listMags.call(391, 400, 1, 10)</lang>
listMags.call(391, 400, 1, 10)</syntaxhighlight>


{{out}}
{{out}}