Data update
This commit is contained in:
parent
5150844a7d
commit
4bb20c9b71
7735 changed files with 38060 additions and 199180 deletions
|
|
@ -1,42 +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 ' $'
|
||||
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 ' $'
|
||||
|
|
|
|||
|
|
@ -1,38 +0,0 @@
|
|||
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;
|
||||
|
|
@ -4,22 +4,22 @@ 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];" ";
|
||||
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
|
||||
cont = 1
|
||||
For i = 1 To n/2
|
||||
If (n % i) = 0 Then cont += 1
|
||||
Next i
|
||||
count_divisors = cont
|
||||
End Function
|
||||
|
|
|
|||
|
|
@ -1,12 +1,12 @@
|
|||
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++) {
|
||||
|
|
@ -16,7 +16,7 @@ public static class Program
|
|||
yield return i;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
int CountDivisors(int n) => Enumerable.Range(1, n / 2).Count(i => n % i == 0) + 1;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,84 +0,0 @@
|
|||
******************************************************************
|
||||
* 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
|
||||
******************************************************************
|
||||
|
|
@ -1,5 +1,4 @@
|
|||
func divcnt v .
|
||||
n = v
|
||||
func divcnt n .
|
||||
tot = 1
|
||||
p = 2
|
||||
while p <= sqrt n
|
||||
|
|
|
|||
|
|
@ -1,31 +1,33 @@
|
|||
defmodule AntiPrimes do
|
||||
def divcount(n) when is_integer(n), do: divcount(n, 1, 0)
|
||||
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 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(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 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
|
||||
def main() do
|
||||
:io.format("The first 20 anti-primes are ~w~n", [antiprimes(20)])
|
||||
end
|
||||
end
|
||||
|
||||
AntiPrimes.main()
|
||||
|
|
|
|||
|
|
@ -1,33 +1,33 @@
|
|||
-- 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
|
||||
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
|
||||
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
|
||||
for index, item in ipairs(list) do
|
||||
print(item)
|
||||
end
|
||||
end
|
||||
|
||||
print("The first 20 antiprimes:")
|
||||
|
|
|
|||
|
|
@ -1,14 +1,14 @@
|
|||
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
|
||||
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
|
||||
|
|
@ -16,11 +16,11 @@ 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
|
||||
d = countDivisors(n)
|
||||
if d > maxDiv
|
||||
print format("%d ", n)
|
||||
maxDiv = d
|
||||
count += 1
|
||||
end
|
||||
end
|
||||
println
|
||||
|
|
|
|||
|
|
@ -12,12 +12,15 @@ MODULE AntiPrimes;
|
|||
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;
|
||||
IF N < 2 THEN
|
||||
Facts := 1
|
||||
ELSE
|
||||
Facts := 2;
|
||||
FOR Div := 2 TO N DIV 2 DO
|
||||
IF N MOD Div = 0 THEN INC(Facts) END
|
||||
END
|
||||
END;
|
||||
RETURN Facts;
|
||||
RETURN Facts
|
||||
END Factors;
|
||||
|
||||
BEGIN
|
||||
|
|
|
|||
|
|
@ -2,41 +2,41 @@ package antiprimes
|
|||
import "core:fmt"
|
||||
|
||||
main :: proc() {
|
||||
AntiPrimeCount, MaxDivisors, Divisors, n: u64
|
||||
MaxAntiPrime: u64 = 20
|
||||
fmt.print("\nFirst 20 anti-primes\n")
|
||||
fmt.println("--------------------")
|
||||
for (AntiPrimeCount < MaxAntiPrime) {
|
||||
n += 1
|
||||
Divisors = DivisorCount(n)
|
||||
if Divisors > MaxDivisors {
|
||||
fmt.print(n, " ")
|
||||
MaxDivisors = Divisors
|
||||
AntiPrimeCount += 1
|
||||
}
|
||||
}
|
||||
AntiPrimeCount, MaxDivisors, Divisors, n: u64
|
||||
MaxAntiPrime: u64 = 20
|
||||
fmt.print("\nFirst 20 anti-primes\n")
|
||||
fmt.println("--------------------")
|
||||
for (AntiPrimeCount < MaxAntiPrime) {
|
||||
n += 1
|
||||
Divisors = DivisorCount(n)
|
||||
if Divisors > MaxDivisors {
|
||||
fmt.print(n, " ")
|
||||
MaxDivisors = Divisors
|
||||
AntiPrimeCount += 1
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
DivisorCount :: proc(v: u64) -> u64 {
|
||||
total: u64 = 1
|
||||
a := v
|
||||
if a == 0 {
|
||||
return 0
|
||||
}
|
||||
for a % 2 == 0 {
|
||||
total += 1
|
||||
a /= 2
|
||||
}
|
||||
for p: u64 = 3; p * p <= a; p += 2 {
|
||||
count: u64 = 1
|
||||
for a % p == 0 {
|
||||
count += 1
|
||||
a /= p
|
||||
}
|
||||
total *= count
|
||||
}
|
||||
if a > 1 {
|
||||
total *= 2
|
||||
}
|
||||
return total
|
||||
total: u64 = 1
|
||||
a := v
|
||||
if a == 0 {
|
||||
return 0
|
||||
}
|
||||
for a % 2 == 0 {
|
||||
total += 1
|
||||
a /= 2
|
||||
}
|
||||
for p: u64 = 3; p * p <= a; p += 2 {
|
||||
count: u64 = 1
|
||||
for a % p == 0 {
|
||||
count += 1
|
||||
a /= p
|
||||
}
|
||||
total *= count
|
||||
}
|
||||
if a > 1 {
|
||||
total *= 2
|
||||
}
|
||||
return total
|
||||
}
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@ do -- Find the first 20 antiprimes.
|
|||
ndc = {}
|
||||
for i = 1, maxNumber do ndc[ i ] = 1 end
|
||||
for i = 2, maxNumber do
|
||||
for j = i, maxNumber, i do ++ ndc[ j ] end
|
||||
for j = i, maxNumber, i do ndc[ j ] += 1 end
|
||||
end
|
||||
end
|
||||
local factors = ndc[ number ]
|
||||
|
|
@ -22,7 +22,7 @@ do -- Find the first 20 antiprimes.
|
|||
table.insert( list, number )
|
||||
mostFactors = factors
|
||||
end
|
||||
++ number
|
||||
number += 1
|
||||
end
|
||||
return list
|
||||
end
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
-- 8 May 2025
|
||||
include Settings
|
||||
-- 23 Aug 2025
|
||||
include Setting
|
||||
arg xx
|
||||
if xx = '' then
|
||||
xx = 1500000
|
||||
|
|
@ -25,8 +25,4 @@ say
|
|||
call Timer
|
||||
exit
|
||||
|
||||
include Numbers
|
||||
include Functions
|
||||
include Special
|
||||
include Helper
|
||||
include Abend
|
||||
include Math
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
-- 8 May 2025
|
||||
include Settings
|
||||
-- 23 Aug 2025
|
||||
include Setting
|
||||
arg xx
|
||||
if xx = '' then
|
||||
xx = 1500000
|
||||
|
|
@ -25,9 +25,4 @@ say
|
|||
call Timer
|
||||
exit
|
||||
|
||||
include Numbers
|
||||
include Functions
|
||||
include Special
|
||||
include Sequences
|
||||
include Helper
|
||||
include Abend
|
||||
include Math
|
||||
|
|
|
|||
|
|
@ -1,10 +1,10 @@
|
|||
fcn properDivsN(n) //--> count of proper divisors. 1-->1, wrong but OK here
|
||||
{ [1.. (n + 1)/2 + 1].reduce('wrap(p,i){ p + (n%i==0 and n!=i) }) }
|
||||
fcn antiPrimes{ // -->iterator
|
||||
fcn antiPrimes{ // -->iterator
|
||||
Walker.chain([2..59],[60..*,30]).tweak(fcn(c,rlast){
|
||||
last,mx := rlast.value, properDivsN(c);
|
||||
if(mx<=last) return(Void.Skip);
|
||||
rlast.set(mx);
|
||||
c
|
||||
}.fp1(Ref(0))).push(1); // 1 has no proper divisors
|
||||
}.fp1(Ref(0))).push(1); // 1 has no proper divisors
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue