Skip to content

Instantly share code, notes, and snippets.

@pdxwolfy
Last active March 19, 2016 18:31
Show Gist options
  • Save pdxwolfy/8d140c536245da09e459 to your computer and use it in GitHub Desktop.
Save pdxwolfy/8d140c536245da09e459 to your computer and use it in GitHub Desktop.
# frozen_string_literal: true
#
# Copyright (c) 2016 Pete Hanson
def lowest_number(number_list)
number_list.map(&:to_s)
.permutation
.map(&:join)
.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
puts lowest_number([1890, 18901]) # -> 189011890
puts lowest_number([12, 33, 11, 9]) # -> 1112339
puts lowest_number([1, 1, 0, 1]) # -> 111
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment