Skip to content

Instantly share code, notes, and snippets.

@KrzaQ
Created December 5, 2018 05:41
Show Gist options
  • Save KrzaQ/478e9816fabe93f2d5e991e87b23f247 to your computer and use it in GitHub Desktop.
Save KrzaQ/478e9816fabe93f2d5e991e87b23f247 to your computer and use it in GitHub Desktop.
#!/usr/bin/ruby
DATA = File.read('data.txt').strip
copy = [DATA.clone, true]
# $counts = {}
def make_pass input
input += "?"
n = 0
ret = ""
while n < input.size-1
e1 = input[n]
e2 = input[n+1]
if e1.upcase == e2.upcase and e1 != e2
# $counts[e1.downcase] = $counts.fetch(e1.downcase, 0) + 1
n += 1
else
ret += e1
end
n += 1
end
# p input
# p ret
# p [ret.size, input.size]
[ret, ret.size != input.size-1]
end
# loop do
# copy = make_pass copy.first
# break unless copy.last
# end
# p copy.first.size
p2 = ('a'..'z').map do |c|
copy = [DATA.gsub(/[#{c}#{c.upcase}]/, ''), true]
loop do
copy = make_pass copy.first
break unless copy.last
end
p [c, copy.first.size]
[c, copy.first.size]
end.to_a.sort_by{|k, v| v}
p p2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment