-
-
Save pdxwolfy/8460593d25cf9faaa8e1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# frozen_string_literal: true | |
# | |
# Copyright (c) 2016 Pete Hanson | |
def number_list_to_string(list) | |
list.map(&:to_s).join '' | |
end | |
def lowest_number(number_list) | |
number_list.permutation | |
.map { |list| number_list_to_string(list) } | |
.map(&:to_i) | |
.min | |
end | |
puts lowest_number([23, 550, 1, 80]) # -> 12355080 | |
puts lowest_number([1, 1, 1, 1]) # -> 1111 | |
puts lowest_number([10000, 123, 1890, 11]) # -> 10000111231890 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment