Primes whose first and last number is 3: Difference between revisions
Content added Content deleted
(→J: speedup 20x, add stretch goal) |
m (→{{header|Wren}}: Minor tidy) |
||
Line 1,030: | Line 1,030: | ||
{{libheader|Wren-math}} |
{{libheader|Wren-math}} |
||
{{libheader|Wren-iterate}} |
{{libheader|Wren-iterate}} |
||
{{libheader|Wren-seq}} |
|||
{{libheader|Wren-fmt}} |
{{libheader|Wren-fmt}} |
||
===Basic task=== |
===Basic task=== |
||
<syntaxhighlight lang=" |
<syntaxhighlight lang="wren">import "./math" for Int |
||
import "/iterate" for Stepped |
import "./iterate" for Stepped |
||
import "/ |
import "./fmt" for Fmt |
||
import "/fmt" for Fmt |
|||
var primes = [] |
var primes = [] |
||
Line 1,044: | Line 1,042: | ||
} |
} |
||
System.print("Primes under 4,000 which begin and end in 3:") |
System.print("Primes under 4,000 which begin and end in 3:") |
||
Fmt.tprint("$,5d", primes, 11) |
|||
System.print("\nFound %(primes.count) such primes.")</syntaxhighlight> |
System.print("\nFound %(primes.count) such primes.")</syntaxhighlight> |
||
Line 1,059: | Line 1,057: | ||
===More general=== |
===More general=== |
||
This version deals with primes (in base 10) beginning and ending with any specified digit and with up to a given number of digits. |
This version deals with primes (in base 10) beginning and ending with any specified digit and with up to a given number of digits. |
||
<syntaxhighlight lang=" |
<syntaxhighlight lang="wren">import "./math" for Int |
||
import "/iterate" for Stepped |
import "./iterate" for Stepped |
||
import "/ |
import "./fmt" for Fmt |
||
import "/fmt" for Fmt |
|||
var getQualifyingPrimes = Fn.new { |x, d| |
var getQualifyingPrimes = Fn.new { |x, d| |
||
Line 1,084: | Line 1,081: | ||
var len = d + ((d-1)/3).floor |
var len = d + ((d-1)/3).floor |
||
Fmt.print("Primes under $,%(len)d which begin and end in $d:", 10.pow(d), x) |
Fmt.print("Primes under $,%(len)d which begin and end in $d:", 10.pow(d), x) |
||
Fmt.tprint("$,%(len)d", primes, 10) |
|||
System.print("\nFound %(primes.count) such primes.\n") |
System.print("\nFound %(primes.count) such primes.\n") |
||
} |
} |