45
\$\begingroup\$

Given a nonempty list of positive decimal integers, output the largest number from the set of numbers with the fewest digits.

The input list will not be in any particular order and may contain repeated values.

Examples:

[1] -> 1
[9] -> 9
[1729] -> 1729
[1, 1] -> 1
[34, 3] -> 3
[38, 39] -> 39
[409, 12, 13] -> 13
[11, 11, 11, 1] -> 1
[11, 11, 11, 11] -> 11
[78, 99, 620, 1] -> 1
[78, 99, 620, 10] -> 99
[78, 99, 620, 100] -> 99
[1, 5, 9, 12, 63, 102] -> 9
[3451, 29820, 2983, 1223, 1337] -> 3451
[738, 2383, 281, 938, 212, 1010] -> 938

The shortest code in bytes wins.

\$\endgroup\$
2
  • \$\begingroup\$ Can the input numbers be on separate lines? \$\endgroup\$
    – seshoumara
    Commented Sep 16, 2016 at 5:48
  • \$\begingroup\$ @seshoumara That sounds reasonable, yes. \$\endgroup\$ Commented Sep 16, 2016 at 5:48

61 Answers 61

1 2
3
0
\$\begingroup\$

J-uby, 22 bytes

Port of my Ruby solution.

:max_by+-[S|:+@|:-@,I]

Attempt This Online!

\$\endgroup\$
1 2
3

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.