6 kyu

Most Consecutive Zeros of a Binary Number

65 of 726ajLapid718

Description:

Given a string (str) containing a base-10 integer between 0 and 10000, convert the integer to its binary representation. At that point, obtain a count of the maximum amount of consecutive 0s. From there, return the count in written form with a capital letter.

max_consec_zeros("9") => "Two"
max_consec_zeros("13") => "One"
max_consec_zeros("15") => "Zero"
max_consec_zeros("42") => "One"
max_consec_zeros("550") => "Three"

In the very first example, we have an argument of "9" which is being passed to the method. The binary representation of 9 is 1001 which can be read as: one, zero, zero, one. There are, at most, two consecutive 0s, resulting in the integer 2 as the value of the count. The output in the block of code above reflects the final step of taking 2 from standard form to the written form "Two" as prompted.

In the very last example, we have an argument of "550" which is being passed to the method. The binary representation of 550 is 1000100110 which can be read as: one, zero, zero, zero, one, zero, zero, one, one, zero. There are, at most, three consecutive 0s, resulting in the integer 3 as the value of the count. The output in the block of code above reflects the final step of taking 3 from standard form to the written form of "Three" as prompted.

One way, among many, to visualize the end of each step might look like:

max_consec_zeros("777")
1: "777"
2: 777
3: 1100001001
4: 4
5: "Four"
max_consec_zeros("777") => "Four"

Happy coding!

Fundamentals
Mathematics
Strings

More By Author:

Check out these other kata created by ajLapid718

Stats:

CreatedOct 12, 2017
PublishedOct 12, 2017
Warriors Trained1175
Total Skips17
Total Code Submissions2432
Total Times Completed726
Ruby Completions65
JavaScript Completions265
Python Completions427
Crystal Completions12
Total Stars21
% of votes with a positive feedback rating88% of 233
Total "Very Satisfied" Votes185
Total "Somewhat Satisfied" Votes41
Total "Not Satisfied" Votes7
Total Rank Assessments11
Average Assessed Rank
6 kyu
Highest Assessed Rank
5 kyu
Lowest Assessed Rank
8 kyu
Ad
Contributors
  • ajLapid718 Avatar
  • GiacomoSorbi Avatar
  • aweleshetu Avatar
  • ice1000 Avatar
  • Just4FunCoder Avatar
  • saudiGuy Avatar
Ad