Last active
March 19, 2016 20:46
-
-
Save pdxwolfy/93d5e2bc3dbc389d3129 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 | |
require 'minitest/autorun' | |
def lowest_number(number_list) | |
number_list.map(&:to_s).sort do |a, b| | |
if a.start_with?(b) | |
a[b.size..-1] <=> b | |
elsif b.start_with?(a) | |
a <=> b[a.size..-1] | |
else | |
a <=> b | |
end | |
end.join('').to_i | |
end | |
class TestLowestNumber < Minitest::Test | |
def test_1 | |
assert_equal 1_23_550_80, lowest_number([23, 550, 1, 80]) | |
end | |
def test_2 | |
assert_equal 1_1_1_1, lowest_number([1, 1, 1, 1]) | |
end | |
def test_3 | |
assert_equal 10000_11_123_1890, lowest_number([10000, 123, 1890, 11]) | |
end | |
def test_4 | |
assert_equal 1890_11890, lowest_number([1890, 18901]) | |
end | |
def test_5 | |
assert_equal 11_12_33_9, lowest_number([12, 33, 11, 9]) | |
end | |
def test_6 | |
assert_equal 18_1834_55023_550, lowest_number([55023, 550, 1834, 18]) | |
end | |
def test_7 | |
assert_equal 1817_18_55023_550, lowest_number([55023, 550, 1817, 18]) | |
end | |
def test_8 | |
assert_equal 1818_18_55023_550, lowest_number([55023, 550, 1818, 18]) | |
end | |
def test_9 | |
assert_equal 1_1_1, lowest_number([1, 1, 0, 1]) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment