Skip to content

Instantly share code, notes, and snippets.

View cardotrejos's full-sized avatar

Ricardo Trejos cardotrejos

View GitHub Profile
@cardotrejos
cardotrejos / bin_gap.rb
Created June 5, 2020 20:54
Function def binary_gap(n) that, given a positive integer N, returns the length of its longest binary gap.
def bin_gap (n)
bin = n.to_s(2)
temp = []
gaps = []
bin.each_char do |char|
if char == "1"
unless temp.empty?
gaps << temp.length
temp = []
end