Pernicious numbers: Difference between revisions

Add Miranda
(Add Cowgol)
(Add Miranda)
Line 2,135:
Pernicious numbers betweeen 888888877 and 888888888 inclusive
<syntaxhighlight lang="mathematica">Cases[Range[888888877, 888888888], _?(perniciousQ@# &)]</syntaxhighlight>
 
=={{header|Miranda}}==
<syntaxhighlight lang="miranda">main :: [sys_message]
main = [Stdout (lay (map show [first25, large]))]
 
first25 :: [num]
first25 = take 25 (filter pernicious [1..])
 
large :: [num]
large = filter pernicious [888888877..888888888]
 
pernicious :: num->bool
pernicious = prime . popcount
 
popcount :: num->num
popcount 0 = 0
popcount n = n mod 2 + popcount (n div 2)
 
prime :: num->bool
prime n = n >= 2 & and [n mod d ~= 0 | d<-[2..sqrt n]]
</syntaxhighlight>
{{out}}
<pre>[3,5,6,7,9,10,11,12,13,14,17,18,19,20,21,22,24,25,26,28,31,33,34,35,36]
[888888877,888888878,888888880,888888883,888888885,888888886]</pre>
 
=={{header|Modula-2}}==
2,114

edits