Population count: Difference between revisions

Scala contribution added.
(add actual →‎Free Pascal: implementation)
(Scala contribution added.)
Line 2,358:
</pre>
 
{{Out}}See it yourself by running in your browser either by [https://scalafiddle.io/sf/1IYuvtd/0 ScalaFiddle (ES aka JavaScript, non JVM)] or [https://scastie.scala-lang.org/w0oHalRXS1mtI59tXh1NaA Scastie (remote JVM)].
{{libheader|Scala LazyList}}
{{libheader|Scala Tail recursion}}
{{libheader|ScalaFiddle qualified}}
{{libheader|Scastie qualified}}
{{works with|Scala|2.13}}
<lang Scala>import java.lang.Long.bitCount
 
object PopCount extends App {
val nNumber = 30
 
def powersThree(start: Long): LazyList[Long] = start #:: powersThree(start * 3L)
 
println("Population count of 3ⁿ :")
println(powersThree(1L).map(bitCount).take(nNumber).mkString(", "))
 
def series(start: Long): LazyList[Long] = start #:: series(start + 1L)
 
println("Evil numbers:")
println(series(0L).filter(bitCount(_) % 2 == 0).take(nNumber).mkString(", "))
 
println("Odious numbers:")
println(series(0L).filter(bitCount(_) % 2 != 0).take(nNumber).mkString(", "))
 
}</lang>
=={{header|Seed7}}==
The function <code>popcount</code> below [http://seed7.sourceforge.net/libraries/bitset.htm#bitset(in_integer) converts]
Line 2,396 ⟶ 2,421:
writeln;
end func;</lang>
 
{{out}}
<pre>1 2 2 4 3 6 6 5 6 8 9 13 10 11 14 15 11 14 14 17 17 20 19 22 16 18 24 30 25 25
<pre>
1 2 2 4 3 6 6 5 6 8 9 13 10 11 14 15 11 14 14 17 17 20 19 22 16 18 24 30 25 25
evil: 0 3 5 6 9 10 12 15 17 18 20 23 24 27 29 30 33 34 36 39 40 43 45 46 48 51 53 54 57 58
odious: 1 2 4 7 8 11 13 14 16 19 21 22 25 26 28 31 32 35 37 38 41 42 44 47 49 50 52 55 56 59 </pre>
</pre>
 
=={{header|Sidef}}==
Anonymous user