Advertisement
Guest User

Untitled

a guest
Feb 5th, 2017
222
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. def is_lucky(ticket)
  2.   return false if ticket =~ /\D/
  3.   return false if ticket.length > 6
  4.   return false if ticket.length < 6
  5.   arr1 = (ticket).split("")[0..2]
  6.   arr2 = (ticket).split("")[3..5]
  7.   hey = arr1.reduce(0) { |a, s| a + s.to_i }
  8.   bye = arr2.reduce(0) { |a, s| a + s.to_i }
  9.   if hey == bye
  10.     true
  11.   else
  12.     false
  13.   end
  14. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement