Data update
This commit is contained in:
parent
4bb20c9b71
commit
cbaf4c4b64
12390 changed files with 318560 additions and 27248 deletions
27
Task/Smith-numbers/Ada/smith-numbers.adb
Normal file
27
Task/Smith-numbers/Ada/smith-numbers.adb
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
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;
|
||||
23
Task/Smith-numbers/Frink/smith-numbers.frink
Normal file
23
Task/Smith-numbers/Frink/smith-numbers.frink
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
/** Solver for the Rosetta Code problem Smith numbers
|
||||
|
||||
https://rosettacode.org/wiki/Smith_numbers
|
||||
*/
|
||||
for n = 2 to 10000
|
||||
if isSmith[n]
|
||||
print["$n "]
|
||||
|
||||
println[]
|
||||
|
||||
isSmith[n] :=
|
||||
{
|
||||
if isPrime[n]
|
||||
return false
|
||||
sn = sumDigits[n]
|
||||
ss = 0
|
||||
for [b,p] = factor[n]
|
||||
ss = ss + sumDigits[b] * p
|
||||
|
||||
return sn == ss
|
||||
}
|
||||
|
||||
sumDigits[n] := sum[integerDigits[n]]
|
||||
|
|
@ -1,7 +1,7 @@
|
|||
N ← 10000
|
||||
Primes ← ⇌◌⍢(⊃(▽≠0◿⊢..|⊂⊢)|>0⧻)⊙[]↘2⇡N
|
||||
Candidates ← ▽¬∊:Primes.↘2⇡ # Exclude primes
|
||||
SumD ← /+≡⋕°⋕
|
||||
PrimeDivisors ← ◌◌⍢(⟜(÷/×)⟜(⊙⊂:)▽:⟜(=0◿)⊙.|⋅(>1))Primes ⊙[]
|
||||
Smith ← ▽⊸≡(=⊃(SumD|/+≡SumD PrimeDivisors))
|
||||
N ← 10000
|
||||
Primes ← ⇌◌⍢(⊃(▽≠0◿⊸⊸⊢|⊂⊢)|>0⧻)⊙[]↘2⇡N
|
||||
Candidates ← ▽¬⊸∊Primes↘2⇡ # Exclude primes
|
||||
SumD ← /+≡⋕°⋕
|
||||
PrimeDivisors ← ◌◌⍢(⟜(÷/×)⟜(⊙⊂⊃⋅∘∘)˜▽⟜(=0◿)⊙⟜∘|⋅>₁)Primes ⊙[]
|
||||
Smith ← ▽⊸≡(=⊃(SumD|/+≡SumD PrimeDivisors))
|
||||
⟜⧻ Smith Candidates N
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue