Attractive numbers: Difference between revisions

(Added 11l)
Line 1,370:
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|jq}}==
{{works with|jq}}
'''Works with gojq, the Go implementation of jq'''
 
This entry uses:
* `is_prime` as defined at https://rosettacode.org/wiki/Erd%C5%91s-primes#jq
* `prime_factors` as defined at https://rosettacode.org/wiki/Smith_numbers#jq
<lang jq>
def count(s): reduce s as $x (null; .+1);
 
def is_attractive:
count(prime_factors) | is_prime;
 
def printattractive($m; $n):
"The attractive numbers from \($m) to \($n) are:\n",
[range($m; $n+1) | select(is_attractive)];
printattractive(1; 120)</lang>
{{out}}
<pre>
The attractive numbers from 1 to 120 are:
 
[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>
 
2,489

edits