Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def max_multiplication(str)
- return unless str.is_a?(String)
- digital_combinations = str.scan(/\d+/).select { |item| item.length >= 4 }
- return if digital_combinations.empty?
- best_digital_combination = digital_combinations.map { |item| item.chars.sort { |a, b| b <=> a }.take(4) }.max
- best_digital_combination.map(&:to_i).reduce(:*)
- end
- def sort(array_of_numbers)
- array_of_numbers.map { |number| number.to_s(2) }.sort do |a, b|
- if a.count('1') == b.count('1')
- a.to_i(2) <=> b.to_i(2)
- else
- a.count('1') <=> b.count('1')
- end
- end.map { |number| number.to_i(2) }
- end
- p(max_multiplication('abc12345def'))
- p(max_multiplication('a1b2c3d4e'))
- p(max_multiplication('ds23fgf99fdsd54fd90'))
- p(sort([3,7,8,9]))
- p(sort([3,12,15,5]))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement