4 kyu

Count ones in a segment

641 of 3,233d0n14

Description:

Given two numbers: 'left' and 'right' (1 <= 'left' <= 'right' <= 200000000000000) return sum of all '1' occurencies in binary representations of numbers between 'left' and 'right' (including both)

Example:
countOnes 4 7 should return 8, because:
4(dec) = 100(bin), which adds 1 to the result.
5(dec) = 101(bin), which adds 2 to the result.
6(dec) = 110(bin), which adds 2 to the result.
7(dec) = 111(bin), which adds 3 to the result.
So finally result equals 8.

WARNING: Segment may contain billion elements, to pass this kata, your solution cannot iterate through all numbers in the segment!

Binary
Performance
Algorithms

More By Author:

Check out these other kata created by d0n14

Stats:

CreatedJul 17, 2017
PublishedJul 17, 2017
Warriors Trained17517
Total Skips5564
Total Code Submissions23170
Total Times Completed3233
C++ Completions641
Haskell Completions115
JavaScript Completions786
Python Completions1003
C Completions336
NASM Completions18
Java Completions220
Forth Completions11
C# Completions147
COBOL Completions8
Go Completions37
Rust Completions66
Kotlin Completions45
Total Stars742
% of votes with a positive feedback rating94% of 512
Total "Very Satisfied" Votes457
Total "Somewhat Satisfied" Votes45
Total "Not Satisfied" Votes10
Total Rank Assessments8
Average Assessed Rank
4 kyu
Highest Assessed Rank
4 kyu
Lowest Assessed Rank
6 kyu
Ad
Contributors
  • d0n14 Avatar
  • myjinxin2015 Avatar
  • docgunthrop Avatar
  • NerdNeils Avatar
  • Blind4Basics Avatar
  • AlexPuts Avatar
  • nomennescio Avatar
  • har-s Avatar
  • Voile Avatar
  • KataSideKick Avatar
  • monadius Avatar
  • hobovsky Avatar
  • user8436785 Avatar
  • akar-0 Avatar
  • sid114 Avatar
Ad