Skip to content

Instantly share code, notes, and snippets.

@bchase
Created May 29, 2014 00:18
Show Gist options
  • Save bchase/84e430215cd9734bab0d to your computer and use it in GitHub Desktop.
Save bchase/84e430215cd9734bab0d to your computer and use it in GitHub Desktop.
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