Data update
This commit is contained in:
parent
5150844a7d
commit
4bb20c9b71
7735 changed files with 38060 additions and 199180 deletions
|
|
@ -1,4 +1,4 @@
|
|||
[[wp:Smith numbers|Smith numbers]] are numbers such that the [[Sum_digits_of_an_integer|sum of the decimal digits of the integers]] that make up that number is the same as the sum of the decimal digits of its prime factors excluding 1.
|
||||
[[wp:Smith numbers|Smith numbers]] are numbers such that the [[Sum_digits_of_an_integer|sum of the decimal digits of the integers]] that make up that number is the same as the sum of the decimal digits of its prime factors excluding the number itself.
|
||||
|
||||
By definition, all primes are ''excluded'' as they (naturally) satisfy this condition!
|
||||
|
||||
|
|
|
|||
|
|
@ -1,27 +0,0 @@
|
|||
with Ada.Text_IO;
|
||||
|
||||
procedure smith is
|
||||
type Vector is array (natural range <>) of Positive;
|
||||
empty_vector : constant Vector(1..0):= (others=>1);
|
||||
|
||||
function digits_sum (n : Positive) return Positive is
|
||||
(if n < 10 then n else n mod 10 + digits_sum (n / 10));
|
||||
|
||||
function prime_factors (n : Positive; d : Positive := 2) return Vector is
|
||||
(if n = 1 then empty_vector elsif n mod d = 0 then prime_factors (n / d, d) & d
|
||||
else prime_factors (n, d + (if d=2 then 1 else 2)));
|
||||
|
||||
function vector_digits_sum (v : Vector) return Natural is
|
||||
(if v'Length = 0 then 0 else digits_sum (v(v'First)) + vector_digits_sum (v(v'First+1..v'Last)));
|
||||
|
||||
begin
|
||||
for n in 1..10000 loop
|
||||
declare
|
||||
primes : Vector := prime_factors (n);
|
||||
begin
|
||||
if primes'Length > 1 and then vector_digits_sum (primes) = digits_sum (n) then
|
||||
Ada.Text_IO.put (n'img);
|
||||
end if;
|
||||
end;
|
||||
end loop;
|
||||
end smith;
|
||||
|
|
@ -1,24 +1,8 @@
|
|||
digitSum: function [v][
|
||||
n: new v
|
||||
result: new 0
|
||||
while [n > 0][
|
||||
'result + n % 10
|
||||
'n / 10
|
||||
]
|
||||
return result
|
||||
smith?: function [z][
|
||||
(prime? z) ? -> false
|
||||
-> (sum digits z) = sum map factors.prime z 'num [sum digits num]
|
||||
]
|
||||
|
||||
smith?: function [z][
|
||||
return
|
||||
(prime? z) ? -> false
|
||||
-> (digitSum z) = sum map factors.prime z 'num [digitSum num]
|
||||
loop split.every:10 select 1..10000 => smith? 'row [
|
||||
print map row 'r -> pad to :string r 6
|
||||
]
|
||||
found: 0
|
||||
loop 1..10000 'x [
|
||||
if smith? x [
|
||||
found: found + 1
|
||||
prints (pad to :string x 6) ++ " "
|
||||
if 0 = found % 10 -> print ""
|
||||
]
|
||||
]
|
||||
print ""
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue