Created
December 2, 2017 22:29
-
-
Save jasper-lyons/c816f16b06e8ea9db67b8ee03ce0e143 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
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