Colorful numbers: Difference between revisions

m
→‎{{header|Ruby}}: mostly indentation
m (→‎{{header|Ruby}}: mostly indentation)
Line 1,182:
All colorful candidates larger than 1 digit must be a permutation of digits [2,3,4,5,6,7,8,9], so test only those:
<syntaxhighlight lang="ruby">def colorful?(ar)
prodsproducts = []
(1..ar.size).all? do |chunk_size|
ar.each_cons(chunk_size) do |chunk|
product = chunk.inject(&:*)
return false if prodsproducts.include?(product)
prodsproducts << product
end
end
end
end
 
less100below100 = (0..100).select{|n| colorful?(n.digits)}
puts "The colorful numbers less than 100 are:\n #{less100below100.join(" ")}", ""
puts "\nLargestLargest colorful number: #{(98765432.downto(1).detect{|n| colorful?(n.digits) })}", ""
 
total = 0
1,149

edits