Last active
April 29, 2017 16:22
-
-
Save niquepa/56ae122d932a756f6f685e3f369d530a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/ruby | |
n = gets.strip.to_i | |
bin = n.to_s(2) | |
#puts bin | |
state = nil | |
max = 0 | |
count = 0 | |
bin.each_char do |char| | |
if state == char | |
count += 1 | |
else | |
count = 1 | |
end | |
max = count if count > max | |
#puts "STATE => #{state}" | |
#puts "CHAR => #{char}" | |
#puts "COUNT => #{count}" | |
#puts "MAX => #{max}" | |
state = char | |
end | |
puts max |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment