Created
May 29, 2014 00:18
-
-
Save bchase/84e430215cd9734bab0d 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
class LuckyArray < Array | |
def self.from_string(str) | |
new str.split('').map(&:to_i) | |
end | |
def front_half | |
slice 0, length/2 | |
end | |
def back_half | |
idx = length - length/2 | |
slice idx, length/2 | |
end | |
def sum | |
inject :+ | |
end | |
def lucky? | |
front_half.sum == back_half.sum | |
end | |
end | |
def luck_check(str) | |
LuckyArray.from_string(str).lucky? | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment