| Bytes | Lang | Time | Link |
|---|---|---|---|
| 097 | AWK | 241129T204731Z | xrs |
| 007 | Japt h | 240910T101851Z | Shaggy |
| 004 | Vyxal | 240910T202242Z | emanresu |
| 011 | Husk | 240910T080322Z | int 21h |
| 009 | Pyth | 160905T203444Z | Maltysen |
| 008 | Pyth | 160905T063057Z | Steven H |
| 100 | Javascript ES6 | 160903T140352Z | Arnauld |
| 090 | JavaScript ES6 | 160905T083615Z | edc65 |
| 048 | Perl | 160905T060111Z | Ton Hosp |
| 011 | Pyth | 160903T180740Z | TheBikin |
| 097 | Ruby | 160903T080359Z | cia_rana |
| 082 | Mathematica | 160903T165916Z | DavidC |
| 063 | Haskell | 160903T090620Z | nimi |
| 006 | Jelly | 160903T070643Z | Sp3000 |
AWK, 97 bytes
{l<NF&&l=NF;x++;for(t=k=0;k++<NF;t+=$k)a[x][k]=$k;if(t>g){g=t;b=x}}END{for(;m++<l;)print a[b][m]}
{ # code block runs with each column
l<NF&&l=NF; # keep track of longest column
x++; # number of columns
for(t=k=0;k++<NF; # for each digit
t+=$k) # add to temp total
a[x][k]=$k; # place in array
if(t>g){g=t;b=x}} # update if new total is larger
END{ # runs after all data processed.
for(;m++<l;)print a[b][m]} # print our column
Japt -h, 7 bytes
May be a bit too liberal with the ability to "print these numbers in any format you like".
z3 ñȬx
Vyxal, 4 bytes
∩⁽∑∴
Try it Online! It's a bit weird that this challenge overrides default I/O, but thankfully vyxal casts the ints to digit lists anyway.
∩ # Transpose (casting each int to digits)
⁽ ∴ # Largest column by
∑ # Sum
Husk, 11 bytes
S!oS€▲mΣTmd
Takes input of a list of integers as an argument and outputs the "largest column" as a list too.
Not sure how exactly this works, but here is a tentative explanation:
# Implicit input
md # Start by conversion of every integer into its digits
T # Transpose or zip the lists into the columns
mΣ # Sum up the columns
▲ # Find the maximum column sum
S€ # Find the position of the column with the maximum sum
# (Combinator S passes 2 args to €: max and list of sums)
S! # Another S-combinator: take the nth item of
o Tmd # ...the earlier calculated transposed list
Pyth, 5 8 bytes
esDsMM.T
Takes in input as a list of strings, outputs as a nothing-separated list of digits.
Explanation:
.T Transpose input to zip together corresponding columns
sMM Cast to digit lists
sD sort(D) by (s)um
e take last element, implicitly print
Javascript (ES6), 108 103 100 bytes
It's a bit verbose and could probably be golfed some more with a different approach. I wish I could get rid of this .filter(n=>n).
Saved 5 bytes thanks to Neil
Saved 3 bytes thanks to edc65
l=>l.map(n=>[...n].map((d,x)=>(m=(s[x]=(s[x]|0)-d)<m?s[c=x]:m,d)),s=[m=0]).map(n=>n[c]).filter(n=>n)
Demo
let f =
l=>l.map(n=>[...n].map((d,x)=>(m=(s[x]=(s[x]|0)-d)<m?s[c=x]:m,d)),s=[m=0]).map(n=>n[c]).filter(n=>n)
console.log(f(["1", "11", "111", "1111"]).join`,`); // --> [1, 1, 1, 1]
console.log(f(["1", "12", "123"]).join`,`); // --> [2, 2]
console.log(f(["987654321", "111"]).join`,`); // --> [9, 1]
console.log(f(["111", "123456789"]).join`,`); // --> [9]
console.log(f(["4", "8", "15", "16", "23", "42"]).join`,`); // --> [4, 8, 1, 1, 2, 4]
console.log(f(["4", "8", "12", "26", "27", "38"]).join`,`); // --> [2, 6, 7, 8]
console.log(f(["24", "53"]).join`,`); // --> [2, 5]
console.log(f(["12", "304", "506"]).join`,`); // --> [4, 6]
console.log(f(["30", "285", "121"]).join`,`); // --> [0, 8, 2]
JavaScript (ES6), 90
(l,x)=>[...l+0].map((t,i)=>l.map(n=>(n=n[i])&&(v-=n,t.push(n)),v=t=[])|v>=x||(x=v,r=t))&&r
f=(l,x)=>[...l+0].map((t,i)=>l.map(n=>(n=n[i])&&(v-=n,t.push(n)),v=t=[])|v>=x||(x=v,r=t))&&r
;[
[[123, 7, 49, 681] , [2,9,8]]
,[[25, 223, 302] , [2, 2, 3]]
,[[1, 11, 111, 1111] , [1, 1, 1, 1]]
,[[1, 12, 123] , [2, 2]]
,[[987654321, 111] , [9, 1]]
,[[111, 123456789] , [9]]
,[[4, 8, 15, 16, 23, 42] , [4, 8, 1, 1, 2, 4]]
,[[4, 8, 12, 26, 27, 38] , [2, 6, 7, 8]]
,[[24, 53] , [2, 5]]
,[[12, 304, 506] , [4, 6]]
,[[30, 285, 121] , [0, 8, 2]]]
.forEach(t=>{
var i=t[0], o=t[1], r, ok
i=i.map(x=>x+'') // convert i to a string list
r=f(i)
ok = (r+'')==(o+'') // compare r and o as comma separated strings
console.log(ok?'OK':'KO', i+' -> '+ r)
})
Perl, 49 48 bytes
Includes +1 for -p
Run with the input on STDIN, prints to STDOUT the column numbers prefixed by +
lcolumn.pl
123
7
49
681
lcolumn.pl:
#!/usr/bin/perl -p
s/./@;[@-].="+$&"/eg}{($_)=sort{eval"$b<=>$a"}@
Pyth, 11 bytes
h.MsZ.TmjdT
A program that takes input of a list of integers on STDIN and prints a list.
How it works
h.MsZ.TmjdT Program. Input: Q
j T Yield the base-10 representation, giving a list of digits
m d Map that over Q (implicit input fill)
.T Justified transpose, giving each column as a list
.MsZ Filter the above by maximum sum
h First element of above
Implicitly print
Ruby, 100 97 bytes
a=$<.map &:chomp
puts a.map(&:size).max.times.map{|i|a.map{|e|e[i]}.compact}.max_by{|e|eval e*?+}
Mathematica 82 bytes
This pads the digits of each number with x's to the right, transposes the matrix, removes the dummy x's, orders by sum of the digits and takes the greatest.
SortBy[#~Select~NumberQ&/@Transpose[PadRight[#,30,x]&/@IntegerDigits@#],Tr][[-1]]&
There ought to be some way to use the superscript-T form of Transpose to save a few bytes.
Haskell, 63 bytes
import Data.Lists
argmax sum.transpose.map(map(read.pure).show)
Usage example: argmax sum.transpose.map(map(read.pure).show) $ [12,304,506] -> [4,6].
How it works:
map -- for each number
map(read.pure).show -- turn into list of digits
transpose -- transpose the list of list
argmax sum -- find the element with the
-- largest sum
Jelly, 6 bytes
DZṚSÞṪ
Try it online!. This is a relatively straightforward implementation of the question.
D Convert each number in the input to a list of digits, e.g.
[353, 2247] -> [[3, 5, 3], [2, 2, 4, 7]]
Z Zip the lists together, e.g. [[3, 2], [5, 2], [3, 4], [7]]
Ṛ Reverse the list of lists so that first occurrences are now
at the end, e.g. [[7], [3, 4], [5, 2], [3, 2]]
SÞ Sort by sum - this uses Python's sorted function, which is stable
so equal elements end up in order of appearance, e.g.
[[3, 2], [7], [3, 4], [5, 2]]
Ṫ Tail - get the last element, e.g. [5, 2]