Skip to content

Instantly share code, notes, and snippets.

@pdxwolfy
Created March 19, 2016 18:14
Show Gist options
  • Save pdxwolfy/8460593d25cf9faaa8e1 to your computer and use it in GitHub Desktop.
Save pdxwolfy/8460593d25cf9faaa8e1 to your computer and use it in GitHub Desktop.
# 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