N-smooth numbers: Difference between revisions
Content added Content deleted
(Added Quackery.) |
Thundergnat (talk | contribs) m (syntax highlighting fixup automation) |
||
Line 56: | Line 56: | ||
{{trans|Python}} |
{{trans|Python}} |
||
< |
<syntaxhighlight lang="11l">V primes = [2, 3, 5, 7, 11, 13, 17, 19, 23] |
||
F isPrime(n) |
F isPrime(n) |
||
Line 131: | Line 131: | ||
print(‘The 30000 to 3019 ’p‘ -smooth numbers are:’) |
print(‘The 30000 to 3019 ’p‘ -smooth numbers are:’) |
||
print(nsmooth(p, 30019)[29999..]) |
print(nsmooth(p, 30019)[29999..]) |
||
print()</ |
print()</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
Line 205: | Line 205: | ||
=={{header|C}}== |
=={{header|C}}== |
||
{{libheader|GMP}} |
{{libheader|GMP}} |
||
< |
<syntaxhighlight lang="c">#include <stdbool.h> |
||
#include <stdint.h> |
#include <stdint.h> |
||
#include <stdio.h> |
#include <stdio.h> |
||
Line 330: | Line 330: | ||
} |
} |
||
return 0; |
return 0; |
||
}</ |
}</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
Line 366: | Line 366: | ||
{{trans|D}} |
{{trans|D}} |
||
The output for the 30,000 3-smooth numbers is not correct due to insuffiant bits to represent that actual value |
The output for the 30,000 3-smooth numbers is not correct due to insuffiant bits to represent that actual value |
||
< |
<syntaxhighlight lang="cpp">#include <algorithm> |
||
#include <iostream> |
#include <iostream> |
||
#include <vector> |
#include <vector> |
||
Line 498: | Line 498: | ||
return 0; |
return 0; |
||
}</ |
}</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
<pre>The first 2-smooth numbers are: |
<pre>The first 2-smooth numbers are: |
||
Line 559: | Line 559: | ||
=={{header|C sharp|C#}}== |
=={{header|C sharp|C#}}== |
||
{{trans|D}} |
{{trans|D}} |
||
< |
<syntaxhighlight lang="csharp">using System; |
||
using System.Collections.Generic; |
using System.Collections.Generic; |
||
using System.Linq; |
using System.Linq; |
||
Line 698: | Line 698: | ||
} |
} |
||
} |
} |
||
}</ |
}</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
<pre>The first 2-smooth numbers are: |
<pre>The first 2-smooth numbers are: |
||
Line 768: | Line 768: | ||
=={{header|Crystal}}== |
=={{header|Crystal}}== |
||
{{trans|Ruby}} |
{{trans|Ruby}} |
||
< |
<syntaxhighlight lang="ruby">require "big" |
||
def prime?(n) # P3 Prime Generator primality test |
def prime?(n) # P3 Prime Generator primality test |
||
Line 823: | Line 823: | ||
print nsmooth(prime, 30019)[29999..] |
print nsmooth(prime, 30019)[29999..] |
||
puts |
puts |
||
end</ |
end</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
Line 868: | Line 868: | ||
=={{header|D}}== |
=={{header|D}}== |
||
{{trans|Kotlin}} |
{{trans|Kotlin}} |
||
< |
<syntaxhighlight lang="d">import std.algorithm; |
||
import std.bigint; |
import std.bigint; |
||
import std.exception; |
import std.exception; |
||
Line 986: | Line 986: | ||
writeln; |
writeln; |
||
} |
} |
||
}</ |
}</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
<pre>The first 2-smooth numbers are: |
<pre>The first 2-smooth numbers are: |
||
Line 1,059: | Line 1,059: | ||
{{libheader| Velthuis.BigIntegers}}Thanks for Rudy Velthuis[https://github.com/rvelthuis/DelphiBigNumbers] |
{{libheader| Velthuis.BigIntegers}}Thanks for Rudy Velthuis[https://github.com/rvelthuis/DelphiBigNumbers] |
||
{{Trans|D}} |
{{Trans|D}} |
||
<syntaxhighlight lang="delphi"> |
|||
<lang Delphi> |
|||
program N_smooth_numbers; |
program N_smooth_numbers; |
||
Line 1,256: | Line 1,256: | ||
Readln; |
Readln; |
||
end. |
end. |
||
</syntaxhighlight> |
|||
</lang> |
|||
=={{header|Factor}}== |
=={{header|Factor}}== |
||
< |
<syntaxhighlight lang="factor">USING: deques dlists formatting fry io kernel locals make math |
||
math.order math.primes math.text.english namespaces prettyprint |
math.order math.primes math.text.english namespaces prettyprint |
||
sequences tools.memory.private ; |
sequences tools.memory.private ; |
||
Line 1,297: | Line 1,297: | ||
503 521 30,000 30,019 show-smooth ; |
503 521 30,000 30,019 show-smooth ; |
||
MAIN: smooth-numbers-demo</ |
MAIN: smooth-numbers-demo</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
<pre> |
<pre> |
||
Line 1,327: | Line 1,327: | ||
=={{header|Go}}== |
=={{header|Go}}== |
||
< |
<syntaxhighlight lang="go">package main |
||
import ( |
import ( |
||
Line 1,425: | Line 1,425: | ||
fmt.Println(nSmooth(i, 30019)[29999:], "\n") |
fmt.Println(nSmooth(i, 30019)[29999:], "\n") |
||
} |
} |
||
}</ |
}</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
Line 1,498: | Line 1,498: | ||
The solution is based on the hamming numbers solution [[Hamming_numbers#Avoiding_generation_of_duplicates]].<br> |
The solution is based on the hamming numbers solution [[Hamming_numbers#Avoiding_generation_of_duplicates]].<br> |
||
Uses Library Data.Number.Primes: http://hackage.haskell.org/package/primes-0.2.1.0/docs/Data-Numbers-Primes.html |
Uses Library Data.Number.Primes: http://hackage.haskell.org/package/primes-0.2.1.0/docs/Data-Numbers-Primes.html |
||
< |
<syntaxhighlight lang="haskell">import Data.Numbers.Primes (primes) |
||
import Text.Printf (printf) |
import Text.Printf (printf) |
||
Line 1,527: | Line 1,527: | ||
showTwentyFive = show . take 25 . nSmooth |
showTwentyFive = show . take 25 . nSmooth |
||
showRange1 = show . ((<$> [2999 .. 3001]) . (!!) . nSmooth) |
showRange1 = show . ((<$> [2999 .. 3001]) . (!!) . nSmooth) |
||
showRange2 = show . ((<$> [29999 .. 30018]) . (!!) . nSmooth)</ |
showRange2 = show . ((<$> [29999 .. 30018]) . (!!) . nSmooth)</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
<pre> |
<pre> |
||
Line 1,604: | Line 1,604: | ||
=={{header|J}}== |
=={{header|J}}== |
||
This solution involves sorting, duplicate removal, and limits on the number of preserved terms. |
This solution involves sorting, duplicate removal, and limits on the number of preserved terms. |
||
<syntaxhighlight lang="j"> |
|||
<lang J> |
|||
nsmooth=: dyad define NB. TALLY nsmooth N |
nsmooth=: dyad define NB. TALLY nsmooth N |
||
factors=. x: i.@:>:&.:(p:inv) y |
factors=. x: i.@:>:&.:(p:inv) y |
||
Line 1,615: | Line 1,615: | ||
end. |
end. |
||
) |
) |
||
</syntaxhighlight> |
|||
</lang> |
|||
<pre> |
<pre> |
||
25 (] ; nsmooth)&> p: i. 10 |
25 (] ; nsmooth)&> p: i. 10 |
||
Line 1,665: | Line 1,665: | ||
=={{header|Java}}== |
=={{header|Java}}== |
||
< |
<syntaxhighlight lang="java"> |
||
import java.math.BigInteger; |
import java.math.BigInteger; |
||
import java.util.ArrayList; |
import java.util.ArrayList; |
||
Line 1,770: | Line 1,770: | ||
} |
} |
||
</syntaxhighlight> |
|||
</lang> |
|||
{{out}} |
{{out}} |
||
Line 1,845: | Line 1,845: | ||
=={{header|JavaScript}}== |
=={{header|JavaScript}}== |
||
< |
<syntaxhighlight lang="javascript"> |
||
function isPrime(n){ |
function isPrime(n){ |
||
var x = Math.floor(Math.sqrt(n)), i = 2 |
var x = Math.floor(Math.sqrt(n)), i = 2 |
||
Line 1,894: | Line 1,894: | ||
console.log(sOut) |
console.log(sOut) |
||
</syntaxhighlight> |
|||
</lang> |
|||
{{out}} |
{{out}} |
||
Line 1,923: | Line 1,923: | ||
=={{header|Julia}}== |
=={{header|Julia}}== |
||
< |
<syntaxhighlight lang="julia">using Primes |
||
function nsmooth(N, needed) |
function nsmooth(N, needed) |
||
Line 1,953: | Line 1,953: | ||
testnsmoothfilters() |
testnsmoothfilters() |
||
</ |
</syntaxhighlight>{{out}} |
||
<pre> |
<pre> |
||
The first 25 n-smooth numbers for n = 2 are: [1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768, 65536, 131072, 262144, 524288, 1048576, 2097152, 4194304, 8388608, 16777216] |
The first 25 n-smooth numbers for n = 2 are: [1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768, 65536, 131072, 262144, 524288, 1048576, 2097152, 4194304, 8388608, 16777216] |
||
Line 1,981: | Line 1,981: | ||
=={{header|Kotlin}}== |
=={{header|Kotlin}}== |
||
{{trans|Go}} |
{{trans|Go}} |
||
< |
<syntaxhighlight lang="scala">import java.math.BigInteger |
||
var primes = mutableListOf<BigInteger>() |
var primes = mutableListOf<BigInteger>() |
||
Line 2,073: | Line 2,073: | ||
println() |
println() |
||
} |
} |
||
}</ |
}</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
<pre>The first 25 2-smooth numbers are: |
<pre>The first 25 2-smooth numbers are: |
||
Line 2,142: | Line 2,142: | ||
=={{header|Mathematica}} / {{header|Wolfram Language}}== |
=={{header|Mathematica}} / {{header|Wolfram Language}}== |
||
< |
<syntaxhighlight lang="mathematica">ClearAll[GenerateSmoothNumbers] |
||
GenerateSmoothNumbers[max_?Positive] := GenerateSmoothNumbers[max, 7] |
GenerateSmoothNumbers[max_?Positive] := GenerateSmoothNumbers[max, 7] |
||
GenerateSmoothNumbers[max_?Positive, maxprime_?Positive] := |
GenerateSmoothNumbers[max_?Positive, maxprime_?Positive] := |
||
Line 2,188: | Line 2,188: | ||
s[[30000 ;; 30019]] |
s[[30000 ;; 30019]] |
||
s = Select[Range[10^5], FactorInteger /* Last /* First /* LessEqualThan[521]]; |
s = Select[Range[10^5], FactorInteger /* Last /* First /* LessEqualThan[521]]; |
||
s[[30000 ;; 30019]]</ |
s[[30000 ;; 30019]]</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
<pre>{1,2,4,8,16,32,64,128,256,512,1024,2048,4096,8192,16384,32768,65536,131072,262144,524288,1048576,2097152,4194304,8388608,16777216} |
<pre>{1,2,4,8,16,32,64,128,256,512,1024,2048,4096,8192,16384,32768,65536,131072,262144,524288,1048576,2097152,4194304,8388608,16777216} |
||
Line 2,217: | Line 2,217: | ||
{{libheader|bignum}} |
{{libheader|bignum}} |
||
Translation of Kotlin except for the search of primes where we have chosen to use a sieve of Eratosthenes. |
Translation of Kotlin except for the search of primes where we have chosen to use a sieve of Eratosthenes. |
||
< |
<syntaxhighlight lang="nim">import sequtils, strutils |
||
import bignum |
import bignum |
||
Line 2,278: | Line 2,278: | ||
echo "The 30000th to 30019th ", n, "-smooth numbers are:" |
echo "The 30000th to 30019th ", n, "-smooth numbers are:" |
||
echo nSmooth(n, 30_019)[29_999..^1].join(" ") |
echo nSmooth(n, 30_019)[29_999..^1].join(" ") |
||
echo ""</ |
echo ""</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
Line 2,350: | Line 2,350: | ||
=={{header|Pascal}}== |
=={{header|Pascal}}== |
||
{{works with|Extended Pascal}} |
{{works with|Extended Pascal}} |
||
< |
<syntaxhighlight lang="pascal">program nSmoothNumbers(output); |
||
const |
const |
||
Line 2,592: | Line 2,592: | ||
writeLn |
writeLn |
||
end; |
end; |
||
end.</ |
end.</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
<pre style="height:45ex"> 2-smooth: 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768, 65536, 131072, 262144, 524288, 1048576, 2097152, 4194304, 8388608, 16777216 |
<pre style="height:45ex"> 2-smooth: 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768, 65536, 131072, 262144, 524288, 1048576, 2097152, 4194304, 8388608, 16777216 |
||
Line 2,617: | Line 2,617: | ||
=={{header|Perl}}== |
=={{header|Perl}}== |
||
{{libheader|ntheory}} |
{{libheader|ntheory}} |
||
< |
<syntaxhighlight lang="perl">use strict; |
||
use warnings; |
use warnings; |
||
use feature 'say'; |
use feature 'say'; |
||
Line 2,677: | Line 2,677: | ||
} until @Sm == $cnt; |
} until @Sm == $cnt; |
||
say join ' ', @Sm; |
say join ' ', @Sm; |
||
}</ |
}</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
Line 2,732: | Line 2,732: | ||
{{libheader|Phix/mpfr}} |
{{libheader|Phix/mpfr}} |
||
{{trans|Julia}} |
{{trans|Julia}} |
||
<!--< |
<!--<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;">include</span> <span style="color: #004080;">mpfr</span><span style="color: #0000FF;">.</span><span style="color: #000000;">e</span> |
<span style="color: #008080;">include</span> <span style="color: #004080;">mpfr</span><span style="color: #0000FF;">.</span><span style="color: #000000;">e</span> |
||
Line 2,769: | Line 2,769: | ||
<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;">"%d-smooth[30000..30019]: %s\n"</span><span style="color: #0000FF;">,{</span><span style="color: #7060A8;">get_prime</span><span style="color: #0000FF;">(</span><span style="color: #000000;">n</span><span style="color: #0000FF;">),</span><span style="color: #000000;">flat_str</span><span style="color: #0000FF;">(</span><span style="color: #000000;">nsmooth</span><span style="color: #0000FF;">(</span><span style="color: #000000;">n</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">30019</span><span style="color: #0000FF;">)[</span><span style="color: #000000;">30000</span><span style="color: #0000FF;">..</span><span style="color: #000000;">30019</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;">"%d-smooth[30000..30019]: %s\n"</span><span style="color: #0000FF;">,{</span><span style="color: #7060A8;">get_prime</span><span style="color: #0000FF;">(</span><span style="color: #000000;">n</span><span style="color: #0000FF;">),</span><span style="color: #000000;">flat_str</span><span style="color: #0000FF;">(</span><span style="color: #000000;">nsmooth</span><span style="color: #0000FF;">(</span><span style="color: #000000;">n</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">30019</span><span style="color: #0000FF;">)[</span><span style="color: #000000;">30000</span><span style="color: #0000FF;">..</span><span style="color: #000000;">30019</span><span style="color: #0000FF;">])})</span> |
||
<span style="color: #008080;">end</span> <span style="color: #008080;">for</span> |
<span style="color: #008080;">end</span> <span style="color: #008080;">for</span> |
||
<!--</ |
<!--</syntaxhighlight>--> |
||
{{out}} |
{{out}} |
||
<pre> |
<pre> |
||
Line 2,799: | Line 2,799: | ||
=={{header|Python}}== |
=={{header|Python}}== |
||
{{trans|C#}} |
{{trans|C#}} |
||
< |
<syntaxhighlight lang="python">primes = [2, 3, 5, 7, 11, 13, 17, 19, 23] |
||
def isPrime(n): |
def isPrime(n): |
||
Line 2,879: | Line 2,879: | ||
print |
print |
||
main()</ |
main()</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
<pre>The first 2 -smooth numbers are: |
<pre>The first 2 -smooth numbers are: |
||
Line 2,949: | Line 2,949: | ||
=={{header|Quackery}}== |
=={{header|Quackery}}== |
||
<syntaxhighlight lang="quackery"> |
|||
<lang Quackery> |
|||
[ behead 0 swap rot |
[ behead 0 swap rot |
||
witheach |
witheach |
||
Line 2,992: | Line 2,992: | ||
[ i^ 2 + primes |
[ i^ 2 + primes |
||
smoothwith [ size 3002 = ] |
smoothwith [ size 3002 = ] |
||
-3 split nip echo cr ]</ |
-3 split nip echo cr ]</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
Line 3,022: | Line 3,022: | ||
{{works with|Rakudo|2019.07.1}} |
{{works with|Rakudo|2019.07.1}} |
||
<lang |
<syntaxhighlight lang="raku" line>sub smooth-numbers (*@list) { |
||
cache my \Smooth := gather { |
cache my \Smooth := gather { |
||
my %i = (flat @list) Z=> (Smooth.iterator for ^@list); |
my %i = (flat @list) Z=> (Smooth.iterator for ^@list); |
||
Line 3,059: | Line 3,059: | ||
put "\n{$start}th through {$start+19}th {@primes[$i]}-smooth numbers:\n" ~ |
put "\n{$start}th through {$start+19}th {@primes[$i]}-smooth numbers:\n" ~ |
||
smooth-numbers(|@primes[0..$i])[$start - 1 .. $start + 18]; |
smooth-numbers(|@primes[0..$i])[$start - 1 .. $start + 18]; |
||
}</ |
}</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
Line 3,112: | Line 3,112: | ||
=={{header|REXX}}== |
=={{header|REXX}}== |
||
< |
<syntaxhighlight lang="rexx">/*REXX pgm computes&displays X n-smooth numbers; both X and N can be specified as ranges*/ |
||
numeric digits 200 /*be able to handle some big numbers. */ |
numeric digits 200 /*be able to handle some big numbers. */ |
||
parse arg LOx HIx LOn HIn . /*obtain optional arguments from the CL*/ |
parse arg LOx HIx LOn HIn . /*obtain optional arguments from the CL*/ |
||
Line 3,155: | Line 3,155: | ||
end /*j*/; return |
end /*j*/; return |
||
/*──────────────────────────────────────────────────────────────────────────────────────*/ |
/*──────────────────────────────────────────────────────────────────────────────────────*/ |
||
th: parse arg th; return th || word('th st nd rd', 1+(th//10)*(th//100%10\==1)*(th//10<4))</ |
th: parse arg th; return th || word('th st nd rd', 1+(th//10)*(th//100%10\==1)*(th//10<4))</syntaxhighlight> |
||
{{out|output|text= when using the default inputs:}} |
{{out|output|text= when using the default inputs:}} |
||
<pre> |
<pre> |
||
Line 3,231: | Line 3,231: | ||
=={{header|Ruby}}== |
=={{header|Ruby}}== |
||
{{trans|Python}} |
{{trans|Python}} |
||
< |
<syntaxhighlight lang="ruby">def prime?(n) # P3 Prime Generator primality test |
||
return n | 1 == 3 if n < 5 # n: 2,3|true; 0,1,4|false |
return n | 1 == 3 if n < 5 # n: 2,3|true; 0,1,4|false |
||
return false if n.gcd(6) != 1 # this filters out 2/3 of all integers |
return false if n.gcd(6) != 1 # this filters out 2/3 of all integers |
||
Line 3,284: | Line 3,284: | ||
print nsmooth(prime, 30019)[29999..-1] # for ruby >= 2.6: (..)[29999..] |
print nsmooth(prime, 30019)[29999..-1] # for ruby >= 2.6: (..)[29999..] |
||
puts |
puts |
||
end</ |
end</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
Line 3,329: | Line 3,329: | ||
=={{header|Rust}}== |
=={{header|Rust}}== |
||
{{trans|C}} |
{{trans|C}} |
||
< |
<syntaxhighlight lang="rust">fn is_prime(n: u32) -> bool { |
||
if n < 2 { |
if n < 2 { |
||
return false; |
return false; |
||
Line 3,422: | Line 3,422: | ||
} |
} |
||
} |
} |
||
}</ |
}</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
Line 3,456: | Line 3,456: | ||
=={{header|Sidef}}== |
=={{header|Sidef}}== |
||
< |
<syntaxhighlight lang="ruby">func smooth_generator(primes) { |
||
var s = primes.len.of { [1] } |
var s = primes.len.of { [1] } |
||
{ |
{ |
||
Line 3,478: | Line 3,478: | ||
var g = smooth_generator(p.primes) |
var g = smooth_generator(p.primes) |
||
say ("3,000th through 3,002nd #{'%2d'%p}-smooth numbers: ", 3002.of { g.run }.last(3).join(' ')) |
say ("3,000th through 3,002nd #{'%2d'%p}-smooth numbers: ", 3002.of { g.run }.last(3).join(' ')) |
||
}</ |
}</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
<pre> |
<pre> |
||
Line 3,504: | Line 3,504: | ||
Optionally, an efficient algorithm for checking if a given arbitrary large number is smooth over a given product of primes: |
Optionally, an efficient algorithm for checking if a given arbitrary large number is smooth over a given product of primes: |
||
< |
<syntaxhighlight lang="ruby">func is_smooth_over_prod(n, k) { |
||
return true if (n == 1) |
return true if (n == 1) |
||
Line 3,521: | Line 3,521: | ||
var a = {|n| is_smooth_over_prod(n, k) }.first(30_019).last(20) |
var a = {|n| is_smooth_over_prod(n, k) }.first(30_019).last(20) |
||
say ("30,000th through 30,019th #{p}-smooth numbers: ", a.join(' ')) |
say ("30,000th through 30,019th #{p}-smooth numbers: ", a.join(' ')) |
||
}</ |
}</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
<pre> |
<pre> |
||
Line 3,533: | Line 3,533: | ||
{{libheader|AttaSwift BigInt}} |
{{libheader|AttaSwift BigInt}} |
||
< |
<syntaxhighlight lang="swift">import BigInt |
||
import Foundation |
import Foundation |
||
Line 3,596: | Line 3,596: | ||
for n in 503...521 where n.isPrime { |
for n in 503...521 where n.isPrime { |
||
print("The 30,000...30,019 \(n)-smooth numbers are: \(smoothN(n: BigInt(n), count: 30_019).dropFirst(29999).prefix(20))") |
print("The 30,000...30,019 \(n)-smooth numbers are: \(smoothN(n: BigInt(n), count: 30_019).dropFirst(29999).prefix(20))") |
||
}</ |
}</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
Line 3,629: | Line 3,629: | ||
{{libheader|Wren-math}} |
{{libheader|Wren-math}} |
||
{{libheader|Wren-big}} |
{{libheader|Wren-big}} |
||
< |
<syntaxhighlight lang="ecmascript">import "/math" for Int |
||
import "/big" for BigInt, BigInts |
import "/big" for BigInt, BigInts |
||
Line 3,683: | Line 3,683: | ||
System.print(nSmooth.call(i, 30019)[29999..-1]) |
System.print(nSmooth.call(i, 30019)[29999..-1]) |
||
System.print() |
System.print() |
||
}</ |
}</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
Line 3,757: | Line 3,757: | ||
{{trans|Go}} |
{{trans|Go}} |
||
{{libheader|GMP}} GNU Multiple Precision Arithmetic Library and primes |
{{libheader|GMP}} GNU Multiple Precision Arithmetic Library and primes |
||
< |
<syntaxhighlight lang="zkl">var [const] BI=Import("zklBigNum"); // libGMP |
||
fcn nSmooth(n,sz){ // --> List of big ints |
fcn nSmooth(n,sz){ // --> List of big ints |
||
Line 3,779: | Line 3,779: | ||
} |
} |
||
ns |
ns |
||
}</ |
}</syntaxhighlight> |
||
< |
<syntaxhighlight lang="zkl">smallPrimes:=List(); |
||
p:=BI(1); while(p<29) { smallPrimes.append(p.nextPrime().toInt()) } |
p:=BI(1); while(p<29) { smallPrimes.append(p.nextPrime().toInt()) } |
||
Line 3,794: | Line 3,794: | ||
println("\nThe 30,000th to 30,019th %d-smooth numbers are:".fmt(p)); |
println("\nThe 30,000th to 30,019th %d-smooth numbers are:".fmt(p)); |
||
println(nSmooth(p,30019)[29999,*].concat(" ")); |
println(nSmooth(p,30019)[29999,*].concat(" ")); |
||
}</ |
}</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
<pre style="height:45ex"> |
<pre style="height:45ex"> |