Attractive numbers: Difference between revisions

Add ABC
(Initial FutureBasic task solution added)
(Add ABC)
 
(4 intermediate revisions by 4 users not shown)
Line 171:
 
<pre>4 6 8 9 10 12 14 15 18 20 21 22 25 26 27 28 30 32 33 34 35 38 39 42 44 45 46 48 49 50 51 52 55 57 58 62 63 65 66 68 69 70 72 74 75 76 77 78 80 82 85 86 87 91 92 93 94 95 98 99 102 105 106 108 110 111 112 114 115 116 117 118 119 120</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 REPORT attractive n:
REPORT 1 = #factors #factors n
 
PUT 0 IN col
FOR i IN {1..120}:
IF attractive i:
WRITE i>>5
PUT col+1 IN col
IF col mod 10=0: WRITE /</syntaxhighlight>
{{out}}
<pre> 4 6 8 9 10 12 14 15 18 20
21 22 25 26 27 28 30 32 33 34
35 38 39 42 44 45 46 48 49 50
51 52 55 57 58 62 63 65 66 68
69 70 72 74 75 76 77 78 80 82
85 86 87 91 92 93 94 95 98 99
102 105 106 108 110 111 112 114 115 116
117 118 119 120</pre>
 
=={{header|Action!}}==
Line 1,289 ⟶ 1,321:
92 93 94 95 98 99 102 105 106 108 110 111 112 114 115 116 117 118
119 120</pre>
 
=={{header|EasyLang}}==
<syntaxhighlight lang=easylang>
func isprim num .
if num < 2
return 0
.
i = 2
while i <= sqrt num
if num mod i = 0
return 0
.
i += 1
.
return 1
.
func count n .
f = 2
repeat
if n mod f = 0
cnt += 1
n /= f
else
f += 1
.
until n = 1
.
return cnt
.
for i = 2 to 120
n = count i
if isprim n = 1
write i & " "
.
.
</syntaxhighlight>
 
=={{header|F_Sharp|F#}}==
Line 2,507 ⟶ 2,575:
<pre>
[4,6,8,9,10,12,14,15,18,20,21,22,25,26,27,28,30,32,33,34,35,38,39,42,44,45,46,48,49,50,51,52,55,57,58,62,63,65,66,68,69,70,72,74,75,76,77,78,80,82,85,86,87,91,92,93,94,95,98,99,102,105,106,108,110,111,112,114,115,116,117,118,119,120]</pre>
 
=={{header|MiniScript}}==
<syntaxhighlight lang="miniscript">
isPrime = function(n)
if n < 2 then return false
if n < 4 then return true
for i in range(2,floor(n ^ 0.5))
if n % i == 0 then return false
end for
return true
end function
 
countFactors = function(n)
cnt = 0
for i in range(2, n)
while n % i == 0
cnt += 1
n /= i
end while
end for
return cnt
end function
 
isAttractive = function(n)
if n < 1 then return false
factorCnt = countFactors(n)
return isPrime(factorCnt)
end function
 
numbers = []
for i in range(2, 120)
if isAttractive(i) then numbers.push(i)
end for
 
print numbers.join(", ")
</syntaxhighlight>
{{out}}
<pre>4, 6, 8, 9, 10, 12, 14, 15, 18, 20, 21, 22, 25, 26, 27, 28, 30, 32, 33, 34, 35, 38, 39, 42, 44, 45, 46, 48, 49, 50, 51, 52, 55, 57, 58, 62, 63, 65, 66, 68, 69, 70, 72, 74, 75, 76, 77, 78, 80, 82, 85, 86, 87, 91, 92, 93, 94, 95, 98, 99, 102, 105, 106, 108, 110, 111, 112, 114, 115, 116, 117, 118, 119, 120</pre>
 
=={{header|Miranda}}==
Line 4,010 ⟶ 4,116:
.foreach { case (_, row) => println(row.map(_._1).mkString) }
}</syntaxhighlight>
 
=={{header|SETL}}==
<syntaxhighlight lang="setl">program attractive_numbers;
numbers := [n in [2..120] | attractive(n)];
printtab(numbers, 20, 3);
 
proc printtab(list, cols, width);
lines := [list(k..cols+k-1) : k in [1, cols+1..#list]];
loop for line in lines do
print(+/[lpad(str item, width+1) : item in line]);
end loop;
end proc;
 
proc attractive(n);
return #factorize(#factorize(n)) = 1;
end proc;
 
proc factorize(n);
factors := [];
d := 2;
loop until d > n do
loop while n mod d = 0 do
factors with:= d;
n div:= d;
end loop;
d +:= 1;
end loop;
return factors;
end proc;
end program;</syntaxhighlight>
{{out}}
<pre> 4 6 8 9 10 12 14 15 18 20 21 22 25 26 27 28 30 32 33 34
35 38 39 42 44 45 46 48 49 50 51 52 55 57 58 62 63 65 66 68
69 70 72 74 75 76 77 78 80 82 85 86 87 91 92 93 94 95 98 99
102 105 106 108 110 111 112 114 115 116 117 118 119 120</pre>
 
=={{header|Sidef}}==
Line 4,433 ⟶ 4,574:
{{libheader|Wren-fmt}}
{{libheader|Wren-math}}
<syntaxhighlight lang="ecmascriptwren">import "./fmt" for Fmt
import "./math" for Int
var max = 120
Line 4,442 ⟶ 4,583:
var n = Int.primeFactors(i).count
if (Int.isPrime(n)) {
SystemFmt.write(Fmt.d(4"$4d", i))
count = count + 1
if (count%20 == 0) System.print()
2,115

edits