Want more features on Pastebin? Sign Up, it's FREE!

This problem can be solved by pre-school children...

By: RedTeaHacker on Feb 21st, 2012  |  syntax: Ruby  |  size: 0.74 KB  |  views: 15,614  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. #!/usr/bin/env ruby
  2. # Solution for:
  3. #   This problem can be solved by pre-school children in 5-10 minutes,
  4. #   by programmers - in 1 hour, by people with higher education...
  5. #   well, check it yourself :)
  6. def enigma array
  7.   array.each do |x|
  8.     print "#{enigma2(x)} "
  9.   end
  10.   puts
  11. end
  12.  
  13. def enigma2 x
  14.   i=0
  15.   x.each_char do |y|
  16.     case Integer(y)
  17.       when 0,6,9
  18.         i+=1
  19.       when 8
  20.         i+=2
  21.     end
  22.   end
  23.   i
  24. end
  25.  
  26. zero=['7111','2172','1111','3213','2222','3333','5555','7777','5531']
  27. one=['9313','7756']
  28. two=['7662']
  29. three=['8193','6855']
  30. four=['6666','0000','9999']
  31. five=['8096','9881']
  32. six=['8809']
  33. unknown=['2581']
  34.  
  35. enigmas=[zero,one,two,three,four,five,six,unknown]
  36. enigmas.each do |x|
  37.   enigma x
  38. end
clone this paste RAW Paste Data