# Reduce the list to a final number

Inputs

A list (array) of numbers, or numerical strings if that makes it easier. You can assume there will always be at least two elements in the list and every element will be a natural number (integer larger than zero).

### Outputs

A single number, or again, a numerical string.

### Problem

The idea is to reduce the list of numbers by removing the last digit of the largest number at that current stage of the list, eventually ending with one number (only one number should be returned, even if there are multiple instances)

### Example

[123,343,121,76,465,786] -- The last digit in 786 is dropped, so it becomes 78
[123,343,121,76,465,78]  -- New largest number is 465, so the 5 is dropped, making it 46
[123,343,121,76,46,78]   -- Repeat until left with one number
[123,34,121,76,46,78]
[12,34,121,76,46,78]
[12,34,12,76,46,78]
[12,34,12,76,46,7]
[12,34,12,7,46,7]
[12,34,12,7,4,7]
[12,3,12,7,4,7]
[1,3,1,7,4,7]            -- If there are multiple max numbers, you **must** remove the last digit from all of them
[1,3,1,4]
[1,3,1]
[1,1]                    -- You have your answer when there is one number, or multiple numbers that are equal
1                        -- Result


### Loopholes

Standard loopholes apply

### Other constraints

Your program must work for any list of random numbers (within reason of course)

### Test Cases

[24,72,4]
[24,7,4]
[2,7,4]
[2,4]
[2]
2

[14, 7]
[1, 7]
[1]
1

[1278,232,98273,2334]
[1278,232,9827,2334]
[1278,232,982,2334]
[1278,232,982,233]
[127,232,982,233]
[127,232,98,233]
[127,232,98,23]
[127,23,98,23]
[12,23,98,23]
[12,23,9,23]
[12,2,9,2]
[1,2,9,2]
[1,2,2]
[1]
1


### Scoring

This is , so shortest answer in every language wins!

• Please let me know if I missed anything. First question. Jul 6, 2017 at 20:45
• Dunno if it's too late to change, but the question might be better if we did have to output each stage. I think the answers will be quite straightforward otherwise. Jul 6, 2017 at 20:59
• Since no one else has mentioned it, this is the kind of thing that would frequently be caught in the sandbox. Jul 6, 2017 at 21:52
• Can you add testcases where the answer is not the first digit of the first entry in the list?
Jul 7, 2017 at 9:54
• The way I read this question the answer for [12, 123, 124] is 12, which makes every single posted answer wrong. Nov 17, 2017 at 1:15

minimum.map head


Try it online!

# Python 2, 24 bytes

-4 bytes thanks to notjagan.

lambda l:min(zip(*l)[0])


Try it online!

• This can be shortened 4 bytes while keeping the same idea using min(zip(*l)[0]). Jul 6, 2017 at 23:51

# Python 3, 24, 21, 18 bytes

lambda l:min(l)[0]


Try it online!

Three Six bytes saved thanks to @totallyhuman!

# Mathematica, 29 bytes

Min[First@*IntegerDigits/@#]&


# Japt, 86 5 bytes

-1 byte thanks to @Shaggy

n g g


Takes input as an array of numeric strings. Try it online!

## Explanation

        // implicit input: array of strings
n       // sort the array
g     // get the first element
g   // get the first character
// implicit output

• 5 bytes: Sort the array, get the first element, get the first character. Jul 7, 2017 at 14:18
• @Shaggy Oh duh, I totally over complicated this one. Thanks! Jul 7, 2017 at 14:22
• No problem :) n v g would also work for 5 bytes. Welcome to Japt, by the way. Jul 7, 2017 at 14:25

# 05AB1E, 3 bytes

€нW


Try it online!

• Fails for [12,23,12]. Jul 7, 2017 at 13:16
• @OlivierGrégoire: How? Removing the digits in the order 3,2,2,2,1 results in 1 as expected. Jul 7, 2017 at 13:28
• My bad, I misread. See previous comment. Jul 7, 2017 at 13:33

# PHP, 45 bytes

<?foreach($_GET as$v)$r[]=$v[0];echo min($r);  Try it online! • Fails for [12,23,12]. Jul 7, 2017 at 13:14 • @OlivierGrégoire [12,23,12]->[12,2,12]->[1,2,12]->[1,2,1]->[1,1]->[1]->1 is in my opinion correct Jul 7, 2017 at 13:30 • My bad, I misread. See previous comment. Jul 7, 2017 at 13:32 # V, 11, 5 bytes ÚxV}p  Try it online! I was making this waaay more complicated than it actually is. This answer simply sorts every line by ASCII values, and then returns the very first character. Since this is kind or a boring answer, here is a more interesting answer that actually implements the algorithm originally described: # V, 11 bytes òún /äîä Lx  Try it online! • I was too when I posed the question. Your original answer was what I expected most to look like. Bummer. Jul 6, 2017 at 21:51 # Jelly, 3 2 bytes ṂḢ  A full program which takes a list of lists of characters (strings) and prints the result. Try it online! ### How? We just need to return the smallest leading digit... ṂḢ - Main link: list of lists of characters Ṃ - minimum (lexicographical ordering ensures this will start with the minimal digit) Ḣ - head (get that first digit character)  • No problem, it happens. Jul 7, 2017 at 13:38 # JavaScript (ES6), 17 bytes Takes input as an array of strings. a=>a.sort()[0][0]  ## Try it Input a comma separated list of numbers. o.innerText=(f= a=>a.sort()[0][0] )((i.value="1278,232,98273,2334").split,);oninput=_=>o.innerText=f(i.value.split,) <input id=i><pre id=o> # ,,,, 3 bytes ⫰1⊣  ## Explanation ⫰1⊣ ⫰ pop the whole stack and push the minimum element 1 push 1 ⊣ pop the minimum and 1 and push the first character of it  # Braingolf, 17 bytes VVR{Mvd<M&$_R}vvx


Try it online!

## Explanation

VVR{Mvd<M&$_R}vvx Implicit input from commandline args VVR Create stack2 and stack3, return to stack1 {.........} Foreach item in stack.. M ..Move item to next stack v ..Switch to next stack d ..Split item into digits <M ..Move first item to next stack &$_       ..Clear stack
vv   Switch to stack3
x  Reduce to lowest value
Implicit output of last item on stack


In other words, it constructs a stack consisting of only the first digit of each item, then outputs the lowest.

This challenge gave me a bunch of useful ideas for builtins to add to Braingolf, and now thanks to the addition of the "special" foreach loop, Braingolf can do it in 5 bytes:

# Braingolf, 5 bytes [non-competing]

(d<)x


## Explanation

(d<)x  Implicit input from commandline args
(..)   Special foreach loop, iterates over the stack, moving each item to a special
Sandboxed stack environment, and prepends the last item of the sandboxed
stack to the real stack at the end of each iteration
d<    Split into digits, move first digit to end of stack
x  Reduce to lowest value
Implicit output of last item on stack


Try it online!

I'm normally against adding builtins just to complete one challenge, but I can see a plethora of uses for the new (...) foreach loop, so I don't really consider it adding a feature just for this challenge.

• Fails for [12,23,12]. Expected output is 2, you returned 1. Jul 7, 2017 at 13:24
• @OlivierGrégoire The expected output of that is 1: [12,23,12] > [12,2,12] > [1,2,1] > [1,1] Jul 7, 2017 at 13:28
• My bad, I misread. See previous comment. Jul 7, 2017 at 13:33

# Funky, 18 bytes

x=>x::sort()[0][0]


Takes input as a list of strings.

Try it online!

# Pip, 5 bytes

Takes the list of input numbers as command-line arguments.

@@SSg


Try it online!

Alternately:

MN@Zg


Try it online!

### Explanations

In both programs, g is the list of command-line args.

@@SSg


SS sorts using string comparison, thus putting the numbers with smallest first digits first, regardless of their magnitudes. Unary @ gives the first element of a list or scalar. We apply it twice to get the first digit of the first number after sorting.

    g  [24 72 491]
SS   [24 491 72]
@     24
@      2


Alternately:

MN@Zg


Z is zip; its unary version can be used to transpose a list. The first element of the transposed list is a list of the first digits of all the numbers. @ gets that list of digits; MN takes its minimum.

    g  [24 72 491]
Z   [[2 7 4] [4 2 9]]
@    [2 7 4]
MN     2


# Pyth, 9 7 bytes

hSmshd


Try it online!

Explanation

This basically return the smallest leading digit.

       Q    # Implicit input
mshd     # For each number in Q, convert to string, take the first character, convert to integer
hS          # Return the minimum


# Python 3, 33 bytes

lambda l:min(str(x)[0]for x in l)


Try it online!

@DJMcMayhem and @totallyhuman have a better solutions but mine assumes numerical input instead of string.

# Pyth, 3 bytes

hhS


Input is list of string representations of numbers.

Try It Online

Explanation:

hhS
# Q=input
S # Sort Q
h  # First Element of sorted list
h   # First element of string
# Implicitly print result