Data commit

This commit is contained in:
Ingy döt Net 2023-07-01 11:58:00 -04:00
parent 7387c8f97b
commit cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions

View file

@ -0,0 +1,4 @@
---
category:
- Prime Numbers
from: http://rosettacode.org/wiki/Anti-primes

View file

@ -0,0 +1,14 @@
The [https://youtu.be/2JM2oImb9Qg anti-primes]
(or [https://en.wikipedia.org/wiki/Highly_composite_number highly composite numbers], sequence [https://oeis.org/A002182 A002182] in the [https://oeis.org/ OEIS])
are the natural numbers with more factors than any smaller than itself.
;Task:
Generate and show here, the first twenty anti-primes.
;Related tasks:
:*   [[Factors of an integer]]
:*   [[Sieve of Eratosthenes]]
<br><br>

View file

@ -0,0 +1,17 @@
V max_divisors = 0
V c = 0
V n = 1
L
V divisors = 1
L(i) 1 .. n I/ 2
I n % i == 0
divisors++
I divisors > max_divisors
max_divisors = divisors
print(n, end' )
c++
I c == 20
L.break
n++

View file

@ -0,0 +1,42 @@
puts: equ 9 ; MS-DOS print string syscall
amount: equ 20 ; Amount of antiprimes to find
cpu 8086
org 100h
xor si,si ; SI = current number
xor cx,cx ; CH = max # of factors, CL = # of antiprimes
cand: inc si
mov di,si ; DI = maximum factor to test
shr di,1
mov bp,1 ; BP = current candidate
xor bl,bl ; BL = factor count
.test: mov ax,si ; Test current candidate
xor dx,dx
div bp
test dx,dx ; Evenly divisible?
jnz .next
inc bx ; Then increment factors
.next: inc bp ; Next possible factor
cmp bp,si ; Are we there yet?
jbe .test ; If not, try next factor
cmp bl,ch ; Is it an antiprime?
jbe cand ; If not, next candidate
inc cx ; If so, increment the amount of antiprimes seen
mov ch,bl ; Update maximum amount of factors
mov bx,nbuf ; Convert current number to ASCII
mov ax,si
mov di,10
digit: xor dx,dx ; Extract a digit
div di
add dl,'0' ; Add ASCII 0
dec bx
mov [bx],dl ; Store it
test ax,ax ; Any more digits?
jnz digit ; If so, get next digit
mov dx,bx
mov ah,puts
int 21h ; Print using MS-DOS
cmp cl,amount ; Do we need any more antiprimes?
jb cand ; If so, find the next one
ret ; Otherwise, back to DOS
db '.....' ; Placeholder for decimal output
nbuf: db ' $'

View file

@ -0,0 +1,114 @@
/* ARM assembly AARCH64 Raspberry PI 3B */
/* program antiprime64.s */
/************************************/
/* Constantes */
/************************************/
.include "../includeConstantesARM64.inc"
.equ NMAXI, 20
.equ MAXLINE, 5
/*********************************/
/* Initialized data */
/*********************************/
.data
sMessResult: .asciz " @ "
szCarriageReturn: .asciz "\n"
/*********************************/
/* UnInitialized data */
/*********************************/
.bss
sZoneConv: .skip 24
/*********************************/
/* code section */
/*********************************/
.text
.global main
main: // entry of program
ldr x3,qNMaxi // load limit
mov x5,#0 // maxi
mov x6,#0 // result counter
mov x7,#0 // display counter
mov x4,#1 // number begin
1:
mov x0,x4 // number
bl decFactor // compute number factors
cmp x0,x5 // maxi ?
cinc x4,x4,le // no -> increment indice
//addle x4,x4,#1 // no -> increment indice
ble 1b // and loop
mov x5,x0
mov x0,x4
bl displayResult
add x7,x7,#1 // increment display counter
cmp x7,#MAXLINE // line maxi ?
blt 2f
mov x7,#0
ldr x0,qAdrszCarriageReturn
bl affichageMess // display message
2:
add x6,x6,#1 // increment result counter
add x4,x4,#1 // increment number
cmp x6,x3 // end ?
blt 1b
100: // standard end of the program
mov x0, #0 // return code
mov x8,EXIT
svc #0 // perform the system call
qAdrszCarriageReturn: .quad szCarriageReturn
qNMaxi: .quad NMAXI
/***************************************************/
/* display message number */
/***************************************************/
/* x0 contains number 1 */
/* x1 contains number 2 */
displayResult:
stp x1,lr,[sp,-16]! // save registers
ldr x1,qAdrsZoneConv
bl conversion10 // call décimal conversion
ldr x0,qAdrsMessResult
ldr x1,qAdrsZoneConv // insert conversion in message
bl strInsertAtCharInc
bl affichageMess // display message
ldp x1,lr,[sp],16 // restaur registers
ret
qAdrsMessResult: .quad sMessResult
qAdrsZoneConv: .quad sZoneConv
/***************************************************/
/* compute factors sum */
/***************************************************/
/* x0 contains the number */
decFactor:
stp x1,lr,[sp,-16]! // save registers
stp x2,x3,[sp,-16]! // save registers
stp x4,x5,[sp,-16]! // save registers
mov x5,#0 // init number factors
mov x4,x0 // save number
mov x1,#1 // start factor -> divisor
1:
mov x0,x4 // dividende
udiv x2,x0,x1
msub x3,x2,x1,x0
cmp x1,x2 // divisor > quotient ?
bgt 3f
cmp x3,#0 // remainder = 0 ?
bne 2f
add x5,x5,#1 // increment counter factors
cmp x1,x2 // divisor = quotient ?
beq 3f // yes -> end
add x5,x5,#1 // no -> increment counter factors
2:
add x1,x1,#1 // increment factor
b 1b // and loop
3:
mov x0,x5 // return counter
ldp x4,x5,[sp],16 // restaur registers
ldp x2,x3,[sp],16 // restaur registers
ldp x1,lr,[sp],16 // restaur registers
ret
/***************************************************/
/* ROUTINES INCLUDE */
/***************************************************/
.include "../includeARM64.inc"

View file

@ -0,0 +1,21 @@
BEGIN # find some anti-primes: numbers with more divisors than the #
# previous numbers #
INT max number := 10 000;
INT max divisors := 0;
# construct a table of the divisor counts #
[ 1 : max number ]INT ndc; FOR i FROM 1 TO UPB ndc DO ndc[ i ] := 1 OD;
FOR i FROM 2 TO UPB ndc DO
FOR j FROM i BY i TO UPB ndc DO ndc[ j ] +:= 1 OD
OD;
# show the numbers with more divisors than their predecessors #
INT a count := 0;
FOR i TO UPB ndc WHILE a count < 20 DO
INT divisor count = ndc[ i ];
IF divisor count > max divisors THEN
print( ( " ", whole( i, 0 ) ) );
max divisors := divisor count;
a count +:= 1
FI
OD;
print( ( newline ) )
END

View file

@ -0,0 +1,41 @@
begin
% find some anti-primes - numbers with more factors than the numbers %
% smaller than them %
% calculates the number of divisors of v %
integer procedure divisor_count( integer value v ) ; begin
integer total, n, p;
total := 1; n := v;
while not odd( n ) do begin
total := total + 1;
n := n div 2
end while_not_odd_n ;
p := 3;
while ( p * p ) <= n do begin
integer count;
count := 1;
while n rem p = 0 do begin
count := count + 1;
n := n div p
end while_n_rem_p_eq_0 ;
p := p + 2;
total := total * count
end while_p_x_p_le_n ;
if n > 1 then total := total * 2;
total
end divisor_count ;
begin
integer maxAntiPrime, antiPrimeCount, maxDivisors, n;
maxAntiPrime := 20;
n := maxDivisors := antiPrimeCount := 0;
while antiPrimeCount < maxAntiPrime do begin
integer divisors;
n := n + 1;
divisors := divisor_count( n );
if divisors > maxDivisors then begin
writeon( i_w := 1, s_w := 0, " ", n );
maxDivisors := divisors;
antiPrimeCount := antiPrimeCount + 1
end if_have_an_anti_prime
end while_antiPrimeCoiunt_lt_maxAntiPrime
end
end.

View file

@ -0,0 +1 @@
f{\()¨}

View file

@ -0,0 +1,112 @@
/* ARM assembly Raspberry PI or android with termux */
/* program antiprime.s */
/* REMARK 1 : this program use routines in a include file
see task Include a file language arm assembly
for the routine affichageMess conversion10
see at end of this program the instruction include */
/* for constantes see task include a file in arm assembly */
/************************************/
/* Constantes */
/************************************/
.include "../constantes.inc"
.equ NMAXI, 20
.equ MAXLINE, 5
/*********************************/
/* Initialized data */
/*********************************/
.data
sMessResult: .asciz " @ "
szCarriageReturn: .asciz "\n"
/*********************************/
/* UnInitialized data */
/*********************************/
.bss
sZoneConv: .skip 24
/*********************************/
/* code section */
/*********************************/
.text
.global main
main: @ entry of program
ldr r3,iNMaxi @ load limit
mov r5,#0 @ maxi
mov r6,#0 @ result counter
mov r7,#0 @ display counter
mov r4,#1 @ number begin
1:
mov r0,r4 @ number
bl decFactor @ compute number factors
cmp r0,r5 @ maxi ?
addle r4,r4,#1 @ no -> increment indice
ble 1b @ and loop
mov r5,r0
mov r0,r4
bl displayResult
add r7,r7,#1 @ increment display counter
cmp r7,#MAXLINE @ line maxi ?
blt 2f
mov r7,#0
ldr r0,iAdrszCarriageReturn
bl affichageMess @ display message
2:
add r6,r6,#1 @ increment result counter
add r4,r4,#1 @ increment number
cmp r6,r3 @ end ?
blt 1b
100: @ standard end of the program
mov r0, #0 @ return code
mov r7, #EXIT @ request to exit program
svc #0 @ perform the system call
iAdrszCarriageReturn: .int szCarriageReturn
iNMaxi: .int NMAXI
/***************************************************/
/* display message number */
/***************************************************/
/* r0 contains number 1 */
/* r1 contains number 2 */
displayResult:
push {r1,lr} @ save registers
ldr r1,iAdrsZoneConv
bl conversion10 @ call décimal conversion
ldr r0,iAdrsMessResult
ldr r1,iAdrsZoneConv @ insert conversion in message
bl strInsertAtCharInc
bl affichageMess @ display message
pop {r1,pc} @ restaur des registres
iAdrsMessResult: .int sMessResult
iAdrsZoneConv: .int sZoneConv
/***************************************************/
/* compute factors sum */
/***************************************************/
/* r0 contains the number */
decFactor:
push {r1-r5,lr} @ save registers
mov r5,#0 @ init number factors
mov r4,r0 @ save number
mov r1,#1 @ start factor -> divisor
1:
mov r0,r4 @ dividende
bl division
cmp r1,r2 @ divisor > quotient ?
bgt 3f
cmp r3,#0 @ remainder = 0 ?
bne 2f
add r5,r5,#1 @ increment counter factors
cmp r1,r2 @ divisor = quotient ?
beq 3f @ yes -> end
add r5,r5,#1 @ no -> increment counter factors
2:
add r1,r1,#1 @ increment factor
b 1b @ and loop
3:
mov r0,r5 @ return counter
pop {r1-r5,pc} @ restaur registers
/***************************************************/
/* ROUTINES INCLUDE */
/***************************************************/
.include "../affichage.inc"

View file

@ -0,0 +1,26 @@
# syntax: GAWK -f ANTI-PRIMES.AWK
BEGIN {
print("The first 20 anti-primes are:")
while (count < 20) {
d = count_divisors(++n)
if (d > max_divisors) {
printf("%d ",n)
max_divisors = d
count++
}
}
printf("\n")
exit(0)
}
function count_divisors(n, count,i) {
if (n < 2) {
return(1)
}
count = 2
for (i=2; i<=n/2; i++) {
if (n % i == 0) {
count++
}
}
return(count)
}

View file

@ -0,0 +1,49 @@
BYTE FUNC CountDivisors(INT a)
INT i
BYTE prod,count
prod=1 count=0
WHILE a MOD 2=0
DO
count==+1
a==/2
OD
prod==*(1+count)
i=3
WHILE i*i<=a
DO
count=0
WHILE a MOD i=0
DO
count==+1
a==/i
OD
prod==*(1+count)
i==+2
OD
IF a>2 THEN
prod==*2
FI
RETURN (prod)
PROC Main()
BYTE toFind=[20],found=[0],count,max=[0]
INT i=[1]
PrintF("The first %B Anti-primes are:%E",toFind)
WHILE found<toFind
DO
count=CountDivisors(i)
IF count>max THEN
max=count
found==+1
PrintI(i)
IF found<toFind THEN
Print(", ")
FI
FI
i==+1
OD
RETURN

View file

@ -0,0 +1,38 @@
with Ada.Text_IO; use Ada.Text_IO;
procedure Antiprimes is
function Count_Divisors (N : Integer) return Integer is
Count : Integer := 1;
begin
for i in 1 .. N / 2 loop
if N mod i = 0 then
Count := Count + 1;
end if;
end loop;
return Count;
end Count_Divisors;
Results : array (1 .. 20) of Integer;
Candidate : Integer := 1;
Divisors : Integer;
Max_Divisors : Integer := 0;
begin
for i in Results'Range loop
loop
Divisors := Count_Divisors (Candidate);
if Max_Divisors < Divisors then
Results (i) := Candidate;
Max_Divisors := Divisors;
exit;
end if;
Candidate := Candidate + 1;
end loop;
end loop;
Put_Line ("The first 20 anti-primes are:");
for I in Results'Range loop
Put (Integer'Image (Results (I)));
end loop;
New_Line;
end Antiprimes;

View file

@ -0,0 +1,33 @@
on factorCount(n)
set counter to 0
set sqrt to n ^ 0.5
set limit to sqrt div 1
if (limit = sqrt) then
set counter to counter + 1
set limit to limit - 1
end if
repeat with i from limit to 1 by -1
if (n mod i is 0) then set counter to counter + 2
end repeat
return counter
end factorCount
on antiprimes(howMany)
set output to {}
set mostFactorsSoFar to 0
set n to 0
repeat until ((count output) = howMany)
set n to n + 1
tell (factorCount(n))
if (it > mostFactorsSoFar) then
set end of output to n
set mostFactorsSoFar to it
end if
end tell
end repeat
return output
end antiprimes
antiprimes(20)

View file

@ -0,0 +1 @@
{1, 2, 4, 6, 12, 24, 36, 48, 60, 120, 180, 240, 360, 720, 840, 1260, 1680, 2520, 5040, 7560}

View file

@ -0,0 +1,13 @@
found: 0
i: 1
maxDiv: 0
while [found<20][
fac: size factors i
if fac > maxDiv [
print i
maxDiv: fac
found: found + 1
]
i: i + 1
]

View file

@ -0,0 +1,25 @@
Dim Results(20)
Candidate = 1
max_divisors = 0
Print "Los primeros 20 anti-primos son:"
For j = 0 To 19
Do
divisors = count_divisors(Candidate)
If max_divisors < divisors Then
Results[j] = Candidate
max_divisors = divisors
Exit Do
End If
Candidate += 1
Until false
Print Results[j];" ";
Next j
Function count_divisors(n)
cont = 1
For i = 1 To n/2
If (n % i) = 0 Then cont += 1
Next i
count_divisors = cont
End Function

View file

@ -0,0 +1,24 @@
get "libhdr"
manifest $( LIMIT = 20 $)
let nfactors(n) =
n < 2 -> 1, valof
$( let c = 2
for i=2 to n/2
if n rem i = 0 then c := c + 1
resultis c
$)
let start() be
$( let max = 0 and seen = 0 and n = 1
while seen < LIMIT
$( let f = nfactors(n)
if f > max
$( writef("%N ",n)
max := f
seen := seen + 1
$)
n := n + 1
$)
wrch('*N')
$)

View file

@ -0,0 +1,25 @@
#include <iostream>
int countDivisors(int n) {
if (n < 2) return 1;
int count = 2; // 1 and n
for (int i = 2; i <= n/2; ++i) {
if (n%i == 0) ++count;
}
return count;
}
int main() {
int maxDiv = 0, count = 0;
std::cout << "The first 20 anti-primes are:" << std::endl;
for (int n = 1; count < 20; ++n) {
int d = countDivisors(n);
if (d > maxDiv) {
std::cout << n << " ";
maxDiv = d;
count++;
}
}
std::cout << std::endl;
return 0;
}

View file

@ -0,0 +1,22 @@
using System;
using System.Linq;
using System.Collections.Generic;
public static class Program
{
public static void Main() =>
Console.WriteLine(string.Join(" ", FindAntiPrimes().Take(20)));
static IEnumerable<int> FindAntiPrimes() {
int max = 0;
for (int i = 1; ; i++) {
int divisors = CountDivisors(i);
if (divisors > max) {
max = divisors;
yield return i;
}
}
int CountDivisors(int n) => Enumerable.Range(1, n / 2).Count(i => n % i == 0) + 1;
}
}

View file

@ -0,0 +1,26 @@
#include <stdio.h>
int countDivisors(int n) {
int i, count;
if (n < 2) return 1;
count = 2; // 1 and n
for (i = 2; i <= n/2; ++i) {
if (n%i == 0) ++count;
}
return count;
}
int main() {
int n, d, maxDiv = 0, count = 0;
printf("The first 20 anti-primes are:\n");
for (n = 1; count < 20; ++n) {
d = countDivisors(n);
if (d > maxDiv) {
printf("%d ", n);
maxDiv = d;
count++;
}
}
printf("\n");
return 0;
}

View file

@ -0,0 +1,36 @@
% Count factors
factors = proc (n: int) returns (int)
if n<2 then return(1) end
count: int := 2
for i: int in int$from_to(2, n/2) do
if n//i = 0 then count := count + 1 end
end
return(count)
end factors
% Generate antiprimes
antiprimes = iter () yields (int)
max: int := 0
n: int := 1
while true do
f: int := factors(n)
if f > max then
yield(n)
max := f
end
n := n + 1
end
end antiprimes
% Show the first 20 antiprimes
start_up = proc ()
max = 20
po: stream := stream$primary_output()
count: int := 0
for i: int in antiprimes() do
stream$puts(po, int$unparse(i) || " ")
count := count + 1
if count = max then break end
end
end start_up

View file

@ -0,0 +1,84 @@
******************************************************************
* COBOL solution to Anti-primes challange
* The program was run on OpenCobolIDE
******************************************************************
IDENTIFICATION DIVISION.
PROGRAM-ID. ANGLE-PRIMES.
ENVIRONMENT DIVISION.
DATA DIVISION.
WORKING-STORAGE SECTION.
77 ANTI-PRIMES-CTR PIC 9(3) VALUE 0.
77 FACTORS-CTR PIC 9(3) VALUE 0.
77 WS-INTEGER PIC 9(5) VALUE 1.
77 WS-MAX PIC 9(5) VALUE 0.
77 WS-I PIc 9(5) VALUE 0.
77 WS-LIMIT PIC 9(5) VALUE 1.
77 WS-REMAINDER PIC 9(5).
01 OUT-HDR PIC X(23) VALUE 'SEQ ANTI-PRIME FACTORS'.
01 OUT-LINE.
05 OUT-SEQ PIC 9(3).
05 FILLER PIC X(3) VALUE SPACES.
05 OUT-ANTI PIC ZZZZ9.
05 FILLER PIC X(4) VALUE SPACES.
05 OUT-FACTORS PIC ZZZZ9.
PROCEDURE DIVISION.
000-MAIN.
DISPLAY OUT-HDR.
PERFORM 100-GET-ANTI-PRIMES
VARYING WS-INTEGER FROM 1 By 1
UNTIL ANTI-PRIMES-CTR >= 20.
STOP RUN.
100-GET-ANTI-PRIMES.
SET FACTORS-CTR TO 0.
COMPUTE WS-LIMIT = 1 + WS-INTEGER ** .5.
PERFORM 200-COUNT-FACTORS
VARYING WS-I FROM 1 BY 1
UNTIL WS-I >= WS-LIMIT.
IF FACTORS-CTR > WS-MAX
ADD 1 TO ANTI-PRIMES-CTR
COMPUTE WS-MAX = FACTORS-CTR
MOVE ANTI-PRIMES-CTR TO OUT-SEQ
MOVE WS-INTEGER TO OUT-ANTI
MOVE FACTORS-CTR TO OUT-FACTORS
DISPLAY OUT-LINE
END-IF.
200-COUNT-FACTORS.
COMPUTE WS-REMAINDER =
FUNCTION MOD(WS-INTEGER WS-I).
IF WS-REMAINDER = ZERO
ADD 1 TO FACTORS-CTR
IF WS-INTEGER NOT = WS-I ** 2
ADD 1 TO FACTORS-CTR
END-IF
END-IF.
******************************************************************
* OUTPUT:
******************************************************************
* SEQ ANTI-PRIME FACTORS
* 001 1 1
* 002 2 2
* 003 4 3
* 004 6 4
* 005 12 6
* 006 24 8
* 007 36 9
* 008 48 10
* 009 60 12
* 010 120 16
* 011 180 18
* 012 240 20
* 013 360 24
* 014 720 30
* 015 840 32
* 016 1260 36
* 017 1680 40
* 018 2520 48
* 019 5040 60
* 020 7560 64
******************************************************************

View file

@ -0,0 +1,20 @@
(defun factors (n &aux (lows '()) (highs '()))
(do ((limit (1+ (isqrt n))) (factor 1 (1+ factor)))
((= factor limit)
(when (= n (* limit limit))
(push limit highs))
(remove-duplicates (nreconc lows highs)))
(multiple-value-bind (quotient remainder) (floor n factor)
(when (zerop remainder)
(push factor lows)
(push quotient highs)))))
(defun anti-prime ()
(format t "The first 20 anti-primes are :~%")
(do ((dmax 0) (c 0) (i 0 (1+ i)))
((= c 20))
(setf facts (list-length (factors i)))
(when (< dmax facts)
(format t "~d " i)
(setq dmax facts)
(incf c))))

View file

@ -0,0 +1,30 @@
include "cowgol.coh";
const AMOUNT := 20;
sub countFactors(n: uint16): (count: uint16) is
var i: uint16 := 1;
count := 1;
while i <= n/2 loop
if n%i == 0 then
count := count + 1;
end if;
i := i + 1;
end loop;
end sub;
var max: uint16 := 0;
var seen: uint8 := 0;
var n: uint16 := 1;
var f: uint16 := 0;
while seen < AMOUNT loop;
f := countFactors(n);
if f > max then
print_i16(n);
print_char(' ');
max := f;
seen := seen + 1;
end if;
n := n + 1;
end loop;
print_nl();

View file

@ -0,0 +1,32 @@
def count_divisors(n : Int64) : Int64
return 1_i64 if n < 2
count = 2_i64
i = 2
while i <= n // 2
count += 1 if n % i == 0
i += 1
end
count
end
max_div = 0_i64
count = 0_i64
print "The first 20 anti-primes are: "
n = 1_i64
while count < 20
d = count_divisors n
if d > max_div
print "#{n} "
max_div = d
count += 1
end
n += 1
end
puts ""

View file

@ -0,0 +1,28 @@
import std.stdio;
int countDivisors(int n) {
if (n < 2) {
return 1;
}
int count = 2; // 1 and n
for (int i = 2; i <= n/2; ++i) {
if (n % i == 0) {
++count;
}
}
return count;
}
void main() {
int maxDiv, count;
writeln("The first 20 anti-primes are:");
for (int n = 1; count < 20; ++n) {
int d = countDivisors(n);
if (d > maxDiv) {
write(n, ' ');
maxDiv = d;
count++;
}
}
writeln;
}

View file

@ -0,0 +1,22 @@
int countDivisors(int n) {
if (n < 2) return 1;
int count = 2; // 1 and n
for (int i = 2; i <= n / 2; ++i) {
if (n % i == 0) ++count;
}
return count;
}
void main() {
int maxDiv = 0, count = 0;
print("The first 20 anti-primes are:");
for (int n = 1; count < 20; ++n) {
int d = countDivisors(n);
if (d > maxDiv) {
print("$n ");
maxDiv = d;
count++;
}
}
print("");
}

View file

@ -0,0 +1,19 @@
fun countDivisors = int by int n
if n < 2 do return 1 end
int count = 2
for int i = 2; i <= n / 2; ++i
if n % i == 0 do ++count end
end
return count
end
int maxDiv = 0
int count = 0
writeLine("The first 20 anti-primes are:")
for int n = 1; count < 20; ++n
int d = countDivisors(n)
if d <= maxDiv do continue end # never nester version
write(n + " ")
maxDiv = d
++count
end
writeLine()

View file

@ -0,0 +1,31 @@
defmodule AntiPrimes do
def divcount(n) when is_integer(n), do: divcount(n, 1, 0)
def divcount(n, d, count) when d * d > n, do: count
def divcount(n, d, count) do
divs = case rem(n, d) do
0 ->
case n - d * d do
0 -> 1
_ -> 2
end
_ -> 0
end
divcount(n, d + 1, count + divs)
end
def antiprimes(n), do: antiprimes(n, 1, 0, [])
def antiprimes(0, _, _, l), do: Enum.reverse(l)
def antiprimes(n, m, max, l) do
count = divcount(m)
case count > max do
true -> antiprimes(n-1, m+1, count, [m|l])
false -> antiprimes(n, m+1, max, l)
end
end
def main() do
:io.format("The first 20 anti-primes are ~w~n", [antiprimes(20)])
end
end

View file

@ -0,0 +1,28 @@
divcount(N) -> divcount(N, 1, 0).
divcount(N, D, Count) when D*D > N -> Count;
divcount(N, D, Count) ->
Divs = case N rem D of
0 ->
case N - D*D of
0 -> 1;
_ -> 2
end;
_ -> 0
end,
divcount(N, D + 1, Count + Divs).
antiprimes(N) -> antiprimes(N, 1, 0, []).
antiprimes(0, _, _, L) -> lists:reverse(L);
antiprimes(N, M, Max, L) ->
Count = divcount(M),
case Count > Max of
true -> antiprimes(N-1, M+1, Count, [M|L]);
false -> antiprimes(N, M+1, Max, L)
end.
main(_) ->
io:format("The first 20 anti-primes are ~w~n", [antiprimes(20)]).

View file

@ -0,0 +1,6 @@
// Find Antı-Primes. Nigel Galloway: Secember 10th., 2018
let N=200000000000000000000000000I
let fI,_=Seq.scan(fun (_,g) e->(e,e*g)) (2I,4I) (primes|>Seq.skip 1|>Seq.map bigint)|>Seq.takeWhile(fun(_,n)->n<N)|>List.ofSeq|>List.unzip
let fG g=Seq.unfold(fun ((n,i,e) as z)->Some(z,(n+1,i+1,(e*g)))) (1,2,g)|>Seq.takeWhile(fun(_,_,n)->n<N)
let fE n i=n|>Seq.collect(fun(n,e,g)->Seq.map(fun(a,c,b)->(a,c*e,g*b)) (i|>Seq.takeWhile(fun(g,_,_)->g<=n)) |> Seq.takeWhile(fun(_,_,n)->n<N))
let fL,_=Seq.concat(Seq.scan(fun n g->fE n (fG g)) (seq[(2147483647,1,1I)]) fI)|>List.ofSeq|>List.sortBy(fun(_,_,n)->n)|>List.fold(fun ((a,b) as z) (_,n,g)->if n>b then ((n,g)::a,n) else z) ([],0)

View file

@ -0,0 +1 @@
printfn "The first 20 anti-primes are :-"; for (_,g) in (List.rev fL)|>List.take 20 do printfn "%A" g

View file

@ -0,0 +1 @@
printfn "There are %d anti-primes less than %A:-" (List.length fL) N; for (n,g) in (List.rev fL) do printfn "%A has %d dividers" g n

View file

@ -0,0 +1,26 @@
USING: assocs formatting kernel locals make math
math.primes.factors sequences.extras ;
IN: rosetta-code.anti-primes
<PRIVATE
: count-divisors ( n -- m )
dup 1 = [ group-factors values [ 1 + ] map-product ] unless ;
: (n-anti-primes) ( md n count -- ?md' n' ?count' )
dup 0 >
[| max-div! n count! |
n count-divisors :> d
d max-div > [ d max-div! n , count 1 - count! ] when
max-div n dup 60 >= 20 1 ? + count (n-anti-primes)
] when ;
PRIVATE>
: n-anti-primes ( n -- seq )
[ 0 1 ] dip [ (n-anti-primes) 3drop ] { } make ;
: anti-primes-demo ( -- )
20 n-anti-primes "First 20 anti-primes:\n%[%d, %]\n" printf ;
MAIN: anti-primes-demo

View file

@ -0,0 +1,21 @@
include ./factors.fs
: max-count ( n1 n2 -- n f )
\ n is max(n1, factor-count n2); if n is new maximum then f = true.
\
count-factors 2dup <
if nip true
else drop false
then ;
: .anti-primes ( n -- )
0 1 rot \ stack: max, candidate, count
begin
>r dup >r max-count
if r> dup . r> 1-
else r> r>
then swap 1+ swap
dup 0= until drop 2drop ;
." The first 20 anti-primes are: " 20 .anti-primes cr
bye

View file

@ -0,0 +1,36 @@
program anti_primes
use iso_fortran_env, only: output_unit
implicit none
integer :: n, d, maxDiv, pCount
write(output_unit,*) "The first 20 anti-primes are:"
n = 1
maxDiv = 0
pCount = 0
do
if (pCount >= 20) exit
d = countDivisors(n)
if (d > maxDiv) then
write(output_unit,'(I0,x)', advance="no") n
maxDiv = d
pCount = pCount + 1
end if
n = n + 1
end do
write(output_unit,*)
contains
pure function countDivisors(n)
integer, intent(in) :: n
integer :: countDivisors
integer :: i
countDivisors = 1
if (n < 2) return
countDivisors = 2
do i = 2, n/2
if (modulo(n, i) == 0) countDivisors = countDivisors + 1
end do
end function countDivisors
end program anti_primes

View file

@ -0,0 +1,31 @@
' convertido desde Ada
Declare Function count_divisors(n As Integer) As Integer
Dim As Integer max_divisors, divisors, results(1 To 20), candidate, j
candidate = 1
Function count_divisors(n As Integer) As Integer
Dim As Integer i, count = 1
For i = 1 To n/2
If (n Mod i) = 0 Then count += 1
Next i
count_divisors = count
End Function
Print "Los primeros 20 anti-primos son:"
For j = 1 To 20
Do
divisors = count_divisors(Candidate)
If max_divisors < divisors Then
Results(j) = Candidate
max_divisors = divisors
Exit Do
End If
Candidate += 1
Loop
Next j
For j = 1 To 20
Print Results(j);
Next j
Print
Sleep

View file

@ -0,0 +1,15 @@
smallest = 0
n = 1
results = new array
do
{
len = length[allFactors[n]]
if len > smallest
{
results.push[n]
smallest = len
}
n = n + 1
} until length[results] == 20
println[join[" ", results]]

View file

@ -0,0 +1,39 @@
local fn DivisorCount( v as long ) as long
long total = 1, n = v, p, count
while ( n mod 2 ) == 0
total++
n = int( n / 2 )
wend
p = 3
while ( p * p ) <= n
count = 1
while ( n mod p ) == 0
count++
n = int( n / p )
wend
p = p + 2
total = total * count
wend
if n > 1 then total = total * 2
end fn = total
void local fn AntiPrimes( howMany as long )
long n = 0, count = 0, divisors, max_divisors = 0
printf @"The first %ld anti-primes are:", howMany
while ( count < howMany )
n++
divisors = fn DivisorCount( n )
if ( divisors > max_divisors )
printf @"%ld \b", n
max_divisors = divisors
count++
end if
wend
end fn
fn AntiPrimes( 20 )
HandleEvents

View file

@ -0,0 +1,13 @@
10 REM Anti-primes
20 DEFINT A-Z
30 N=1
40 IF S>=20 THEN END ELSE F=1
50 IF N<2 GOTO 80 ELSE FOR I=1 TO N\2
60 IF N MOD I=0 THEN F=F+1
70 NEXT
80 IF F<=M GOTO 120
90 PRINT N,
100 M=F
110 S=S+1
120 N=N+1
130 GOTO 40

View file

@ -0,0 +1,16 @@
10 REM Anti-primes
20 C = -999
30 N = N + 1
40 GOSUB 70
50 IF T = 20 THEN END
60 GOTO 30
70 D = 0
80 FOR F = 1 TO INT(N/2)
90 IF N MOD F = 0 THEN D = D + 1
100 NEXT F
110 IF D > C THEN GOSUB 130
120 RETURN
130 C = D
140 T = T + 1
150 PRINT N
160 RETURN

View file

@ -0,0 +1,29 @@
Function count_divisors(n As Integer) As Integer
Dim i, count As Integer
If n < 2 Then Return 1
count = 2
For i = 2 To n / 2
If Not (n Mod i) Then Inc count
Next
Return count
End Function
Public Sub Main()
Dim count, max_divisors, n, d As Integer
Print "Los primeros 20 anti-primos son:"
While (count < 20)
Inc n
d = count_divisors(n)
If d > max_divisors Then
Print n; " ";
max_divisors = d
Inc count
End If
Wend
End

View file

@ -0,0 +1,31 @@
package main
import "fmt"
func countDivisors(n int) int {
if n < 2 {
return 1
}
count := 2 // 1 and n
for i := 2; i <= n/2; i++ {
if n%i == 0 {
count++
}
}
return count
}
func main() {
fmt.Println("The first 20 anti-primes are:")
maxDiv := 0
count := 0
for n := 1; count < 20; n++ {
d := countDivisors(n)
if d > maxDiv {
fmt.Printf("%d ", n)
maxDiv = d
count++
}
}
fmt.Println()
}

View file

@ -0,0 +1,15 @@
def getAntiPrimes(def limit = 10) {
def antiPrimes = []
def candidate = 1L
def maxFactors = 0
while (antiPrimes.size() < limit) {
def factors = factorize(candidate)
if (factors.size() > maxFactors) {
maxFactors = factors.size()
antiPrimes << candidate
}
candidate++
}
antiPrimes
}

View file

@ -0,0 +1 @@
println (getAntiPrimes(20))

View file

@ -0,0 +1,28 @@
import Data.List (find, group)
import Data.Maybe (fromJust)
firstPrimeFactor :: Int -> Int
firstPrimeFactor n = head $ filter ((0 ==) . mod n) [2 .. n]
allPrimeFactors :: Int -> [Int]
allPrimeFactors 1 = []
allPrimeFactors n =
let first = firstPrimeFactor n
in first : allPrimeFactors (n `div` first)
factorCount :: Int -> Int
factorCount 1 = 1
factorCount n = product ((succ . length) <$> group (allPrimeFactors n))
divisorCount :: Int -> (Int, Int)
divisorCount = (,) <*> factorCount
hcnNext :: (Int, Int) -> (Int, Int)
hcnNext (num, factors) =
fromJust $ find ((> factors) . snd) (divisorCount <$> [num ..])
hcnSequence :: [Int]
hcnSequence = fst <$> iterate hcnNext (1, 1)
main :: IO ()
main = print $ take 20 hcnSequence

View file

@ -0,0 +1,13 @@
NB. factor count is the product of the incremented powers of prime factors
factor_count =: [: */ [: >: _&q:
NB. N are the integers 1 to 10000
NB. FC are the corresponding factor counts
FC =: factor_count&> N=: >: i. 10000
NB. take from the integers N{~
NB. the indexes of truth I.
NB. the vector which doesn't equal itself when rotated by one position (~: _1&|.)
NB. where that vector is the maximum over all prefixes of the factor counts >./\FC
N{~I.(~: _1&|.)>./\FC
1 2 4 6 12 24 36 48 60 120 180 240 360 720 840 1260 1680 2520 5040 7560

View file

@ -0,0 +1,25 @@
public class Antiprime {
static int countDivisors(int n) {
if (n < 2) return 1;
int count = 2; // 1 and n
for (int i = 2; i <= n/2; ++i) {
if (n%i == 0) ++count;
}
return count;
}
public static void main(String[] args) {
int maxDiv = 0, count = 0;
System.out.println("The first 20 anti-primes are:");
for (int n = 1; count < 20; ++n) {
int d = countDivisors(n);
if (d > maxDiv) {
System.out.printf("%d ", n);
maxDiv = d;
count++;
}
}
System.out.println();
}
}

View file

@ -0,0 +1,39 @@
function factors(n) {
var factors = [];
for (var i = 1; i <= n; i++) {
if (n % i == 0) {
factors.push(i);
}
}
return factors;
}
function generateAntiprimes(n) {
var antiprimes = [];
var maxFactors = 0;
for (var i = 1; antiprimes.length < n; i++) {
var ifactors = factors(i);
if (ifactors.length > maxFactors) {
antiprimes.push(i);
maxFactors = ifactors.length;
}
}
return antiprimes;
}
function go() {
var number = document.getElementById("n").value;
document.body.removeChild(document.getElementById("result-list"));
document.body.appendChild(showList(generateAntiprimes(number)));
}
function showList(array) {
var list = document.createElement("ul");
list.id = "result-list";
for (var i = 0; i < array.length; i++) {
var item = document.createElement("li");
item.appendChild(document.createTextNode(array[i]));
list.appendChild(item);
}
return list;
}

View file

@ -0,0 +1,32 @@
# Compute the number of divisors, without calling sqrt
def ndivisors:
def sum(s): reduce s as $x (null; .+$x);
if . == 1 then 1
else . as $n
| sum( label $out
| range(1; $n) as $i
| ($i * $i) as $i2
| if $i2 > $n then break $out
else if $i2 == $n
then 1
elif ($n % $i) == 0
then 2
else empty
end
end)
end;
# Emit the antiprimes as a stream
def antiprimes:
1,
foreach range(2; infinite; 2) as $i ({maxfactors: 1};
.emit = null
| ($i | ndivisors) as $nfactors
| if $nfactors > .maxfactors
then .emit = $i
| .maxfactors = $nfactors
else .
end;
select(.emit).emit);
"The first 20 anti-primes are:", limit(20; antiprimes)

View file

@ -0,0 +1,21 @@
using Primes, Combinatorics
function antiprimes(N, maxn = 2000000)
antip = [1] # special case: 1 is antiprime
count = 1
maxfactors = 1
for i in 2:2:maxn # antiprimes > 2 should be even
lenfac = length(unique(sort(collect(combinations(factor(Vector, i)))))) + 1
if lenfac > maxfactors
push!(antip, i)
if length(antip) >= N
return antip
end
maxfactors = lenfac
end
end
antip
end
println("The first 20 anti-primes are:\n", antiprimes(20))
println("The first 40 anti-primes are:\n", antiprimes(40))

View file

@ -0,0 +1,27 @@
// Version 1.3.10
fun countDivisors(n: Int): Int {
if (n < 2) return 1;
var count = 2 // 1 and n
for (i in 2..n / 2) {
if (n % i == 0) count++
}
return count;
}
fun main(args: Array<String>) {
println("The first 20 anti-primes are:")
var maxDiv = 0
var count = 0
var n = 1
while (count < 20) {
val d = countDivisors(n)
if (d > maxDiv) {
print("$n ")
maxDiv = d
count++
}
n++
}
println()
}

View file

@ -0,0 +1,30 @@
{def factors
{def factors.filter
{lambda {:n :a :i}
{if {= {% :n :i} 0}
then {A.addlast! :i :a}
else}}}
{lambda {:n}
{S.last
{S.map {factors.filter :n {A.new}}
{S.serie 1 :n}}}}}
-> factors
{def antiprimes
{def antiprimes.filter
{lambda {:ap :max :i}
{let { {:ap :ap} {:max :max} {:i :i}
{:len {A.length {factors :i}}}
} {if {> :len {A.get 0 :max}}
then {A.addlast! :i :ap}
{A.set! 0 :len :max}
else} }}}
{lambda {:n}
{S.first
{S.map {antiprimes.filter {A.new 1} {A.new 1}}
{S.serie 1 :n}}}}}
-> antiprimes
{antiprimes 8000} // 8000 choosen manually to reach 20 antiprimes
-> [1,2,4,6,12,24,36,48,60,120,180,240,360,720,840,1260,1680,2520,5040,7560]
// in 105400ms on my iPad

View file

@ -0,0 +1,35 @@
1) building the interface to the javascript function.
{script
LAMBDATALK.DICT['jsgenerateAntiprimes'] = function() {
function factors(n) {
var factors = [];
for (var i = 1; i <= n; i++) {
if (n % i == 0) {
factors.push(i);
}
}
return factors;
}
function generateAntiprimes(n) {
var antiprimes = [];
var maxFactors = 0;
for (var i = 1; antiprimes.length < n; i++) {
var ifactors = factors(i);
if (ifactors.length > maxFactors) {
antiprimes.push(i);
maxFactors = ifactors.length;
}
}
return antiprimes;
}
return generateAntiprimes( arguments[0].trim() )
};
}
2) and using it in the wiki page as a builtin primitive
{jsgenerateAntiprimes 20}
->
1,2,4,6,12,24,36,48,60,120,180,240,360,720,840,1260,1680,2520,5040,7560 // in 100ms

View file

@ -0,0 +1,18 @@
val .countDivisors = f(.n) {
if .n < 2: return 1
for[=2] .i = 2; .i <= .n\2; .i += 1 {
if .n div .i : _for += 1
}
}
writeln "The first 20 anti-primes are:"
var .maxDiv, .count = 0, 0
for .n = 1; .count < 20; .n += 1 {
val .d = .countDivisors(.n)
if .d > .maxDiv {
write .n, " "
.maxDiv = .d
.count += 1
}
}
writeln()

View file

@ -0,0 +1,35 @@
-- First 20 antiprimes.
function count_factors(number)
local count = 0
for attempt = 1, number do
local remainder = number % attempt
if remainder == 0 then
count = count + 1
end
end
return count
end
function antiprimes(goal)
local list, number, mostFactors = {}, 1, 0
while #list < goal do
local factors = count_factors(number)
if factors > mostFactors then
table.insert(list, number)
mostFactors = factors
end
number = number + 1
end
return list
end
function recite(list)
for index, item in ipairs(list) do
print(item)
end
end
print("The first 20 antiprimes:")
recite(antiprimes(20))
print("Done.")

View file

@ -0,0 +1,16 @@
antiprimes := proc(n)
local ap, i, max_divisors, num_divisors;
max_divisors := 0;
ap := [];
for i from 1 while numelems(ap) < n do
num_divisors := numelems(NumberTheory:-Divisors(i));
if num_divisors > max_divisors then
ap := [op(ap), i];
max_divisors := num_divisors;
end if;
end do;
return ap;
end proc:
antiprimes(20);

View file

@ -0,0 +1,14 @@
sigma = DivisorSigma[0, #] &;
currentmax = -\[Infinity];
res = {};
Do[
s = sigma[v];
If[s > currentmax,
AppendTo[res, v];
currentmax = s;
];
If[Length[res] >= 25, Break[]]
,
{v, \[Infinity]}
]
res

View file

@ -0,0 +1,34 @@
MODULE Antiprimes;
FROM InOut IMPORT WriteCard, WriteLn;
CONST Amount = 20;
VAR max, seen, n, f: CARDINAL;
PROCEDURE factors(n: CARDINAL): CARDINAL;
VAR facs, div: CARDINAL;
BEGIN
IF n<2 THEN RETURN 1; END;
facs := 2;
FOR div := 2 TO n DIV 2 DO
IF n MOD div = 0 THEN
INC(facs);
END;
END;
RETURN facs;
END factors;
BEGIN
max := 0;
seen := 0;
n := 1;
WHILE seen < Amount DO
f := factors(n);
IF f > max THEN
WriteCard(n,5);
max := f;
INC(seen);
IF seen MOD 10 = 0 THEN WriteLn(); END;
END;
INC(n);
END;
END Antiprimes.

View file

@ -0,0 +1,37 @@
MODULE AntiPrimes EXPORTS Main;
IMPORT IO,Fmt;
CONST
Amount = 20;
VAR
Max,Seen,N,F:CARDINAL;
PROCEDURE Factors(N:CARDINAL):CARDINAL =
VAR
Facts:CARDINAL;
BEGIN
IF N < 2 THEN RETURN 1 END;
Facts := 2;
FOR Div := 2 TO N DIV 2 DO
IF N MOD Div = 0 THEN INC(Facts) END;
END;
RETURN Facts;
END Factors;
BEGIN
Max := 0;
Seen := 0;
N := 1;
WHILE Seen < Amount DO
F := Factors(N);
IF F > Max THEN
IO.Put(Fmt.F("%5s",Fmt.Int(N)));
Max := F;
INC(Seen);
IF Seen MOD 10 = 0 THEN IO.Put("\n") END;
END;
INC(N);
END;
END AntiPrimes.

View file

@ -0,0 +1,26 @@
def countDivisors(n)
if (n < 2)
return 1
end
count = 2
for i in range(2, int(n/2))
if (n % i) = 0
count += 1
end
end
return count
end
maxDiv = 0
count = 0
println "The first 20 anti-primes are:"
for (n = 1) (count < 20) (n += 1)
d = countDivisors(n)
if d > maxDiv
print format("%d ", n)
maxDiv = d
count += 1
end
end
println

View file

@ -0,0 +1,25 @@
# First 20 antiprimes
proc countDivisors(n: int): int =
if n < 2:
return 1
var count = 2
for i in countup(2, (n / 2).toInt()):
if n %% i == 0:
count += 1
return count
proc antiPrimes(n: int) =
echo("The first ", n, " anti-primes:")
var maxDiv = 0
var count = 0
var i = 1
while count < n:
let d = countDivisors(i)
if d > maxDiv:
echo(i)
maxDiv = d
count += 1
i += 1
antiPrimes(20)

View file

@ -0,0 +1,37 @@
MODULE AntiPrimes;
IMPORT Out;
CONST
Amount = 20;
VAR
Max,Seen,N,F:INTEGER;
PROCEDURE Factors(N:INTEGER):INTEGER;
VAR
Facts,Div:INTEGER;
BEGIN
IF N < 2 THEN RETURN 1 END;
Facts := 2;
FOR Div := 2 TO N DIV 2 DO
IF N MOD Div = 0 THEN INC(Facts) END;
END;
RETURN Facts;
END Factors;
BEGIN
Max := 0;
Seen := 0;
N := 1;
WHILE Seen < Amount DO
F := Factors(N);
IF F > Max THEN
Out.Int(N,5);
Max := F;
INC(Seen);
IF Seen MOD 10 = 0 THEN Out.Ln END;
END;
INC(N);
END;
END AntiPrimes.

View file

@ -0,0 +1,24 @@
class AntiPrimes {
function : Main(args : String[]) ~ Nil {
maxDiv := 0; count := 0;
"The first 20 anti-primes are:"->PrintLine();
for(n := 1; count < 20; ++n;) {
d := CountDivisors(n);
if(d > maxDiv) {
"{$n} "->Print();
maxDiv := d;
count++;
};
};
'\n'->Print();
}
function : native : CountDivisors(n : Int) ~ Int {
if (n < 2) { return 1; };
count := 2;
for(i := 2; i <= n/2; ++i;) {
if(n%i = 0) { ++count; };
};
return count;
}
}

View file

@ -0,0 +1,9 @@
countfactors(n)={
my(count(m)= prod(i=1,#factor(m)~,factor(m)[i,2]+1));
v=vector(n);
v[1]=1;
for(x=2,n,
v[x]=v[x-1]+1;
while(count(v[x-1])>=count(v[x]),v[x]++));
return(v)}
countfactors(20)

View file

@ -0,0 +1,23 @@
C :n=1
:max=0
:seen=0
*number
U :*count
T (c>max):#n
C (c>max):seen=seen+1
C (c>max):max=c
:n=n+1
J (seen<20):*number
E :
*count
C (n=1):c=1
E (n=1):
C :c=2
:i=2
*cnloop
E (i>n/2):
C (i*(n/i)=n):c=c+1
:i=i+1
J :*cnloop

View file

@ -0,0 +1,37 @@
var i, n, maxdivcnt, divcnt;
procedure countdivs;
var p;
begin
divcnt := 1;
if n > 1 then divcnt := 2;
p := 2;
while p * p < n do
begin
if (n / p) * p = n then divcnt := divcnt + 2;
p := p + 1
end;
if p * p = n then divcnt := divcnt + 1
end;
procedure searchnext;
begin
call countdivs;
while divcnt <= maxdivcnt do
begin
n := n + 1;
call countdivs
end
end;
begin
i := 1; n := 1; maxdivcnt := 0;
while i <= 20 do
begin
call searchnext;
maxdivcnt := divcnt;
i := i + 1;
! n;
n := n + 1
end
end.

View file

@ -0,0 +1,28 @@
antiprimes: procedure options(main);
/* count the factors of a number */
countFactors: procedure(n) returns(fixed);
declare (n, i, count) fixed;
if n<2 then return(1);
count = 1;
do i=1 to n/2;
if mod(n,i) = 0 then count = count + 1;
end;
return(count);
end countFactors;
declare maxFactors fixed static init (0);
declare seen fixed static init (0);
declare n fixed;
declare factors fixed;
do n=1 repeat(n+1) while(seen < 20);
factors = countFactors(n);
if factors > maxFactors then do;
put edit(n) (F(5));
maxFactors = factors;
seen = seen + 1;
if mod(seen,15) = 0 then put skip;
end;
end;
end antiprimes;

View file

@ -0,0 +1,46 @@
100H:
/* CP/M CALLS */
BDOS: PROCEDURE (FN, ARG); DECLARE FN BYTE, ARG ADDRESS; GO TO 5; END BDOS;
EXIT: PROCEDURE; CALL BDOS(0,0); END EXIT;
PRINT: PROCEDURE (S); DECLARE S ADDRESS; CALL BDOS(9,S); END PRINT;
/* PRINT A NUMBER */
PRINT$NUMBER: PROCEDURE (N);
DECLARE S (7) BYTE INITIAL ('..... $');
DECLARE (N, P) ADDRESS, C BASED P BYTE;
P = .S(5);
DIGIT:
P = P - 1;
C = N MOD 10 + '0';
N = N / 10;
IF N > 0 THEN GO TO DIGIT;
CALL PRINT(P);
END PRINT$NUMBER;
/* COUNT THE FACTORS OF A NUMBER */
COUNT$FACTORS: PROCEDURE (N) ADDRESS;
DECLARE (N, I, COUNT) ADDRESS;
IF N<2 THEN RETURN 1;
COUNT = 1;
DO I=1 TO N/2;
IF N MOD I = 0 THEN COUNT = COUNT + 1;
END;
RETURN COUNT;
END COUNT$FACTORS;
DECLARE MAX$FACTORS ADDRESS INITIAL (0);
DECLARE SEEN BYTE INITIAL (0);
DECLARE N ADDRESS INITIAL (1);
DECLARE FACTORS ADDRESS;
DO WHILE SEEN < 20;
FACTORS = COUNT$FACTORS(N);
IF FACTORS > MAX$FACTORS THEN DO;
CALL PRINT$NUMBER(N);
MAX$FACTORS = FACTORS;
SEEN = SEEN + 1;
END;
N = N + 1;
END;
CALL EXIT;
EOF

View file

@ -0,0 +1,25 @@
100 REM ANTI-PRIMES
110 LET N=1,H=0
120 PRINT "THE FIRST 20 ANTI-PRIMES ARE:"
130 FOR A=1 TO 20
140 GOSUB 300
150 LET H=F
160 PRINT N
170 LET N=N+1
180 NEXT A
190 STOP
290 REM SEARCH NEXT ANTI-PRIME
300 GOSUB 400
310 IF F>H RETURN
320 LET N=N+1
330 GOTO 300
390 REM COUNT DIVISORS
400 LET F=1
410 IF N>1 LET F=2
420 LET C=2
430 IF C*C>=N GOTO 470
440 IF (N/C)*C=N LET F=F+2
450 LET C=C+1
460 GOTO 430
470 IF C*C=N F=F+1
480 RETURN

View file

@ -0,0 +1,49 @@
program AntiPrimes;
{$IFdef FPC}
{$MOde Delphi}
{$IFEND}
function getFactorCnt(n:NativeUint):NativeUint;
var
divi,quot,pot,lmt : NativeUint;
begin
result := 1;
divi := 1;
lmt := trunc(sqrt(n));
while divi < n do
Begin
inc(divi);
pot := 0;
repeat
quot := n div divi;
if n <> quot*divi then
BREAK;
n := quot;
inc(pot);
until false;
result := result*(1+pot);
//IF n= prime leave now
if divi > lmt then
BREAK;
end;
end;
var
i,Count,FacCnt,lastCnt: NativeUint;
begin
count := 0;
lastCnt := 0;
i := 1;
repeat
FacCnt := getFactorCnt(i);
if lastCnt < FacCnt then
Begin
write(i,'(',FacCnt,'),');
lastCnt:= FacCnt;
inc(Count);
if count = 12 then
Writeln;
end;
inc(i);
until Count >= 20;
writeln;
end.

View file

@ -0,0 +1,14 @@
use ntheory qw(divisors);
my @anti_primes;
for (my ($k, $m) = (1, 0) ; @anti_primes < 20 ; ++$k) {
my $sigma0 = divisors($k);
if ($sigma0 > $m) {
$m = $sigma0;
push @anti_primes, $k;
}
}
printf("%s\n", join(' ', @anti_primes));

View file

@ -0,0 +1,14 @@
(phixonline)-->
<span style="color: #008080;">with</span> <span style="color: #008080;">javascript_semantics</span>
<span style="color: #004080;">integer</span> <span style="color: #000000;">n</span><span style="color: #0000FF;">=</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">maxd</span> <span style="color: #0000FF;">=</span> <span style="color: #0000FF;">-</span><span style="color: #000000;">1</span>
<span style="color: #004080;">sequence</span> <span style="color: #000000;">res</span> <span style="color: #0000FF;">=</span> <span style="color: #0000FF;">{}</span>
<span style="color: #008080;">while</span> <span style="color: #7060A8;">length</span><span style="color: #0000FF;">(</span><span style="color: #000000;">res</span><span style="color: #0000FF;">)<</span><span style="color: #000000;">20</span> <span style="color: #008080;">do</span>
<span style="color: #004080;">integer</span> <span style="color: #000000;">lf</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">length</span><span style="color: #0000FF;">(</span><span style="color: #7060A8;">factors</span><span style="color: #0000FF;">(</span><span style="color: #000000;">n</span><span style="color: #0000FF;">,</span><span style="color: #000000;">1</span><span style="color: #0000FF;">))</span>
<span style="color: #008080;">if</span> <span style="color: #000000;">lf</span><span style="color: #0000FF;">></span><span style="color: #000000;">maxd</span> <span style="color: #008080;">then</span>
<span style="color: #000000;">res</span> <span style="color: #0000FF;">&=</span> <span style="color: #000000;">n</span>
<span style="color: #000000;">maxd</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">lf</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">if</span>
<span style="color: #000000;">n</span> <span style="color: #0000FF;">+=</span> <span style="color: #008080;">iff</span><span style="color: #0000FF;">(</span><span style="color: #000000;">n</span><span style="color: #0000FF;">></span><span style="color: #000000;">1</span><span style="color: #0000FF;">?</span><span style="color: #000000;">2</span><span style="color: #0000FF;">:</span><span style="color: #000000;">1</span><span style="color: #0000FF;">)</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 20 anti-primes are: %V\n"</span><span style="color: #0000FF;">,{</span><span style="color: #000000;">res</span><span style="color: #0000FF;">})</span>
<!--

View file

@ -0,0 +1,37 @@
0 var count
0 var n
0 var max_divisors
"The first 20 anti-primes are:" print nl
def count_divisors
dup 2 < if
drop
1
else
2
swap 1 over 2 / 2 tolist
for
over swap mod not if swap 1 + swap endif
endfor
drop
endif
enddef
true
while
count 20 < dup if
n 1 + var n
n count_divisors
dup max_divisors > if
n print " " print
var max_divisors
count 1 + var count
else
drop
endif
endif
endwhile
nl
msec print

View file

@ -0,0 +1,25 @@
count_divisors(1) = 1.
count_divisors(N) = Count, N >= 2 =>
Count = 2,
foreach (I in 2..N/2)
if (N mod I == 0) then
Count := Count + 1
end
end.
main =>
println("The first 20 anti-primes are:"),
MaxDiv = 0,
Count = 0,
N = 1,
while (Count < 20)
D := count_divisors(N),
if (D > MaxDiv) then
printf("%d ", N),
MaxDiv := D,
Count := Count + 1
end,
N := N + 1
end,
nl.

View file

@ -0,0 +1,18 @@
(de factors (N)
(let C 1
(when (>= N 2)
(inc 'C)
(for (I 2 (>= (/ N 2) I) (inc I))
(and (=0 (% N I)) (inc 'C)) ) )
C ) )
(de anti (X)
(let (M 0 I 0 N 0)
(make
(while (> X I)
(inc 'N)
(let R (factors N)
(when (> R M)
(link N)
(setq M R)
(inc 'I) ) ) ) ) ) )
(println (anti 20))

View file

@ -0,0 +1,21 @@
void setup() {
int most_factors = 0;
IntList anti_primes = new IntList();
int n = 1;
while (anti_primes.size() < 20) {
int counter = 1;
for (int i = 1; i <= n / 2; i++) {
if (n % i == 0) {
counter++;
}
}
if (counter > most_factors) {
anti_primes.append(n);
most_factors = counter;
}
n++;
}
for (int num : anti_primes) {
print(num + " ");
}
}

View file

@ -0,0 +1,29 @@
divcount(N, Count) :- divcount(N, 1, 0, Count).
divcount(N, D, C, C) :- D*D > N, !.
divcount(N, D, C, Count) :-
succ(D, D2),
divs(N, D, A), plus(A, C, C2),
divcount(N, D2, C2, Count).
divs(N, D, 0) :- N mod D =\= 0, !.
divs(N, D, 1) :- D*D =:= N, !.
divs(_, _, 2).
antiprimes(N, L) :- antiprimes(N, 1, 0, [], L).
antiprimes(0, _, _, L, R) :- reverse(L, R), !.
antiprimes(N, M, Max, L, R) :-
divcount(M, Count),
succ(M, M2),
(Count > Max
-> succ(N0, N), antiprimes(N0, M2, Count, [M|L], R)
; antiprimes(N, M2, Max, L, R)).
main :-
antiprimes(20, X),
write("The first twenty anti-primes are "), write(X), nl,
halt.
?- main.

View file

@ -0,0 +1,27 @@
Procedure.i cntDiv(n.i)
Define.i i, count
If n < 2 : ProcedureReturn 1 : EndIf
count = 2 : i = 2
While i <= n / 2
If n % i = 0 : count + 1 : EndIf
i + 1
Wend
ProcedureReturn count
EndProcedure
; - - - MAIN - - -
Define.i n = 1, d, maxDiv = 0, count = 0
If OpenConsole("")
PrintN("The first 20 anti-primes are: ")
While count < 20
d = cntDiv(n)
If d > maxDiv
Print(Str(n) + " ")
maxDiv = d : count + 1
EndIf
n + 1
Wend
PrintN("")
Input()
EndIf
End 0

View file

@ -0,0 +1,35 @@
from itertools import chain, count, cycle, islice, accumulate
def factors(n):
def prime_powers(n):
for c in accumulate(chain([2, 1, 2], cycle([2,4]))):
if c*c > n: break
if n%c: continue
d,p = (), c
while not n%c:
n,p,d = n//c, p*c, d+(p,)
yield d
if n > 1: yield n,
r = [1]
for e in prime_powers(n):
r += [a*b for a in r for b in e]
return r
def antiprimes():
mx = 0
yield 1
for c in count(2,2):
if c >= 58: break
ln = len(factors(c))
if ln > mx:
yield c
mx = ln
for c in count(60,30):
ln = len(factors(c))
if ln > mx:
yield c
mx = ln
if __name__ == '__main__':
print(*islice(antiprimes(), 40)))

View file

@ -0,0 +1,36 @@
MaxAntiPrime = 20
n = 0
MaxDivisors = 0
AntiPrimeCount = 0
PRINT "The first 20 anti-primes are: "
WHILE AntiPrimeCount < MaxAntiPrime
n = n + 1
Divisors = DivisorCount(n)
IF Divisors > MaxDivisors THEN
PRINT n;
MaxDivisors = Divisors
AntiPrimeCount = AntiPrimeCount + 1
END IF
WEND
END
FUNCTION DivisorCount (v)
total = 1
n = v
WHILE n MOD 2 = 0
total = total + 1
n = n \ 2
WEND
p = 3
WHILE (p * p) <= n
count = 1
WHILE n MOD p = 0
count = count + 1
n = n \ p
WEND
p = p + 2
total = total * count
WEND
IF n > 1 THEN total = total * 2
DivisorCount = total
END FUNCTION

View file

@ -0,0 +1,10 @@
0 temp put
[] 0
[ 1+ dup factors size
dup temp share > iff
[ temp replace
dup dip join ]
else drop
over size 20 = until ]
temp release
drop echo

View file

@ -0,0 +1,36 @@
' Anti-primes
DECLARE FUNCTION DivisorCount (V%)
MaxAntiPrime% = 20
N% = 0: MaxDivisors% = 0: AntiPrimeCount% = 0
WHILE AntiPrimeCount% < MaxAntiPrime%
N% = N% + 1
Divisors% = DivisorCount(N%)
IF Divisors% > MaxDivisors% THEN
PRINT STR$(N%);
MaxDivisors% = Divisors%
AntiPrimeCount% = AntiPrimeCount% + 1
END IF
WEND
PRINT
END
FUNCTION DivisorCount (V%)
Total% = 1: N% = V%
WHILE N% MOD 2 = 0
Total% = Total% + 1
N% = N% \ 2
WEND
P% = 3
WHILE (P% * P%) <= N%
Count% = 1
WHILE N% MOD P% = 0
Count% = Count% + 1
N% = N% \ P%
WEND
P% = P% + 2
Total% = Total% * Count%
WEND
IF N% > 1 THEN Total% = Total% * 2
DivisorCount = Total%
END FUNCTION

View file

@ -0,0 +1,23 @@
# Antiprimes
max_divisors <- 0
findFactors <- function(x){
myseq <- seq(x)
myseq[(x %% myseq) == 0]
}
antiprimes <- vector()
x <- 1
n <- 1
while(length(antiprimes) < 20){
y <- findFactors(x)
if (length(y) > max_divisors){
antiprimes <- c(antiprimes, x)
max_divisors <- length(y)
n <- n + 1
}
x <- x + 1
}
antiprimes

View file

@ -0,0 +1,40 @@
/*REXX program finds and displays N number of anti─primes or highly─composite numbers.*/
parse arg N . /*obtain optional argument from the CL.*/
if N=='' | N=="," then N= 20 /*Not specified? Then use the default.*/
maxD= 0 /*the maximum number of divisors so far*/
say 'index antiprime' /*display a title for the numbers shown*/
#= 0 /*the count of anti─primes found " " */
do once=1 for 1
do i=1 for 59 /*step through possible numbers by twos*/
d= #divs(i); if d<=maxD then iterate /*get # divisors; Is too small? Skip.*/
#= # + 1; maxD= d /*found an anti─prime #; set new minD.*/
say center(#, 7) right(i, 10) /*display the index and the anti─prime.*/
if #>=N then leave once /*if we have enough anti─primes, done. */
end /*i*/
do j=60 by 20 /*step through possible numbers by 20. */
d= #divs(j); if d<=maxD then iterate /*get # divisors; Is too small? Skip.*/
#= # + 1; maxD= d /*found an anti─prime #; set new minD.*/
say center(#, 7) right(j, 10) /*display the index and the anti─prime.*/
if #>=N then leave /*if we have enough anti─primes, done. */
end /*j*/
end /*once*/
exit /*stick a fork in it, we're all done. */
/*──────────────────────────────────────────────────────────────────────────────────────*/
#divs: procedure; parse arg x 1 y /*X and Y: both set from 1st argument.*/
if x<3 then return x /*handle special cases for one and two.*/
if x==4 then return 3 /* " " " " four. */
if x<6 then return 2 /* " " " " three or five*/
odd= x // 2 /*check if X is odd or not. */
if odd then #= 1 /*Odd? Assume Pdivisors count of 1.*/
else do; #= 3; y= x % 2 /*Even? " " " " 3.*/
end /* [↑] start with known num of Pdivs.*/
do k=3 for x%2-3 by 1+odd while k<y /*for odd numbers, skip evens.*/
if x//k==0 then do; #= # + 2 /*if no remainder, then found a divisor*/
y= x % k /*bump # Pdivs, calculate limit Y. */
if k>=y then do; #= # - 1; leave; end /*limit?*/
end /* ___ */
else if k*k>x then leave /*only divide up to √ x */
end /*k*/ /* [↑] this form of DO loop is faster.*/
return #+1 /*bump "proper divisors" to "divisors".*/

View file

@ -0,0 +1,38 @@
/*REXX program finds and displays N number of anti─primes or highly─composite numbers.*/
parse arg N . /*obtain optional argument from the CL.*/
if N=='' | N=="," then N= 20 /*Not specified? Then use the default.*/
@.= .; @.1= 1; @.2= 2; @.4= 3; @.5= 2; @.6= 4
say 'index antiprime' /*display a title for the numbers shown*/
#= 1 /*the count of anti─primes found " " */
maxD= 1 /*the maximum number of divisors so far*/
say center(#, 7) right(1, 10) /*display the index and the anti─prime.*/
do once=1 for 1
do i=2 by 2 to 59 /*step through possible numbers by twos*/
d= #divs(i); if d<=maxD then iterate /*get # divisors; Is too small? Skip.*/
#= # + 1; maxD= d /*found an anti─prime #; set new minD.*/
say center(#, 7) right(i, 10) /*display the index and the anti─prime.*/
if #>=N then leave once /*if we have enough anti─primes, done. */
end /*i*/
do j=60 by 20 /*step through possible numbers by 20. */
d= #divs(j); if d<=maxD then iterate /*get # divisors; Is too small? Skip.*/
#= # + 1; maxD= d /*found an anti─prime #; set new minD.*/
say center(#, 7) right(j, 10) /*display the index and the anti─prime.*/
if #>=N then leave once /*if we have enough anti─primes, done. */
L= length(j) /*obtain the length of the index (J). */
if L>3 then j= j + left(4, L-2, 0) - 20 /*Length>3? Then calculate a long jump*/
end /*j*/
end /*once*/
exit /*stick a fork in it, we're all done. */
/*──────────────────────────────────────────────────────────────────────────────────────*/
#divs: parse arg x; if @.x\==. then return @.x /*if pre─computed, then return shortcut*/
$= 3; y= x % 2
/* [↑] start with known num of Pdivs.*/
do k=3 for x%2-3 while k<y
if x//k==0 then do; $= $ + 2 /*if no remainder, then found a divisor*/
y= x % k /*bump $ Pdivs, calculate limit Y. */
if k>=y then do; $= $ - 1; leave; end /*limit?*/
end /* ___ */
else if k*k>x then leave /*only divide up to √ x */
end /*k*/ /* [↑] this form of DO loop is faster.*/
return $+1 /*bump "proper divisors" to "divisors".*/

View file

@ -0,0 +1,16 @@
#lang racket
(require racket/generator
math/number-theory)
(define (get-divisors n)
(apply * (map (λ (factor) (add1 (second factor))) (factorize n))))
(define antiprimes
(in-generator
(for/fold ([prev 0]) ([i (in-naturals 1)])
(define divisors (get-divisors i))
(when (> divisors prev) (yield i))
(max prev divisors))))
(for/list ([i (in-range 20)] [antiprime antiprimes]) antiprime)

View file

@ -0,0 +1,22 @@
sub propdiv (\x) {
my @l = 1 if x > 1;
(2 .. x.sqrt.floor).map: -> \d {
unless x % d { @l.push: d; my \y = x div d; @l.push: y if y != d }
}
@l
}
my $last = 0;
my @anti-primes = lazy 1, |(|(2..59), 60, *+60 *).grep: -> $c {
my \mx = +propdiv($c);
next if mx <= $last;
$last = mx;
$c
}
my $upto = 5e5;
put "First 20 anti-primes:\n{ @anti-primes[^20] }";
put "\nCount of anti-primes <= $upto: {+@anti-primes[^(@anti-primes.first: * > $upto, :k)]}";

View file

@ -0,0 +1,14 @@
Red []
inc: func ['v] [set v 1 + get v] ;; shortcut function for n: n + 1
n: 0 found: 0 max_div: 0
print "the first 20 anti-primes are:"
while [ inc n] [
nDiv: 1 ;; count n / n extra
if n > 1 [ repeat div n / 2 [ if n % div = 0 [inc nDiv] ] ]
if nDiv > max_div [
max_div: nDiv
prin [n ""]
if 20 <= inc found [halt]
]
]

View file

@ -0,0 +1,39 @@
# Project : Anti-primes
see "working..." + nl
see "wait for done..." + nl + nl
see "the first 20 anti-primes are:" + nl + nl
maxDivisor = 0
num = 0
n = 0
result = list(20)
while num < 20
n = n + 1
div = factors(n)
if (div > maxDivisor)
maxDivisor = div
num = num + 1
result[num] = n
ok
end
see "["
for n = 1 to len(result)
if n < len(result)
see string(result[n]) + ","
else
see string(result[n]) + "]" + nl + nl
ok
next
see "done..." + nl
func factors(an)
ansum = 2
if an < 2
return(1)
ok
for nr = 2 to an/2
if an%nr = 0
ansum = ansum+1
ok
next
return ansum

View file

@ -0,0 +1,18 @@
require 'prime'
def num_divisors(n)
n.prime_division.inject(1){|prod, (_p,n)| prod *= (n + 1) }
end
anti_primes = Enumerator.new do |y| # y is the yielder
max = 0
y << 1 # yield 1
2.step(nil,2) do |candidate| # nil is taken as Infinity
num = num_divisors(candidate)
if num > max
y << candidate # yield the candidate
max = num
end
end
end
puts anti_primes.take(20).join(" ")

View file

@ -0,0 +1,36 @@
MaxAntiPrime = 20
n = 0
MaxDivisors = 0
AntiPrimeCount = 0
print "The first 20 anti-primes are: "
while AntiPrimeCount < MaxAntiPrime
n = n +1
Divisors = DivisorCount(n)
if Divisors > MaxDivisors then
print n; " ";
MaxDivisors = Divisors
AntiPrimeCount = AntiPrimeCount +1
end if
wend
end
function DivisorCount(v)
total = 1
n = v
while n mod 2 = 0
total = total +1
n = int(n / 2)
wend
p = 3
while (p * p) <= n
count = 1
while n mod p = 0
count = count +1
n = int(n / p)
wend
p = p +2
total = total * count
wend
if n > 1 then total = total *2
DivisorCount = total
end function

View file

@ -0,0 +1,24 @@
fn count_divisors(n: u64) -> usize {
if n < 2 {
return 1;
}
2 + (2..=(n / 2)).filter(|i| n % i == 0).count()
}
fn main() {
println!("The first 20 anti-primes are:");
(1..)
.scan(0, |max, n| {
let d = count_divisors(n);
Some(if d > *max {
*max = d;
Some(n)
} else {
None
})
})
.flatten()
.take(20)
.for_each(|n| print!("{} ", n));
println!();
}

View file

@ -0,0 +1,2 @@
def factorCount(num: Int): Int = Iterator.range(1, num/2 + 1).count(num%_ == 0) + 1
def antiPrimes: LazyList[Int] = LazyList.iterate((1: Int, 1: Int)){case (n, facs) => Iterator.from(n + 1).map(i => (i, factorCount(i))).dropWhile(_._2 <= facs).next}.map(_._1)

View file

@ -0,0 +1,34 @@
$ include "seed7_05.s7i";
const func integer: countDivisors (in integer: number) is func
result
var integer: count is 1;
local
var integer: num is 0;
begin
for num range 1 to number div 2 do
if number rem num = 0 then
incr(count);
end if;
end for;
end func;
const proc: main is func
local
var integer: maxDiv is 0;
var integer: count is 0;
var integer: number is 1;
var integer: divisors is 1;
begin
writeln("The first 20 anti-primes are:");
while count < 20 do
divisors := countDivisors(number);
if divisors > maxDiv then
write(number <& " ");
maxDiv := divisors;
incr(count);
end if;
incr(number);
end while;
writeln;
end func;

View file

@ -0,0 +1,3 @@
say with (0) {|max|
1..Inf -> lazy.grep { (.sigma0 > max) && (max = .sigma0) }.first(20)
}

View file

@ -0,0 +1,54 @@
extension BinaryInteger {
@inlinable
public func countDivisors() -> Int {
var workingN = self
var count = 1
while workingN & 1 == 0 {
workingN >>= 1
count += 1
}
var d = Self(3)
while d * d <= workingN {
var (quo, rem) = workingN.quotientAndRemainder(dividingBy: d)
if rem == 0 {
var dc = 0
while rem == 0 {
dc += count
workingN = quo
(quo, rem) = workingN.quotientAndRemainder(dividingBy: d)
}
count += dc
}
d += 2
}
return workingN != 1 ? count * 2 : count
}
}
var antiPrimes = [Int]()
var maxDivs = 0
for n in 1... {
guard antiPrimes.count < 20 else {
break
}
let divs = n.countDivisors()
if maxDivs < divs {
maxDivs = divs
antiPrimes.append(n)
}
}
print("First 20 anti-primes are \(Array(antiPrimes))")

View file

@ -0,0 +1,23 @@
proc countDivisors {n} {
if {$n < 2} {return 1}
set count 2
set n2 [expr $n / 2]
for {set i 2} {$i <= $n2} {incr i} {
if {[expr $n % $i] == 0} {incr count}
}
return $count
}
# main
set maxDiv 0
set count 0
puts "The first 20 anti-primes are:"
for {set n 1} {$count < 20} {incr n} {
set d [countDivisors $n]
if {$d > $maxDiv} {
puts $n
set maxDiv $d
incr count
}
}

View file

@ -0,0 +1,27 @@
100 REM Anti-primes
110 LET A=0
120 LET N=1
130 LET H=0
140 PRINT "The first 20 anti-primes are:"
150 GOSUB 300
160 LET H=F
170 LET A=A+1
180 PRINT N
190 LET N=N+1
200 IF A<20 THEN GOTO 150
210 END
290 REM Search next anti-prime
300 GOSUB 400
310 IF F>H THEN RETURN
320 LET N=N+1
330 GOTO 300
390 REM Count divisors
400 LET F=1
410 IF N>1 THEN LET F=2
420 LET C=2
430 IF C*C>=N THEN GOTO 470
440 IF (N/C)*C=N THEN LET F=F+2
450 LET C=C+1
460 GOTO 430
470 IF C*C=N THEN LET F=F+1
480 RETURN

View file

@ -0,0 +1,19 @@
#lang transd
MainModule: {
countDivs: (λ n Int() ret_ Int()
(= ret_ 2)
(for i in Range(2 (to-Int (/ (to-Double n) 2) 1)) do
(if (not (mod n i)) (+= ret_ 1)))
(ret ret_)
),
_start: (λ locals: max 0 tmp 0 N 1 i 2
(textout 1 " ")
(while (< N 20)
(= tmp (countDivs i))
(if (> tmp max)
(textout i " ") (= max tmp) (+= N 1))
(+= i 1)
))
}

Some files were not shown because too many files have changed in this diff Show more