Skip to content

Instantly share code, notes, and snippets.

@jasper-lyons
Created December 2, 2017 22:29
Show Gist options
  • Save jasper-lyons/c816f16b06e8ea9db67b8ee03ce0e143 to your computer and use it in GitHub Desktop.
Save jasper-lyons/c816f16b06e8ea9db67b8ee03ce0e143 to your computer and use it in GitHub Desktop.
def reverse_captcha(captcha)
(captcha + captcha[0]). # "21752...7422"
split(''). # ['2', '1', '7', ... '4', '2']
each_cons(2). # [ ['2', '1'], ['1', '7'], ... ['4', '2'], ['2', '2'] ]
map { |a, b| a == b ? a.to_i : 0 }. # [0,0,0,0,0,...0,0,2]
reduce(&:+) # sum
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment