Skip to content
mgarcia edited this page Apr 13, 2012 · 6 revisions

Welcome to the snippets wiki!

number_of_ones

This code snippet solves the following condition:

NumberOfOnes(n) = n

It includes the function number_of_ones(n) that returns the number of ones found from the number 1 to n.

For instance:

number_of_ones(0) = 0 number_of_ones(1) = 1 number_of_ones(2) = 1 number_of_ones(10) = 2 number_of_ones(11) = 4 number_of_ones(12) = 5 ...

Sintaxe

$ perl number_of_ones.pl [num]

Find the first occurence of NumberOfOnes(n) = n starting at "num"

Clone this wiki locally