Population count: Difference between revisions
→{{header|Fōrmulæ}}
Alextretyak (talk | contribs) m (→{{header|11l}}: bits:popcount()) |
|||
Line 1,937:
{{FormulaeEntry|page=https://formulae.org/?script=examples/Population_count}}
'''Solution'''
Fōrmulæ has an integrated expression BitCount that counts the number of 1's of the binary representation of the number.
However, a function can also be written, as follows:
[[File:Fōrmulæ - Population count 01.png]]
'''Case 1. Display the pop count of the 1st thirty powers of 3'''
[[File:Fōrmulæ - Population count 02.png]]
[[File:Fōrmulæ - Population count 03.png]]
'''Case 2. Display the 1st thirty evil numbers'''
We need first a function to calculate the first numbers whose population count satisfies a given condition, passed as a lambda expression:
[[File:Fōrmulæ - Population count 04.png]]
[[File:Fōrmulæ - Population count 05.png]]
[[File:Fōrmulæ - Population count 06.png]]
'''Case 3. Display the 1st thirty odious numbers'''
[[File:Fōrmulæ - Population count 07.png]]
[[File:Fōrmulæ - Population count 08.png]]
=={{Header|FreeBASIC}}==
|