Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save niquepa/56ae122d932a756f6f685e3f369d530a to your computer and use it in GitHub Desktop.
Save niquepa/56ae122d932a756f6f685e3f369d530a to your computer and use it in GitHub Desktop.
#!/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