Sequence: smallest number greater than previous term with exactly n divisors: Difference between revisions
Content added Content deleted
Drkameleon (talk | contribs) (Added Arturo implementation) |
Thundergnat (talk | contribs) m (syntax highlighting fixup automation) |
||
Line 22: | Line 22: | ||
{{trans|Python}} |
{{trans|Python}} |
||
< |
<syntaxhighlight lang="11l">F divisors(n) |
||
V divs = [1] |
V divs = [1] |
||
L(ii) 2 .< Int(n ^ 0.5) + 3 |
L(ii) 2 .< Int(n ^ 0.5) + 3 |
||
Line 49: | Line 49: | ||
L(item) sequence(15) |
L(item) sequence(15) |
||
print(item)</ |
print(item)</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
Line 72: | Line 72: | ||
=={{header|Action!}}== |
=={{header|Action!}}== |
||
Calculations on a real Atari 8-bit computer take quite long time. It is recommended to use an emulator capable with increasing speed of Atari CPU. |
Calculations on a real Atari 8-bit computer take quite long time. It is recommended to use an emulator capable with increasing speed of Atari CPU. |
||
< |
<syntaxhighlight lang="action!">CARD FUNC CountDivisors(CARD a) |
||
CARD i,count |
CARD i,count |
||
Line 105: | Line 105: | ||
PrintC(a) |
PrintC(a) |
||
OD |
OD |
||
RETURN</ |
RETURN</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
[https://gitlab.com/amarok8bit/action-rosetta-code/-/raw/master/images/Sequence_smallest_number_greater_than_previous_term_with_exactly_n_divisors.png Screenshot from Atari 8-bit computer] |
[https://gitlab.com/amarok8bit/action-rosetta-code/-/raw/master/images/Sequence_smallest_number_greater_than_previous_term_with_exactly_n_divisors.png Screenshot from Atari 8-bit computer] |
||
Line 114: | Line 114: | ||
=={{header|Ada}}== |
=={{header|Ada}}== |
||
{{trans|Go}} |
{{trans|Go}} |
||
< |
<syntaxhighlight lang="ada">with Ada.Text_IO; |
||
procedure Show_Sequence is |
procedure Show_Sequence is |
||
Line 153: | Line 153: | ||
begin |
begin |
||
Show (15); |
Show (15); |
||
end Show_Sequence;</ |
end Show_Sequence;</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
Line 161: | Line 161: | ||
=={{header|ALGOL 68}}== |
=={{header|ALGOL 68}}== |
||
{{trans|Go}} with a small optimisation. |
{{trans|Go}} with a small optimisation. |
||
< |
<syntaxhighlight lang="algol68">BEGIN |
||
PROC count divisors = ( INT n )INT: |
PROC count divisors = ( INT n )INT: |
||
Line 183: | Line 183: | ||
OD |
OD |
||
END</ |
END</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
<pre> |
<pre> |
||
Line 191: | Line 191: | ||
=={{header|ALGOL W}}== |
=={{header|ALGOL W}}== |
||
{{Trans|Go}}...via Algol 68 and with a small optimisation. |
{{Trans|Go}}...via Algol 68 and with a small optimisation. |
||
< |
<syntaxhighlight lang="pascal">begin |
||
integer max, next, i; |
integer max, next, i; |
||
Line 219: | Line 219: | ||
end; |
end; |
||
write() |
write() |
||
end.</ |
end.</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
<pre> |
<pre> |
||
Line 227: | Line 227: | ||
=={{header|Arturo}}== |
=={{header|Arturo}}== |
||
< |
<syntaxhighlight lang="rebol">i: new 0 |
||
next: new 1 |
next: new 1 |
||
MAX: 15 |
MAX: 15 |
||
Line 237: | Line 237: | ||
inc 'i |
inc 'i |
||
] |
] |
||
print ""</ |
print ""</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
Line 245: | Line 245: | ||
=={{header|AutoHotkey}}== |
=={{header|AutoHotkey}}== |
||
{{trans|Go}} |
{{trans|Go}} |
||
< |
<syntaxhighlight lang="autohotkey">MAX := 15 |
||
next := 1, i := 1 |
next := 1, i := 1 |
||
while (next <= MAX) |
while (next <= MAX) |
||
Line 258: | Line 258: | ||
count += (A_Index = n/A_Index) ? 1 : 2 |
count += (A_Index = n/A_Index) ? 1 : 2 |
||
return count |
return count |
||
}</ |
}</syntaxhighlight> |
||
Outputs:<pre>The first 15 terms of the sequence are: |
Outputs:<pre>The first 15 terms of the sequence are: |
||
1, 2, 4, 6, 16, 18, 64, 66, 100, 112, 1024, 1035, 4096, 4288, 4624</pre> |
1, 2, 4, 6, 16, 18, 64, 66, 100, 112, 1024, 1035, 4096, 4288, 4624</pre> |
||
=={{header|AWK}}== |
=={{header|AWK}}== |
||
<syntaxhighlight lang="awk"> |
|||
<lang AWK> |
|||
# syntax: GAWK -f SEQUENCE_SMALLEST_NUMBER_GREATER_THAN_PREVIOUS_TERM_WITH_EXACTLY_N_DIVISORS.AWK |
# syntax: GAWK -f SEQUENCE_SMALLEST_NUMBER_GREATER_THAN_PREVIOUS_TERM_WITH_EXACTLY_N_DIVISORS.AWK |
||
# converted from Kotlin |
# converted from Kotlin |
||
Line 287: | Line 287: | ||
return(count) |
return(count) |
||
} |
} |
||
</syntaxhighlight> |
|||
</lang> |
|||
{{out}} |
{{out}} |
||
<pre> |
<pre> |
||
Line 295: | Line 295: | ||
=={{header|C}}== |
=={{header|C}}== |
||
{{trans|Go}} |
{{trans|Go}} |
||
< |
<syntaxhighlight lang="c">#include <stdio.h> |
||
#define MAX 15 |
#define MAX 15 |
||
Line 323: | Line 323: | ||
printf("\n"); |
printf("\n"); |
||
return 0; |
return 0; |
||
}</ |
}</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
Line 333: | Line 333: | ||
=={{header|C++}}== |
=={{header|C++}}== |
||
{{trans|C}} |
{{trans|C}} |
||
< |
<syntaxhighlight lang="cpp">#include <iostream> |
||
#define MAX 15 |
#define MAX 15 |
||
Line 362: | Line 362: | ||
cout << endl; |
cout << endl; |
||
return 0; |
return 0; |
||
}</ |
}</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
Line 371: | Line 371: | ||
===Alternative=== |
===Alternative=== |
||
{{Trans|Pascal}} |
{{Trans|Pascal}} |
||
More terms and quicker than the straightforward C version above. [https://tio.run/##bVJNb9NAFLz7V0yLGu1ihzopJ38EIbgiJMSBG3J3N84KZ@1417QI5a8T3tuQNqm42W/emxnPWA3DvFXqcHhlneombVApH7TtV8nZZDP2jibJ5K1r4Zqt8UOjDGizKI5omSSqdz7AuoBP77@hxt2yTJBMztvWGR2B1oSP9qfVZvQfXBAXmJP4nQAXM800GXYZ9BfjM4zG02RBvHjY2M5AXAmHGRaSjuGwWjHKa2laYv@8JjReQ0tUddTBjmgcbqFL2DWI44a1auQMshbhOcsAuj@N0pqZSzqssSuJ47Zmgv1J5IzleIpomM74nBc1vyz5aTRhGh1RXZFjvIuLVUWPxVFjnyQcwLaxTrCni1hsBvcYMlCWFCNrDSPN1@L668ZgbUfq4UajccHOCaG6MHSTRzOaAtcZ9xMdNlPoqUT6HB9Mo399V12vfhSF6x@EpGQ4pMcQE48xxI/ivMRRmZAXjVoqoj5eseuTLTJDsvYplsiRpry2wluJ2QziBRNhkWop5b8jRENiwTkxjHnsfc7u9rCx8acqCKauTx965mPryYmgVyn0NDbB9q7S/XTfmZX4TwpE74N8o/qJPEn6iRZ5nksi3R8Of9S6a1p/mH@@@ws Try It Online!]< |
More terms and quicker than the straightforward C version above. [https://tio.run/##bVJNb9NAFLz7V0yLGu1ihzopJ38EIbgiJMSBG3J3N84KZ@1417QI5a8T3tuQNqm42W/emxnPWA3DvFXqcHhlneombVApH7TtV8nZZDP2jibJ5K1r4Zqt8UOjDGizKI5omSSqdz7AuoBP77@hxt2yTJBMztvWGR2B1oSP9qfVZvQfXBAXmJP4nQAXM800GXYZ9BfjM4zG02RBvHjY2M5AXAmHGRaSjuGwWjHKa2laYv@8JjReQ0tUddTBjmgcbqFL2DWI44a1auQMshbhOcsAuj@N0pqZSzqssSuJ47Zmgv1J5IzleIpomM74nBc1vyz5aTRhGh1RXZFjvIuLVUWPxVFjnyQcwLaxTrCni1hsBvcYMlCWFCNrDSPN1@L668ZgbUfq4UajccHOCaG6MHSTRzOaAtcZ9xMdNlPoqUT6HB9Mo399V12vfhSF6x@EpGQ4pMcQE48xxI/ivMRRmZAXjVoqoj5eseuTLTJDsvYplsiRpry2wluJ2QziBRNhkWop5b8jRENiwTkxjHnsfc7u9rCx8acqCKauTx965mPryYmgVyn0NDbB9q7S/XTfmZX4TwpE74N8o/qJPEn6iRZ5nksi3R8Of9S6a1p/mH@@@ws Try It Online!]<syntaxhighlight lang="cpp">#include <cstdio> |
||
#include <chrono> |
#include <chrono> |
||
Line 392: | Line 392: | ||
i = (1 << (nxt - 1)) - 1; } i++; } while (nxt <= MAX); |
i = (1 << (nxt - 1)) - 1; } i++; } while (nxt <= MAX); |
||
printf("%d ms", (int)(duration<double>(steady_clock::now() - st).count() * 1000)); |
printf("%d ms", (int)(duration<double>(steady_clock::now() - st).count() * 1000)); |
||
}</ |
}</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
<pre>The first 32 anti-primes plus are: 1 2 4 6 16 18 64 66 100 112 1024 1035 4096 4288 4624 4632 65536 65572 262144 262192 263169 269312 4194304 4194306 4477456 4493312 4498641 4498752 268435456 268437200 1073741824 1073741830 223 ms</pre> |
<pre>The first 32 anti-primes plus are: 1 2 4 6 16 18 64 66 100 112 1024 1035 4096 4288 4624 4632 65536 65572 262144 262192 263169 269312 4194304 4194306 4477456 4493312 4498641 4498752 268435456 268437200 1073741824 1073741830 223 ms</pre> |
||
Line 400: | Line 400: | ||
{{trans|Go}} |
{{trans|Go}} |
||
< |
<syntaxhighlight lang="dyalect">func countDivisors(n) { |
||
var count = 0 |
var count = 0 |
||
var i = 1 |
var i = 1 |
||
Line 427: | Line 427: | ||
} |
} |
||
print()</ |
print()</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
Line 436: | Line 436: | ||
=={{header|F_Sharp|F#}}== |
=={{header|F_Sharp|F#}}== |
||
===First 28 are easy with a Naive implementation=== |
===First 28 are easy with a Naive implementation=== |
||
< |
<syntaxhighlight lang="fsharp"> |
||
// Nigel Galloway: November 19th., 2017 |
// Nigel Galloway: November 19th., 2017 |
||
let fN g=[1..(float>>sqrt>>int)g]|>List.fold(fun Σ n->if g%n>0 then Σ else if g/n=n then Σ+1 else Σ+2) 0 |
let fN g=[1..(float>>sqrt>>int)g]|>List.fold(fun Σ n->if g%n>0 then Σ else if g/n=n then Σ+1 else Σ+2) 0 |
||
Line 442: | Line 442: | ||
A069654 |> Seq.take 28|>Seq.iter(printf "%d "); printfn "" |
A069654 |> Seq.take 28|>Seq.iter(printf "%d "); printfn "" |
||
</syntaxhighlight> |
|||
</lang> |
|||
{{out}} |
{{out}} |
||
<pre> |
<pre> |
||
Line 448: | Line 448: | ||
</pre> |
</pre> |
||
=={{header|Factor}}== |
=={{header|Factor}}== |
||
< |
<syntaxhighlight lang="factor">USING: io kernel math math.primes.factors prettyprint sequences ; |
||
: next ( n num -- n' num' ) |
: next ( n num -- n' num' ) |
||
Line 456: | Line 456: | ||
[ 2 1 ] dip [ [ next ] keep ] replicate 2nip ; |
[ 2 1 ] dip [ [ next ] keep ] replicate 2nip ; |
||
"The first 15 terms of the sequence are:" print 15 A069654 .</ |
"The first 15 terms of the sequence are:" print 15 A069654 .</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
<pre> |
<pre> |
||
Line 464: | Line 464: | ||
=={{header|FreeBASIC}}== |
=={{header|FreeBASIC}}== |
||
< |
<syntaxhighlight lang="freebasic">#define UPTO 15 |
||
function divisors(byval n as ulongint) as uinteger |
function divisors(byval n as ulongint) as uinteger |
||
Line 489: | Line 489: | ||
wend |
wend |
||
print |
print |
||
end</ |
end</syntaxhighlight> |
||
{{out}}<pre> 1 2 4 6 16 18 64 66 100 112 1024 1035 4096 4288 4624</pre> |
{{out}}<pre> 1 2 4 6 16 18 64 66 100 112 1024 1035 4096 4288 4624</pre> |
||
=={{header|Go}}== |
=={{header|Go}}== |
||
< |
<syntaxhighlight lang="go">package main |
||
import "fmt" |
import "fmt" |
||
Line 521: | Line 521: | ||
} |
} |
||
fmt.Println() |
fmt.Println() |
||
}</ |
}</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
Line 529: | Line 529: | ||
</pre> |
</pre> |
||
=={{header|Haskell}}== |
=={{header|Haskell}}== |
||
< |
<syntaxhighlight lang="haskell">import Text.Printf (printf) |
||
sequence_A069654 :: [(Int,Int)] |
sequence_A069654 :: [(Int,Int)] |
||
Line 540: | Line 540: | ||
main :: IO () |
main :: IO () |
||
main = mapM_ (uncurry $ printf "a(%2d)=%5d\n") $ take 15 sequence_A069654</ |
main = mapM_ (uncurry $ printf "a(%2d)=%5d\n") $ take 15 sequence_A069654</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
<pre>a( 1)= 1 |
<pre>a( 1)= 1 |
||
Line 560: | Line 560: | ||
=={{header|J}}== |
=={{header|J}}== |
||
<syntaxhighlight lang="j"> |
|||
<lang j> |
|||
sieve=: 3 :0 |
sieve=: 3 :0 |
||
NB. sieve y returns a vector of y boxes. |
NB. sieve y returns a vector of y boxes. |
||
Line 578: | Line 578: | ||
(</.~ {."1) (,. i.@:#)tally |
(</.~ {."1) (,. i.@:#)tally |
||
) |
) |
||
</syntaxhighlight> |
|||
</lang> |
|||
<pre> |
<pre> |
||
Line 706: | Line 706: | ||
=={{header|Java}}== |
=={{header|Java}}== |
||
{{trans|C}} |
{{trans|C}} |
||
< |
<syntaxhighlight lang="java">public class AntiPrimesPlus { |
||
static int count_divisors(int n) { |
static int count_divisors(int n) { |
||
Line 732: | Line 732: | ||
System.out.println(); |
System.out.println(); |
||
} |
} |
||
}</ |
}</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
Line 744: | Line 744: | ||
{{works with|jq}} |
{{works with|jq}} |
||
'''Works with gojq, the Go implementation of jq''' |
'''Works with gojq, the Go implementation of jq''' |
||
<syntaxhighlight lang="jq"> |
|||
<lang jq> |
|||
# The number of prime factors (as in prime factorization) |
# The number of prime factors (as in prime factorization) |
||
def numfactors: |
def numfactors: |
||
Line 764: | Line 764: | ||
"First 15 terms of OEIS sequence A069654: ", |
"First 15 terms of OEIS sequence A069654: ", |
||
[limit(15; A06954)]</ |
[limit(15; A06954)]</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
<pre> |
<pre> |
||
Line 774: | Line 774: | ||
=={{header|Julia}}== |
=={{header|Julia}}== |
||
{{trans|Perl}} |
{{trans|Perl}} |
||
< |
<syntaxhighlight lang="julia">using Primes |
||
function numfactors(n) |
function numfactors(n) |
||
Line 800: | Line 800: | ||
A06954(15) |
A06954(15) |
||
</ |
</syntaxhighlight>{{out}} |
||
<pre> |
<pre> |
||
First 15 terms of OEIS sequence A069654: |
First 15 terms of OEIS sequence A069654: |
||
Line 808: | Line 808: | ||
=={{header|Kotlin}}== |
=={{header|Kotlin}}== |
||
{{trans|Go}} |
{{trans|Go}} |
||
< |
<syntaxhighlight lang="scala">// Version 1.3.21 |
||
const val MAX = 15 |
const val MAX = 15 |
||
Line 836: | Line 836: | ||
} |
} |
||
println() |
println() |
||
}</ |
}</syntaxhighlight> |
||
{{output}} |
{{output}} |
||
Line 845: | Line 845: | ||
=={{header|Mathematica}} / {{header|Wolfram Language}}== |
=={{header|Mathematica}} / {{header|Wolfram Language}}== |
||
< |
<syntaxhighlight lang="mathematica">res = {#, DivisorSigma[0, #]} & /@ Range[100000]; |
||
highest = 0; |
highest = 0; |
||
filter = {}; |
filter = {}; |
||
Line 856: | Line 856: | ||
{r, res} |
{r, res} |
||
] |
] |
||
Take[filter, 15]</ |
Take[filter, 15]</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
<pre>{1, 2, 4, 6, 16, 18, 64, 66, 100, 112, 1024, 1035, 4096, 4288, 4624}</pre> |
<pre>{1, 2, 4, 6, 16, 18, 64, 66, 100, 112, 1024, 1035, 4096, 4288, 4624}</pre> |
||
=={{header|Nim}}== |
=={{header|Nim}}== |
||
< |
<syntaxhighlight lang="nim">import strformat |
||
const MAX = 15 |
const MAX = 15 |
||
Line 884: | Line 884: | ||
inc next |
inc next |
||
inc i |
inc i |
||
write(stdout, "\n")</ |
write(stdout, "\n")</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
<pre> |
<pre> |
||
Line 897: | Line 897: | ||
I think of next = 33 aka 11*3 with the solution 1031^2 * 2^10=1,088,472,064 with a big distance to next= 32 => 1073741830.<BR> |
I think of next = 33 aka 11*3 with the solution 1031^2 * 2^10=1,088,472,064 with a big distance to next= 32 => 1073741830.<BR> |
||
[https://tio.run/##fVRdb9owFH3Pr7gPk0hYWCG0e2hKJcbHhtQCapm0vSCZxAGvwaa2U1ZV/PWxazsQ2k7jIeR@n3t8HLH4RRPd2BCVkLyRbZL9fiPFUpI1dLlmU8nWVE3zQsXey4fRsD8YwnDa23kALx9uJ/0B9Gm@WbEdRgc39wMX6E6ns5/TAfQm4/vJzWAHZ2eQ2jyTNu6PhjuvUFRhsnpWhWa5CtdEr2IvEVxpdN92f0CnHcUeeFnBE80EhyXVffbEUipVj2ufX35nXLejoPyPPZzyOgcWz5Aak/ElcMA0AUwr2JitICOJFlKZMvJAMN6BKLpomr95q96eR/WLeRtWRIHf@tgK6n5kn218Ysq564yDvCciEbIxw8dC6BBX1eSOqlBSpeESDvgWdMk4ZqK7yDHQgZZZEJAeUwzGE8VoKbohkmjYMr0ShbatFVKAqdsVyymMhfYnaerzIIBUoPtL2RpwDezC4f7bne2OP8YT340MjIPy9DA1k2INXGwB2RU8fwaRpsCL9cJs5TayoNrxcbKvHqVvAsFVh78bjtzfCoQVVmQYDoISSAaWkQ40Qa@oK6mKAQ7EmZnNuHRKuqFEl4bb5pRgu5YLHXMsB2b628D/8QEUKPncgby6riBUDB7PtixxZB5gmabRCclIMe6cE2znxAYiMzosFYgJoyHaOKpVEVKpw73VUTnlmTmhzZqoqRHXn8/NCBZy@luHuBkK/r3WtpJpmnO/Nluh4plEKLUQb1dYA4LLNiwQxIM3HIiklzULf9bE8V@pnrHkoSeK46yDZsHMPBonJ@RgmMib28pKwnBhl9NxPf6pAwvaZ4ixFpyegak4Oiy3tseBT9vMCdnaPnSuYS2URkcEwdzWN1qBKVAiL7S7UiUsG4VrOA@gO@6D//ZzY2abb0NQYba4LA2gVjkc@zdaMX5UmJmDsCVdU65pCiTTVG6JTNV77Th@nP7GDgieUlyd4Mmr//pkGrMmMrVWhivs@cnb7/8kWU6Wat@YRH8B Try it online!] |
[https://tio.run/##fVRdb9owFH3Pr7gPk0hYWCG0e2hKJcbHhtQCapm0vSCZxAGvwaa2U1ZV/PWxazsQ2k7jIeR@n3t8HLH4RRPd2BCVkLyRbZL9fiPFUpI1dLlmU8nWVE3zQsXey4fRsD8YwnDa23kALx9uJ/0B9Gm@WbEdRgc39wMX6E6ns5/TAfQm4/vJzWAHZ2eQ2jyTNu6PhjuvUFRhsnpWhWa5CtdEr2IvEVxpdN92f0CnHcUeeFnBE80EhyXVffbEUipVj2ufX35nXLejoPyPPZzyOgcWz5Aak/ElcMA0AUwr2JitICOJFlKZMvJAMN6BKLpomr95q96eR/WLeRtWRIHf@tgK6n5kn218Ysq564yDvCciEbIxw8dC6BBX1eSOqlBSpeESDvgWdMk4ZqK7yDHQgZZZEJAeUwzGE8VoKbohkmjYMr0ShbatFVKAqdsVyymMhfYnaerzIIBUoPtL2RpwDezC4f7bne2OP8YT340MjIPy9DA1k2INXGwB2RU8fwaRpsCL9cJs5TayoNrxcbKvHqVvAsFVh78bjtzfCoQVVmQYDoISSAaWkQ40Qa@oK6mKAQ7EmZnNuHRKuqFEl4bb5pRgu5YLHXMsB2b628D/8QEUKPncgby6riBUDB7PtixxZB5gmabRCclIMe6cE2znxAYiMzosFYgJoyHaOKpVEVKpw73VUTnlmTmhzZqoqRHXn8/NCBZy@luHuBkK/r3WtpJpmnO/Nluh4plEKLUQb1dYA4LLNiwQxIM3HIiklzULf9bE8V@pnrHkoSeK46yDZsHMPBonJ@RgmMib28pKwnBhl9NxPf6pAwvaZ4ixFpyegak4Oiy3tseBT9vMCdnaPnSuYS2URkcEwdzWN1qBKVAiL7S7UiUsG4VrOA@gO@6D//ZzY2abb0NQYba4LA2gVjkc@zdaMX5UmJmDsCVdU65pCiTTVG6JTNV77Th@nP7GDgieUlyd4Mmr//pkGrMmMrVWhivs@cnb7/8kWU6Wat@YRH8B Try it online!] |
||
< |
<syntaxhighlight lang="pascal">program AntiPrimesPlus; |
||
{$IFDEF FPC} |
{$IFDEF FPC} |
||
{$MODE Delphi} |
{$MODE Delphi} |
||
Line 967: | Line 967: | ||
writeln; |
writeln; |
||
writeln(GetTickCount64-T0,' ms'); |
writeln(GetTickCount64-T0,' ms'); |
||
end.</ |
end.</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
<pre>The first 32 anti-primes plus are: |
<pre>The first 32 anti-primes plus are: |
||
Line 975: | Line 975: | ||
=={{header|Perl}}== |
=={{header|Perl}}== |
||
{{libheader|ntheory}} |
{{libheader|ntheory}} |
||
< |
<syntaxhighlight lang="perl">use strict; |
||
use warnings; |
use warnings; |
||
use ntheory 'divisors'; |
use ntheory 'divisors'; |
||
Line 986: | Line 986: | ||
print("$l "), $m = $l, last if $n == divisors($l); |
print("$l "), $m = $l, last if $n == divisors($l); |
||
} |
} |
||
}</ |
}</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
Line 994: | Line 994: | ||
=={{header|Phix}}== |
=={{header|Phix}}== |
||
Uses the optimisation trick from pascal, of n:=power(2,next-1) when next is a prime>4. |
Uses the optimisation trick from pascal, of n:=power(2,next-1) when next is a prime>4. |
||
<!--< |
<!--<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;">constant</span> <span style="color: #000000;">limit</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">15</span> |
<span style="color: #008080;">constant</span> <span style="color: #000000;">limit</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">15</span> |
||
Line 1,012: | Line 1,012: | ||
<span style="color: #008080;">end</span> <span style="color: #008080;">while</span> |
<span style="color: #008080;">end</span> <span style="color: #008080;">while</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;">"The first %d terms are: %v\n"</span><span style="color: #0000FF;">,{</span><span style="color: #000000;">limit</span><span style="color: #0000FF;">,</span><span style="color: #000000;">res</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;">"The first %d terms are: %v\n"</span><span style="color: #0000FF;">,{</span><span style="color: #000000;">limit</span><span style="color: #0000FF;">,</span><span style="color: #000000;">res</span><span style="color: #0000FF;">})</span> |
||
<!--</ |
<!--</syntaxhighlight>--> |
||
{{out}} |
{{out}} |
||
<pre> |
<pre> |
||
Line 1,032: | Line 1,032: | ||
=={{header|PL/M}}== |
=={{header|PL/M}}== |
||
{{Trans|Go}} via Algol 68 |
{{Trans|Go}} via Algol 68 |
||
< |
<syntaxhighlight lang="pli">100H: /* FIND THE SMALLEST NUMBER > THE PREVIOUS ONE WITH EXACTLY N DIVISORS */ |
||
/* CP/M BDOS SYSTEM CALL */ |
/* CP/M BDOS SYSTEM CALL */ |
||
Line 1,082: | Line 1,082: | ||
END; |
END; |
||
EOF</ |
EOF</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
<pre> |
<pre> |
||
Line 1,097: | Line 1,097: | ||
Note the use of text in column 81 onwards to hide the PL/I specifics from the PL/M compiler. |
Note the use of text in column 81 onwards to hide the PL/I specifics from the PL/M compiler. |
||
{{Trans|PL/M}} |
{{Trans|PL/M}} |
||
< |
<syntaxhighlight lang="pli"> /* FIND THE SMALLEST NUMBER > THE PREVIOUS ONE WITH EXACTLY N DIVISORS */ |
||
sequence_100H: procedure options (main); |
sequence_100H: procedure options (main); |
||
Line 1,177: | Line 1,177: | ||
END; |
END; |
||
EOF: end sequence_100H;</ |
EOF: end sequence_100H;</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
<pre> |
<pre> |
||
Line 1,184: | Line 1,184: | ||
=={{header|Python}}== |
=={{header|Python}}== |
||
<syntaxhighlight lang="python"> |
|||
<lang Python> |
|||
def divisors(n): |
def divisors(n): |
||
divs = [1] |
divs = [1] |
||
Line 1,215: | Line 1,215: | ||
for item in sequence(15): |
for item in sequence(15): |
||
print(item) |
print(item) |
||
</syntaxhighlight> |
|||
</lang> |
|||
<b>Output:</b> |
<b>Output:</b> |
||
<syntaxhighlight lang="python"> |
|||
<lang Python> |
|||
1 |
1 |
||
2 |
2 |
||
Line 1,233: | Line 1,233: | ||
4288 |
4288 |
||
4624 |
4624 |
||
</syntaxhighlight> |
|||
</lang> |
|||
=={{header|Quackery}}== |
=={{header|Quackery}}== |
||
Line 1,239: | Line 1,239: | ||
<code>factors</code> is defined at [[Factors of an integer#Quackery]]. |
<code>factors</code> is defined at [[Factors of an integer#Quackery]]. |
||
< |
<syntaxhighlight lang="quackery"> [ stack ] is terms ( --> s ) |
||
[ temp put |
[ temp put |
||
Line 1,258: | Line 1,258: | ||
dip 2drop ] is task ( n --> [ ) |
dip 2drop ] is task ( n --> [ ) |
||
15 task echo</ |
15 task echo</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
Line 1,265: | Line 1,265: | ||
=={{header|R}}== |
=={{header|R}}== |
||
< |
<syntaxhighlight lang="rsplus">#Need to add 1 to account for skipping n. Not the most efficient way to count divisors, but quite clear. |
||
divisorCount <- function(n) length(Filter(function(x) n %% x == 0, seq_len(n %/% 2))) + 1 |
divisorCount <- function(n) length(Filter(function(x) n %% x == 0, seq_len(n %/% 2))) + 1 |
||
A06954 <- function(terms) |
A06954 <- function(terms) |
||
Line 1,278: | Line 1,278: | ||
out |
out |
||
} |
} |
||
print(A06954(15))</ |
print(A06954(15))</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
<pre>[1] 1 2 4 6 16 18 64 66 100 112 1024 1035 4096 4288 4624</pre> |
<pre>[1] 1 2 4 6 16 18 64 66 100 112 1024 1035 4096 4288 4624</pre> |
||
Line 1,286: | Line 1,286: | ||
{{works with|Rakudo|2019.03}} |
{{works with|Rakudo|2019.03}} |
||
<lang |
<syntaxhighlight lang="raku" line>sub div-count (\x) { |
||
return 2 if x.is-prime; |
return 2 if x.is-prime; |
||
+flat (1 .. x.sqrt.floor).map: -> \d { |
+flat (1 .. x.sqrt.floor).map: -> \d { |
||
Line 1,298: | Line 1,298: | ||
put "First $limit terms of OEIS:A069654"; |
put "First $limit terms of OEIS:A069654"; |
||
put (1..$limit).map: -> $n { my $ = $m = first { $n == .&div-count }, $m..Inf }; |
put (1..$limit).map: -> $n { my $ = $m = first { $n == .&div-count }, $m..Inf }; |
||
</syntaxhighlight> |
|||
</lang> |
|||
{{out}} |
{{out}} |
||
<pre> |
<pre> |
||
Line 1,311: | Line 1,311: | ||
Optimization was included when examining ''even'' or ''odd'' index numbers (determine how much to increment the '''do''' loop). |
Optimization was included when examining ''even'' or ''odd'' index numbers (determine how much to increment the '''do''' loop). |
||
< |
<syntaxhighlight lang="rexx">/*REXX program finds and displays N numbers of the "anti─primes plus" sequence. */ |
||
parse arg N . /*obtain optional argument from the CL.*/ |
parse arg N . /*obtain optional argument from the CL.*/ |
||
if N=='' | N=="," then N= 15 /*Not specified? Then use the default.*/ |
if N=='' | N=="," then N= 15 /*Not specified? Then use the default.*/ |
||
Line 1,344: | Line 1,344: | ||
else if k*k>x then leave /*only divide up to the √ x */ |
else if k*k>x then leave /*only divide up to the √ x */ |
||
end /*k*/ /* [↑] this form of DO loop is faster.*/ |
end /*k*/ /* [↑] this form of DO loop is faster.*/ |
||
return # + 1 /*bump "proper divisors" to "divisors".*/</ |
return # + 1 /*bump "proper divisors" to "divisors".*/</syntaxhighlight> |
||
{{out|output|text= when using the default input:}} |
{{out|output|text= when using the default input:}} |
||
<pre> |
<pre> |
||
Line 1,366: | Line 1,366: | ||
=={{header|Ring}}== |
=={{header|Ring}}== |
||
< |
<syntaxhighlight lang="ring"> |
||
# Project : ANti-primes |
# Project : ANti-primes |
||
Line 1,404: | Line 1,404: | ||
next |
next |
||
return ansum |
return ansum |
||
</syntaxhighlight> |
|||
</lang> |
|||
{{out}} |
{{out}} |
||
<pre> |
<pre> |
||
Line 1,418: | Line 1,418: | ||
=={{header|Ruby}}== |
=={{header|Ruby}}== |
||
< |
<syntaxhighlight lang="ruby">require 'prime' |
||
def num_divisors(n) |
def num_divisors(n) |
||
Line 1,435: | Line 1,435: | ||
p seq.take(15) |
p seq.take(15) |
||
</syntaxhighlight> |
|||
</lang> |
|||
{{out}} |
{{out}} |
||
<pre>[1, 2, 4, 6, 16, 18, 64, 66, 100, 112, 1024, 1035, 4096, 4288, 4624] |
<pre>[1, 2, 4, 6, 16, 18, 64, 66, 100, 112, 1024, 1035, 4096, 4288, 4624] |
||
Line 1,441: | Line 1,441: | ||
=={{header|Sidef}}== |
=={{header|Sidef}}== |
||
< |
<syntaxhighlight lang="ruby">func n_divisors(n, from=1) { |
||
from..Inf -> first_by { .sigma0 == n } |
from..Inf -> first_by { .sigma0 == n } |
||
} |
} |
||
Line 1,447: | Line 1,447: | ||
with (1) { |from| |
with (1) { |from| |
||
say 15.of { from = n_divisors(_+1, from) } |
say 15.of { from = n_divisors(_+1, from) } |
||
}</ |
}</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
<pre> |
<pre> |
||
Line 1,455: | Line 1,455: | ||
=={{header|Swift}}== |
=={{header|Swift}}== |
||
Includes an optimization borrowed from the Pascal example above. |
Includes an optimization borrowed from the Pascal example above. |
||
< |
<syntaxhighlight lang="swift">// See https://en.wikipedia.org/wiki/Divisor_function |
||
func divisorCount(number: Int) -> Int { |
func divisorCount(number: Int) -> Int { |
||
var n = number |
var n = number |
||
Line 1,495: | Line 1,495: | ||
n += 1 |
n += 1 |
||
} |
} |
||
print()</ |
print()</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
Line 1,505: | Line 1,505: | ||
{{trans|Phix}} |
{{trans|Phix}} |
||
{{libheader|Wren-math}} |
{{libheader|Wren-math}} |
||
< |
<syntaxhighlight lang="ecmascript">import "/math" for Int |
||
var limit = 24 |
var limit = 24 |
||
Line 1,521: | Line 1,521: | ||
} |
} |
||
System.print("The first %(limit) terms are:") |
System.print("The first %(limit) terms are:") |
||
System.print(res)</ |
System.print(res)</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
Line 1,530: | Line 1,530: | ||
=={{header|XPL0}}== |
=={{header|XPL0}}== |
||
< |
<syntaxhighlight lang="xpl0">func Divs(N); \Count divisors of N |
||
int N, D, C; |
int N, D, C; |
||
[C:= 0; |
[C:= 0; |
||
Line 1,551: | Line 1,551: | ||
An:= An+1; |
An:= An+1; |
||
]; |
]; |
||
]</ |
]</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
Line 1,559: | Line 1,559: | ||
=={{header|zkl}}== |
=={{header|zkl}}== |
||
< |
<syntaxhighlight lang="zkl">fcn countDivisors(n) |
||
{ [1..(n).toFloat().sqrt()] .reduce('wrap(s,i){ s + (if(0==n%i) 1 + (i!=n/i)) },0) }</ |
{ [1..(n).toFloat().sqrt()] .reduce('wrap(s,i){ s + (if(0==n%i) 1 + (i!=n/i)) },0) }</syntaxhighlight> |
||
< |
<syntaxhighlight lang="zkl">n:=15; |
||
println("The first %d anti-primes plus are:".fmt(n)); |
println("The first %d anti-primes plus are:".fmt(n)); |
||
(1).walker(*).tweak( |
(1).walker(*).tweak( |
||
fcn(n,rn){ if(rn.value==countDivisors(n)){ rn.inc(); n } else Void.Skip }.fp1(Ref(1))) |
fcn(n,rn){ if(rn.value==countDivisors(n)){ rn.inc(); n } else Void.Skip }.fp1(Ref(1))) |
||
.walk(n).concat(" ").println();</ |
.walk(n).concat(" ").println();</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
<pre> |
<pre> |