Skip to content

Instantly share code, notes, and snippets.

@Pomeha
Created May 14, 2019 06:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Pomeha/c5aa07c645e591ea0a5551fb5cac34ec to your computer and use it in GitHub Desktop.
Save Pomeha/c5aa07c645e591ea0a5551fb5cac34ec to your computer and use it in GitHub Desktop.
# frozen_string_literal: true
class LuckyTickets
def self.call(n)
n = n/2
n2 = 10 ** n - 1
a = Array.new(9 * n + 1) { 0 }
(0..n2).each do |l|
a[l.to_s.chars.map(&:to_i).sum] += 1
end
puts a.map { |e| e*e }.sum
end
end
[1] pry(main)> LuckyTickets.call(6)
55252
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment