Smith numbers: Difference between revisions

m
→‎{{header|BASIC}}: fix syntax highlighting
m (syntax highlighting fixup automation)
m (→‎{{header|BASIC}}: fix syntax highlighting)
 
(21 intermediate revisions by 9 users not shown)
Line 268:
</pre>
 
=={{header|ABC}}==
<syntaxhighlight lang="ABC">HOW TO RETURN factors n:
PUT {} IN factors
PUT 2 IN factor
WHILE n >= factor:
SELECT:
n mod factor = 0:
INSERT factor IN factors
PUT n/factor IN n
ELSE:
PUT factor+1 IN factor
RETURN factors
 
HOW TO RETURN digit.sum n:
PUT 0 IN sum
WHILE n > 0:
PUT sum + (n mod 10) IN sum
PUT floor (n/10) IN n
RETURN sum
 
HOW TO REPORT smith.number n:
PUT factors n IN facs
IF #facs = 1: FAIL
PUT 0 IN fac.dsum
FOR fac IN facs:
PUT fac.dsum + digit.sum fac IN fac.dsum
REPORT fac.dsum = digit.sum n
 
PUT 0 IN col
FOR i IN {1..9999}:
IF smith.number i:
WRITE (i>>5)
PUT col+1 IN col
IF col=16:
WRITE /
PUT 0 IN col
WRITE /</syntaxhighlight>
{{out}}
<pre> 4 22 27 58 85 94 121 166 202 265 274 319 346 355 378 382
391 438 454 483 517 526 535 562 576 588 627 634 636 645 648 654
663 666 690 706 728 729 762 778 825 852 861 895 913 915 922 958
985 1086 1111 1165 1219 1255 1282 1284 1376 1449 1507 1581 1626 1633 1642 1678
1736 1755 1776 1795 1822 1842 1858 1872 1881 1894 1903 1908 1921 1935 1952 1962
1966 2038 2067 2079 2155 2173 2182 2218 2227 2265 2286 2326 2362 2366 2373 2409
2434 2461 2475 2484 2515 2556 2576 2578 2583 2605 2614 2679 2688 2722 2745 2751
2785 2839 2888 2902 2911 2934 2944 2958 2964 2965 2970 2974 3046 3091 3138 3168
3174 3226 3246 3258 3294 3345 3366 3390 3442 3505 3564 3595 3615 3622 3649 3663
3690 3694 3802 3852 3864 3865 3930 3946 3973 4054 4126 4162 4173 4185 4189 4191
4198 4209 4279 4306 4369 4414 4428 4464 4472 4557 4592 4594 4702 4743 4765 4788
4794 4832 4855 4880 4918 4954 4959 4960 4974 4981 5062 5071 5088 5098 5172 5242
5248 5253 5269 5298 5305 5386 5388 5397 5422 5458 5485 5526 5539 5602 5638 5642
5674 5772 5818 5854 5874 5915 5926 5935 5936 5946 5998 6036 6054 6084 6096 6115
6171 6178 6187 6188 6252 6259 6295 6315 6344 6385 6439 6457 6502 6531 6567 6583
6585 6603 6684 6693 6702 6718 6760 6816 6835 6855 6880 6934 6981 7026 7051 7062
7068 7078 7089 7119 7136 7186 7195 7227 7249 7287 7339 7402 7438 7447 7465 7503
7627 7674 7683 7695 7712 7726 7762 7764 7782 7784 7809 7824 7834 7915 7952 7978
8005 8014 8023 8073 8077 8095 8149 8154 8158 8185 8196 8253 8257 8277 8307 8347
8372 8412 8421 8466 8518 8545 8568 8628 8653 8680 8736 8754 8766 8790 8792 8851
8864 8874 8883 8901 8914 9015 9031 9036 9094 9166 9184 9193 9229 9274 9276 9285
9294 9296 9301 9330 9346 9355 9382 9386 9387 9396 9414 9427 9483 9522 9535 9571
9598 9633 9634 9639 9648 9657 9684 9708 9717 9735 9742 9760 9778 9840 9843 9849
9861 9880 9895 9924 9942 9968 9975 9985</pre>
=={{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.
Line 456 ⟶ 518:
9895 9924 9942 9968 9975 9985
THere are 376 Smith numbers below 10000
</pre>
 
=={{header|Amazing Hopper}}==
<syntaxhighlight lang="c">
#include <basico.h>
 
#proto muestranúmeroencontrado(_X_)
 
algoritmo
 
resultado={}, primos="", suma1=0, suma2=0 , i=1
temp_primos=0,
fijar separador 'NULO'
decimales '0'
iterar para ( num=4, #(num<=10000), ++num )
ir por el siguiente si ' es primo(num) '
obtener divisores de (num);
luego obtener los primos de esto para 'primos'
 
sumar los dígitos de 'num'; guardar en 'suma2'
/* análisis p-ádico */
guardar 'primos' en 'temp_primos'
iterar para(q=1, #( q<=length(temp_primos) ) , ++q )
iterar para( r=2, #( (num % (temp_primos[q]^r)) == 0 ), ++r )
#(temp_primos[q]); meter en 'primos'
siguiente
siguiente
sumar dígitos de cada número de 'primos'
guardar en 'suma1'
 
'suma1' respecto a 'suma2' son iguales?
entonces{
_muestra número encontrado 'num'
}
siguiente
terminar
 
subrutinas
 
muestra número encontrado (x)
imprimir ( #(lpad(" ",4,string(x))), solo si ( #(i<8), " " ) )
++i
cuando ( #(i>8) ){
saltar, guardar '1' en 'i'
}
retornar
 
</syntaxhighlight>
{{out}}
<pre>
4 22 27 58 85 94 121 166
202 265 274 319 346 355 378 382
391 438 454 483 517 526 535 562
576 588 627 634 636 645 648 654
663 666 690 706 728 729 762 778
825 852 861 895 913 915 922 958
985 1086 1111 1165 1219 1255 1282 1284
1376 1449 1507 1581 1626 1633 1642 1678
1736 1755 1776 1795 1822 1842 1858 1872
1881 1894 1903 1908 1921 1935 1952 1962
1966 2038 2067 2079 2155 2173 2182 2218
2227 2265 2286 2326 2362 2366 2373 2409
2434 2461 2475 2484 2515 2556 2576 2578
2583 2605 2614 2679 2688 2722 2745 2751
2785 2839 2888 2902 2911 2934 2944 2958
2964 2965 2970 2974 3046 3091 3138 3168
3174 3226 3246 3258 3294 3345 3366 3390
3442 3505 3564 3595 3615 3622 3649 3663
3690 3694 3802 3852 3864 3865 3930 3946
3973 4054 4126 4162 4173 4185 4189 4191
4198 4209 4279 4306 4369 4414 4428 4464
4472 4557 4592 4594 4702 4743 4765 4788
4794 4832 4855 4880 4918 4954 4959 4960
4974 4981 5062 5071 5088 5098 5172 5242
5248 5253 5269 5298 5305 5386 5388 5397
5422 5458 5485 5526 5539 5602 5638 5642
5674 5772 5818 5854 5874 5915 5926 5935
5936 5946 5998 6036 6054 6084 6096 6115
6171 6178 6187 6188 6252 6259 6295 6315
6344 6385 6439 6457 6502 6531 6567 6583
6585 6603 6684 6693 6702 6718 6760 6816
6835 6855 6880 6934 6981 7026 7051 7062
7068 7078 7089 7119 7136 7186 7195 7227
7249 7287 7339 7402 7438 7447 7465 7503
7627 7674 7683 7695 7712 7726 7762 7764
7782 7784 7809 7824 7834 7915 7952 7978
8005 8014 8023 8073 8077 8095 8149 8154
8158 8185 8196 8253 8257 8277 8307 8347
8372 8412 8421 8466 8518 8545 8568 8628
8653 8680 8736 8754 8766 8790 8792 8851
8864 8874 8883 8901 8914 9015 9031 9036
9094 9166 9184 9193 9229 9274 9276 9285
9294 9296 9301 9330 9346 9355 9382 9386
9387 9396 9414 9427 9483 9522 9535 9571
9598 9633 9634 9639 9648 9657 9684 9708
9717 9735 9742 9760 9778 9840 9843 9849
9861 9880 9895 9924 9942 9968 9975 9985
 
</pre>
 
Line 636 ⟶ 800:
 
=={{header|BASIC}}==
<syntaxhighlight lang="gwbasicbasic">10 DEFINT A-Z
20 DIM F(32)
30 FOR I=2 TO 9999
Line 1,372 ⟶ 1,536:
 
=={{header|Delphi}}==
See [https://rosettacode.org/wiki/Smith_numbers[Smith numbers#Pascal |Pascal]].
 
=={{header|Draco}}==
<syntaxhighlight lang="draco">/* Find the sum of the digits of a number */
Line 1,470 ⟶ 1,635:
9861 9880 9895 9924 9942 9968 9975 9985
Found 376 Smith numbers.</pre>
 
=={{header|EasyLang}}==
<syntaxhighlight>
proc prim_fact x . pf[] .
pf[] = [ ]
p = 2
repeat
if x mod p = 0
pf[] &= p
x = x div p
else
p += 1
.
until x = 1
.
.
func digsum x .
while x > 0
sum += x mod 10
x = x div 10
.
return sum
.
for i = 2 to 9999
prim_fact i pf[]
if len pf[] >= 2
sum = 0
for e in pf[]
sum += digsum e
.
if digsum i = sum
write i & " "
.
.
.
</syntaxhighlight>
 
=={{header|Elixir}}==
Line 1,587 ⟶ 1,788:
9895 9924 9942 9968 9975 9985
</pre>
 
=={{header|FOCAL}}==
<syntaxhighlight lang="focal">01.10 S C=0
01.20 T %4
01.30 F I=1,10000;D 4
01.40 T !
01.50 Q
 
02.10 S Z=N
02.20 S S=0
02.30 S Y=FITR(Z/10)
02.40 S S=S+(Z-Y*10)
02.50 S Z=Y
02.60 I (-Z)2.3
 
03.05 S V=0;S Z=N
03.10 S Y=FITR(Z/2)
03.15 I (Z-Y*2)3.3,3.2,3.3
03.20 S V=V+1;S V(V)=2
03.25 S Z=Y;G 3.1
03.30 S X=3
03.35 I (Z-X)3.65,3.4,3.4
03.40 S Y=FITR(Z/X)
03.45 I (Z-Y*X)3.6,3.5,3.6
03.50 S V=V+1;S V(V)=X
03.55 S Z=Y;G 3.35
03.60 S X=X+2;G 3.35
03.65 R
 
04.10 S N=I;D 3
04.20 I (V-1)4.3,4.9,4.3
04.30 D 2;S A=S
04.40 S B=0
04.50 F K=1,V;S N=V(K);D 2;S B=B+S
04.60 I (A-B)4.9,4.7,4.9
04.70 T I;S C=C+1;I (C-FITR(C/13)*13)4.9,4.8,4.9
04.80 T !
04.90 R</syntaxhighlight>
{{out}}
<pre>= 4= 22= 27= 58= 85= 94= 121= 166= 202= 265= 274= 319= 346
= 355= 378= 382= 391= 438= 454= 483= 517= 526= 535= 562= 576= 588
= 627= 634= 636= 645= 648= 654= 663= 666= 690= 706= 728= 729= 762
= 778= 825= 852= 861= 895= 913= 915= 922= 958= 985= 1086= 1111= 1165
= 1219= 1255= 1282= 1284= 1376= 1449= 1507= 1581= 1626= 1633= 1642= 1678= 1736
= 1755= 1776= 1795= 1822= 1842= 1858= 1872= 1881= 1894= 1903= 1908= 1921= 1935
= 1952= 1962= 1966= 2038= 2067= 2079= 2155= 2173= 2182= 2218= 2227= 2265= 2286
= 2326= 2362= 2366= 2373= 2409= 2434= 2461= 2475= 2484= 2515= 2556= 2576= 2578
= 2583= 2605= 2614= 2679= 2688= 2722= 2745= 2751= 2785= 2839= 2888= 2902= 2911
= 2934= 2944= 2958= 2964= 2965= 2970= 2974= 3046= 3091= 3138= 3168= 3174= 3226
= 3246= 3258= 3294= 3345= 3366= 3390= 3442= 3505= 3564= 3595= 3615= 3622= 3649
= 3663= 3690= 3694= 3802= 3852= 3864= 3865= 3930= 3946= 3973= 4054= 4126= 4162
= 4173= 4185= 4189= 4191= 4198= 4209= 4279= 4306= 4369= 4414= 4428= 4464= 4472
= 4557= 4592= 4594= 4702= 4743= 4765= 4788= 4794= 4832= 4855= 4880= 4918= 4954
= 4959= 4960= 4974= 4981= 5062= 5071= 5088= 5098= 5172= 5242= 5248= 5253= 5269
= 5298= 5305= 5386= 5388= 5397= 5422= 5458= 5485= 5526= 5539= 5602= 5638= 5642
= 5674= 5772= 5818= 5854= 5874= 5915= 5926= 5935= 5936= 5946= 5998= 6036= 6054
= 6084= 6096= 6115= 6171= 6178= 6187= 6188= 6252= 6259= 6295= 6315= 6344= 6385
= 6439= 6457= 6502= 6531= 6567= 6583= 6585= 6603= 6684= 6693= 6702= 6718= 6760
= 6816= 6835= 6855= 6880= 6934= 6981= 7026= 7051= 7062= 7068= 7078= 7089= 7119
= 7136= 7186= 7195= 7227= 7249= 7287= 7339= 7402= 7438= 7447= 7465= 7503= 7627
= 7674= 7683= 7695= 7712= 7726= 7762= 7764= 7782= 7784= 7809= 7824= 7834= 7915
= 7952= 7978= 8005= 8014= 8023= 8073= 8077= 8095= 8149= 8154= 8158= 8185= 8196
= 8253= 8257= 8277= 8307= 8347= 8372= 8412= 8421= 8466= 8518= 8545= 8568= 8628
= 8653= 8680= 8736= 8754= 8766= 8790= 8792= 8851= 8864= 8874= 8883= 8901= 8914
= 9015= 9031= 9036= 9094= 9166= 9184= 9193= 9229= 9274= 9276= 9285= 9294= 9296
= 9301= 9330= 9346= 9355= 9382= 9386= 9387= 9396= 9414= 9427= 9483= 9522= 9535
= 9571= 9598= 9633= 9634= 9639= 9648= 9657= 9684= 9708= 9717= 9735= 9742= 9760
= 9778= 9840= 9843= 9849= 9861= 9880= 9895= 9924= 9942= 9968= 9975= 9985</pre>
 
=={{header|Fortran}}==
Line 1,857 ⟶ 2,126:
=={{header|Fōrmulæ}}==
 
{{FormulaeEntry|page=https://formulae.org/?script=examples/Smith_numbers}}
Fōrmulæ programs are not textual, visualization/edition of programs is done showing/manipulating structures but not text. Moreover, there can be multiple visual representations of the same program. Even though it is possible to have textual representation &mdash;i.e. XML, JSON&mdash; they are intended for storage and transfer purposes more than visualization and edition.
 
'''Solution'''
 
[[File:Fōrmulæ - Smith numbers 01.png]]
 
'''Test case. Write a program to find all Smith numbers below 10,000'''
 
[[File:Fōrmulæ - Smith numbers 02.png]]
Programs in Fōrmulæ are created/edited online in its [https://formulae.org website], However they run on execution servers. By default remote servers are used, but they are limited in memory and processing power, since they are intended for demonstration and casual use. A local server can be downloaded and installed, it has no limitations (it runs in your own computer). Because of that, example programs can be fully visualized and edited, but some of them will not run if they require a moderate or heavy computation/memory resources, and no local server is being used.
 
[[File:Fōrmulæ - Smith numbers 03.png]]
In '''[https://formulae.org/?example=Smith_numbers this]''' page you can see the program(s) related to this task and their results.
 
=={{header|Go}}==
Line 3,081 ⟶ 3,356:
<pre>{4, 22, 27, 58, 85, 94, 121, 166, 202, 265, 274, 319, 346, 355, 378, 382, 391, 438, 454, 483, 517, 526, 535, 562, 576, 588, 627, 634, 636, 645, 648, 654, 663, 666, 690, 706, 728, 729, 762, 778, 825, 852, 861, 895, 913, 915, 922, 958, 985, 1086, 1111, 1165, 1219, 1255, 1282, 1284, 1376, 1449, 1507, 1581, 1626, 1633, 1642, 1678, 1736, 1755, 1776, 1795, 1822, 1842, 1858, 1872, 1881, 1894, 1903, 1908, 1921, 1935, 1952, 1962, 1966, 2038, 2067, 2079, 2155, 2173, 2182, 2218, 2227, 2265, 2286, 2326, 2362, 2366, 2373, 2409, 2434, 2461, 2475, 2484, 2515, 2556, 2576, 2578, 2583, 2605, 2614, 2679, 2688, 2722, 2745, 2751, 2785, 2839, 2888, 2902, 2911, 2934, 2944, 2958, 2964, 2965, 2970, 2974, 3046, 3091, 3138, 3168, 3174, 3226, 3246, 3258, 3294, 3345, 3366, 3390, 3442, 3505, 3564, 3595, 3615, 3622, 3649, 3663, 3690, 3694, 3802, 3852, 3864, 3865, 3930, 3946, 3973, 4054, 4126, 4162, 4173, 4185, 4189, 4191, 4198, 4209, 4279, 4306, 4369, 4414, 4428, 4464, 4472, 4557, 4592, 4594, 4702, 4743, 4765, 4788, 4794, 4832, 4855, 4880, 4918, 4954, 4959, 4960, 4974, 4981, 5062, 5071, 5088, 5098, 5172, 5242, 5248, 5253, 5269, 5298, 5305, 5386, 5388, 5397, 5422, 5458, 5485, 5526, 5539, 5602, 5638, 5642, 5674, 5772, 5818, 5854, 5874, 5915, 5926, 5935, 5936, 5946, 5998, 6036, 6054, 6084, 6096, 6115, 6171, 6178, 6187, 6188, 6252, 6259, 6295, 6315, 6344, 6385, 6439, 6457, 6502, 6531, 6567, 6583, 6585, 6603, 6684, 6693, 6702, 6718, 6760, 6816, 6835, 6855, 6880, 6934, 6981, 7026, 7051, 7062, 7068, 7078, 7089, 7119, 7136, 7186, 7195, 7227, 7249, 7287, 7339, 7402, 7438, 7447, 7465, 7503, 7627, 7674, 7683, 7695, 7712, 7726, 7762, 7764, 7782, 7784, 7809, 7824, 7834, 7915, 7952, 7978, 8005, 8014, 8023, 8073, 8077, 8095, 8149, 8154, 8158, 8185, 8196, 8253, 8257, 8277, 8307, 8347, 8372, 8412, 8421, 8466, 8518, 8545, 8568, 8628, 8653, 8680, 8736, 8754, 8766, 8790, 8792, 8851, 8864, 8874, 8883, 8901, 8914, 9015, 9031, 9036, 9094, 9166, 9184, 9193, 9229, 9274, 9276, 9285, 9294, 9296, 9301, 9330, 9346, 9355, 9382, 9386, 9387, 9396, 9414, 9427, 9483, 9522, 9535, 9571, 9598, 9633, 9634, 9639, 9648, 9657, 9684, 9708, 9717, 9735, 9742, 9760, 9778, 9840, 9843, 9849, 9861, 9880, 9895, 9924, 9942, 9968, 9975, 9985}</pre>
 
=={{header|Miranda}}==
<syntaxhighlight lang="miranda">main :: [sys_message]
main = [Stdout (table 5 16 taskOutput),
Stdout ("Found " ++ show (#taskOutput) ++ " Smith numbers.\n")]
where taskOutput = takewhile (<= 10000) smiths
 
table :: num->num->[num]->[char]
table cw w ns = lay (map concat (split (map fmt ns)))
where split [] = []
split ls = take w ls : split (drop w ls)
fmt n = reverse (take cw ((reverse (shownum n)) ++ repeat ' '))
 
smiths :: [num]
smiths = filter smith [1..]
 
smith :: num->bool
smith n = (~ prime) & digsum n = sum (map digsum facs)
where facs = factors n
prime = #facs <= 1
 
digsum :: num->num
digsum 0 = 0
digsum n = n mod 10 + digsum (n div 10)
 
factors :: num->[num]
factors = f [] 2
where f acc d n = acc, if d>n
= f (d:acc) d (n div d), if n mod d = 0
= f acc (d+1) n, otherwise</syntaxhighlight>
{{out}}
<pre> 4 22 27 58 85 94 121 166 202 265 274 319 346 355 378 382
391 438 454 483 517 526 535 562 576 588 627 634 636 645 648 654
663 666 690 706 728 729 762 778 825 852 861 895 913 915 922 958
985 1086 1111 1165 1219 1255 1282 1284 1376 1449 1507 1581 1626 1633 1642 1678
1736 1755 1776 1795 1822 1842 1858 1872 1881 1894 1903 1908 1921 1935 1952 1962
1966 2038 2067 2079 2155 2173 2182 2218 2227 2265 2286 2326 2362 2366 2373 2409
2434 2461 2475 2484 2515 2556 2576 2578 2583 2605 2614 2679 2688 2722 2745 2751
2785 2839 2888 2902 2911 2934 2944 2958 2964 2965 2970 2974 3046 3091 3138 3168
3174 3226 3246 3258 3294 3345 3366 3390 3442 3505 3564 3595 3615 3622 3649 3663
3690 3694 3802 3852 3864 3865 3930 3946 3973 4054 4126 4162 4173 4185 4189 4191
4198 4209 4279 4306 4369 4414 4428 4464 4472 4557 4592 4594 4702 4743 4765 4788
4794 4832 4855 4880 4918 4954 4959 4960 4974 4981 5062 5071 5088 5098 5172 5242
5248 5253 5269 5298 5305 5386 5388 5397 5422 5458 5485 5526 5539 5602 5638 5642
5674 5772 5818 5854 5874 5915 5926 5935 5936 5946 5998 6036 6054 6084 6096 6115
6171 6178 6187 6188 6252 6259 6295 6315 6344 6385 6439 6457 6502 6531 6567 6583
6585 6603 6684 6693 6702 6718 6760 6816 6835 6855 6880 6934 6981 7026 7051 7062
7068 7078 7089 7119 7136 7186 7195 7227 7249 7287 7339 7402 7438 7447 7465 7503
7627 7674 7683 7695 7712 7726 7762 7764 7782 7784 7809 7824 7834 7915 7952 7978
8005 8014 8023 8073 8077 8095 8149 8154 8158 8185 8196 8253 8257 8277 8307 8347
8372 8412 8421 8466 8518 8545 8568 8628 8653 8680 8736 8754 8766 8790 8792 8851
8864 8874 8883 8901 8914 9015 9031 9036 9094 9166 9184 9193 9229 9274 9276 9285
9294 9296 9301 9330 9346 9355 9382 9386 9387 9396 9414 9427 9483 9522 9535 9571
9598 9633 9634 9639 9648 9657 9684 9708 9717 9735 9742 9760 9778 9840 9843 9849
9861 9880 9895 9924 9942 9968 9975 9985
Found 376 Smith numbers.</pre>
=={{header|Modula-2}}==
<syntaxhighlight lang="modula2">MODULE SmithNumbers;
Line 4,187 ⟶ 4,517:
Last 12 Smith Numbers below 10000:
9778 9840 9843 9849 9861 9880 9895 9924 9942 9968 9975 9985</pre>
 
=={{header|Quackery}}==
 
<code>primefactors</code> is defined at [[Prime decomposition#Quackery]].
 
<syntaxhighlight lang="Quackery"> [ 0
[ over while
swap 10 /mod
rot + again ]
nip ] is digitsum ( n --> n )
 
[]
10000 times
[ i^ primefactors
dup size 2 <
iff drop done
0 swap witheach
[ digitsum + ]
i^ digitsum =
if [ i^ join ] ]
say "There are "
dup size echo say " Smith numbers less than 10000." cr cr
10 split swap
say "They start: " echo cr
-10 split
say "...and end: " echo cr
drop</syntaxhighlight>
 
{{out}}
 
<pre>There are 376 Smith numbers less than 10000.
 
They start: [ 4 22 27 58 85 94 121 166 202 265 ]
...and end: [ 9843 9849 9861 9880 9895 9924 9942 9968 9975 9985 ]
</pre>
 
=={{header|Racket}}==
Line 4,424 ⟶ 4,790:
All the Smith Numbers < 1000 are:
4 22 27 58 85 94 121 166 202 265 274 319 346 355 378 382 391 438 454 483 517 526 535 562 576 588 627 634 636 645 648 654 663 666 690 706 728 729 762 778 825 852 861 895 913 915 922 958 985
</pre>
 
=={{header|RPL}}==
{{works with|HP|49}}
≪ →STR 0
1 3 PICK SIZE '''FOR''' j
OVER j DUP SUB STR→ +
'''NEXT''' NIP
≫ ≫ '<span style="color:blue">∑DIGITS</span>' STO
≪ DUP FACTORS { }
1 PICK3 SIZE '''FOR''' j
1 PICK3 j 1 + GET '''START'''
OVER j GET + '''NEXT''' <span style="color:grey">@ expand the list of factors to address the 4 case</span>
2 '''STEP''' NIP
'''IF''' DUP SIZE 1 == '''THEN'''
DROP2 0
'''ELSE'''
≪ <span style="color:blue">∑DIGITS</span> == ≫ MAP ∑LIST
SWAP <span style="color:blue">∑DIGITS</span> ==
'''END'''
≫ ≫ '<span style="color:blue">SMITH?</span>' STO
≪ { }
4 10000 '''FOR''' n
'''IF''' n <span style="color:blue">SMITH?</span> '''THEN''' n + '''END'''
'''NEXT'''
≫ ≫ '<span style="color:blue">TASK</span>' STO
{{out}}
<pre>
1: {4 22 27 58 85 94 121 166 202 265 274 319 346 355 378 382 391 438 454 483 517 526 535 562 576 588 627 634 636 645 648 654 663 666 690 706 728 729 762 778 825 852 861 895 913 915 922 958 985 1086 1111 1165 1219 1255 1282 1284 1376 1449 1507 1581 1626 1633 1642 1678 1736 1755 1776 1795 1822 1842 1858 1872 1881 1894 1903 1908 1921 1935 1952 1962 1966 2038 2067 2079 2155 2173 2182 2218 2227 2265 2286 2326 2362 2366 2373 2409 2434 2461 2475 2484 2515 2556 2576 2578 2583 2605 2614 2679 2688 2722 2745 2751 2785 2839 2888 2902 2911 2934 2944 2958 2964 2965 2970 2974 3046 3091 3138 3168 3174 3226 3246 3258 3294 3345 3366 3390 3442 3505 3564 3595 3615 3622 3649 3663 3690 3694 3802 3852 3864 3865 3930 3946 3973 4054 4126 4162 4173 4185 4189 4191 4198 4209 4279 4306 4369 4414 4428 4464 4472 4557 4592 4594 4702 4743 4765 4788 4794 4832 4855 4880 4918 4954 4959 4960 4974 4981 5062 5071 5088 5098 5172 5242 5248 5253 5269 5298 5305 5386 5388 5397 5422 5458 5485 5526 5539 5602 5638 5642 5674 5772 5818 5854 5874 5915 5926 5935 5936 5946 5998 6036 6054 6084 6096 6115 6171 6178 6187 6188 6252 6259 6295 6315 6344 6385 6439 6457 6502 6531 6567 6583 6585 6603 6684 6693 6702 6718 6760 6816 6835 6855 6880 6934 6981 7026 7051 7062 7068 7078 7089 7119 7136 7186 7195 7227 7249 7287 7339 7402 7438 7447 7465 7503 7627 7674 7683 7695 7712 7726 7762 7764 7782 7784 7809 7824 7834 7915 7952 7978 8005 8014 8023 8073 8077 8095 8149 8154 8158 8185 8196 8253 8257 8277 8307 8347 8372 8412 8421 8466 8518 8545 8568 8628 8653 8680 8736 8754 8766 8790 8792 8851 8864 8874 8883 8901 8914 9015 9031 9036 9094 9166 9184 9193 9229 9274 9276 9285 9294 9296 9301 9330 9346 9355 9382 9386 9387 9396 9414 9427 9483 9522 9535 9571 9598 9633 9634 9639 9648 9657 9684 9708 9717 9735 9742 9760 9778 9840 9843 9849 9861 9880 9895 9924 9942 9968 9975 9985}
</pre>
 
Line 4,529 ⟶ 4,926:
 
}</syntaxhighlight>
 
=={{header|SETL}}==
<syntaxhighlight lang="setl">program smith_numbers;
loop for s in [n : n in [2..9999] | smith(n)] do
putchar(lpad(str s, 5));
if (i +:= 1) mod 16=0 then print; end if;
end loop;
print;
 
proc smith(n);
facs := factors(n);
return #facs /= 1 and +/digits(n) = +/[+/digits(f) : f in facs];
end proc;
 
proc digits(n);
d := [];
loop while n > 0 do
d with:= n mod 10;
n div:= 10;
end loop;
return d;
end proc;
 
proc factors(n);
f := [];
loop while even n do
n div:= 2;
f with:= 2;
end loop;
d := 3;
loop while d <= n do
loop while n mod d = 0 do
n div:= d;
f with:= d;
end loop;
d +:= 2;
end loop;
return f;
end proc;
end program;</syntaxhighlight>
{{out}}
<pre> 4 22 27 58 85 94 121 166 202 265 274 319 346 355 378 382
391 438 454 483 517 526 535 562 576 588 627 634 636 645 648 654
663 666 690 706 728 729 762 778 825 852 861 895 913 915 922 958
985 1086 1111 1165 1219 1255 1282 1284 1376 1449 1507 1581 1626 1633 1642 1678
1736 1755 1776 1795 1822 1842 1858 1872 1881 1894 1903 1908 1921 1935 1952 1962
1966 2038 2067 2079 2155 2173 2182 2218 2227 2265 2286 2326 2362 2366 2373 2409
2434 2461 2475 2484 2515 2556 2576 2578 2583 2605 2614 2679 2688 2722 2745 2751
2785 2839 2888 2902 2911 2934 2944 2958 2964 2965 2970 2974 3046 3091 3138 3168
3174 3226 3246 3258 3294 3345 3366 3390 3442 3505 3564 3595 3615 3622 3649 3663
3690 3694 3802 3852 3864 3865 3930 3946 3973 4054 4126 4162 4173 4185 4189 4191
4198 4209 4279 4306 4369 4414 4428 4464 4472 4557 4592 4594 4702 4743 4765 4788
4794 4832 4855 4880 4918 4954 4959 4960 4974 4981 5062 5071 5088 5098 5172 5242
5248 5253 5269 5298 5305 5386 5388 5397 5422 5458 5485 5526 5539 5602 5638 5642
5674 5772 5818 5854 5874 5915 5926 5935 5936 5946 5998 6036 6054 6084 6096 6115
6171 6178 6187 6188 6252 6259 6295 6315 6344 6385 6439 6457 6502 6531 6567 6583
6585 6603 6684 6693 6702 6718 6760 6816 6835 6855 6880 6934 6981 7026 7051 7062
7068 7078 7089 7119 7136 7186 7195 7227 7249 7287 7339 7402 7438 7447 7465 7503
7627 7674 7683 7695 7712 7726 7762 7764 7782 7784 7809 7824 7834 7915 7952 7978
8005 8014 8023 8073 8077 8095 8149 8154 8158 8185 8196 8253 8257 8277 8307 8347
8372 8412 8421 8466 8518 8545 8568 8628 8653 8680 8736 8754 8766 8790 8792 8851
8864 8874 8883 8901 8914 9015 9031 9036 9094 9166 9184 9193 9229 9274 9276 9285
9294 9296 9301 9330 9346 9355 9382 9386 9387 9396 9414 9427 9483 9522 9535 9571
9598 9633 9634 9639 9648 9657 9684 9708 9717 9735 9742 9760 9778 9840 9843 9849
9861 9880 9895 9924 9942 9968 9975 9985</pre>
 
=={{header|Sidef}}==
Line 4,756 ⟶ 5,218:
(376 total)</pre>
 
=={{header|V (Vlang)}}==
{{trans|Go}}
<syntaxhighlight lang="v (vlang)">fn num_prime_factors(xx int) int {
mut p := 2
mut pf := 0
Line 4,850 ⟶ 5,312:
{{libheader|Wren-math}}
{{libheader|Wren-fmt}}
<syntaxhighlight lang="wren">import "./math" for Int
{{libheader|Wren-seq}}
<syntaxhighlight lang="ecmascript">import "./mathfmt" for IntFmt
import "/fmt" for Fmt
import "/seq" for Lst
 
var sumDigits = Fn.new { |n|
Line 4,874 ⟶ 5,334:
}
}
for (chunk in Lst.chunks(smiths, 16)) Fmt.printtprint("$4d", chunksmiths, 16)</syntaxhighlight>
 
{{out}}
2,095

edits