| Bytes | Lang | Time | Link |
|---|---|---|---|
| 056 | Arturo | 240701T144723Z | chunes |
| 063 | Ruby | 240701T141158Z | int 21h |
| 007 | Uiua SBCS | 240630T171626Z | chunes |
| 056 | R | 240630T125936Z | int 21h |
| 041 | Brev | 220621T120132Z | Sandra |
| 005 | Pip | 220612T035714Z | naffetS |
| 085 | Red | 220612T043440Z | chunes |
| 039 | rSNBATWPL | 220612T025127Z | naffetS |
| 034 | Factor | 220612T013842Z | chunes |
| 003 | Vyxal d | 220611T233102Z | naffetS |
| 050 | PowerShell Core | 201030T033159Z | Julian |
| 003 | Japt P | 201029T230240Z | Shaggy |
| 9291 | PHP | 190821T215155Z | 640KB |
| 005 | Stax | 190821T211718Z | Khuldrae |
| 003 | Jelly | 190821T203325Z | Unrelate |
| 1530 | 𝔼𝕊𝕄𝕚𝕟 | 151123T033323Z | Mama Fun |
| 033 | Perl 6 | 151129T190503Z | Brad Gil |
| 004 | GS2 | 151123T011438Z | Dennis |
| 012 | Japt | 151123T010316Z | Downgoat |
| 166 | Ceylon | 151123T232317Z | Paŭlo Eb |
| 036 | Haskell | 151123T173516Z | nimi |
| 043 | Clojure/ClojureScript | 151123T173507Z | MattPutn |
| 051 | Mathematica | 151123T172015Z | LegionMa |
| 152 | C++14 | 151123T145431Z | Zereges |
| 009 | TeaScript | 151123T004104Z | Downgoat |
| 010 | K | 151123T041842Z | JohnE |
| 015 | Octave | 151123T030600Z | alephalp |
| 008 | GolfScript | 151123T003638Z | Dennis |
| 057 | JavaScript ES6 | 151123T013739Z | George R |
| 046 | Minkolang 0.13 | 151123T013420Z | El'e |
| 048 | Python | 151123T005224Z | Dennis |
| 046 | Julia | 151123T011221Z | Alex A. |
| 005 | Pyth | 151123T002458Z | Maltysen |
| 005 | CJam | 151123T002513Z | geokavel |
R, 56 bytes
\(a,`^`=Reduce)paste0^apply(rbind^strsplit(a,""),2,sort)
It seems that to get the shortest solution one should avoid those quite verbose calculations of the length: be it nchar() or length().
Here is a function that inputs a vector of strings and outputs a concatenated string with the sorted characters.
Brev, 53 41 bytes
(as-list flatten(over(sort args char<?)))
Example:
((as-list flatten (over (sort args char<?))) "HELLO" "world" "!!!!!")
Red, 85 bytes
func[b][repeat c length? b/1[foreach a sort collect[foreach m b[keep m/:c]][prin a]]]
PowerShell Core, 56 50 bytes
-join(($a=$args)[0]|% t*y|%{$a|% c*rs($i++)|sort})
-6 bytes thanks to mazzy
PHP, 92 91 bytes
for($argv[0]='';$a=array_column(array_map(str_split,$argv),$i++|0);print join($a))sort($a);
I'm confident this could be done shorter by not trying to use PHP's built-in array functions, but had to try!
Or 85 bytes
@Night2's swing, done shorter by not trying to use PHP's built-in array functions:
for(;''<$argv[1][$i++];print join($a))for($a=[];''<$a[]=$argv[++$$i][$i-1];sort($a));
Stax, 5 bytes
LMFop
So close to LMNOP :(
Run and debug it at staxlang.xyz!
Put all inputs into one list of strings (L), and transpose this list (M). For each resulting string (F), sort (o) and print (p) it.
Jelly, 3 bytes
ZṢ€
Only valid if considered as a full program: the resulting value is a list of strings, but when it's printed Jelly implicitly flattens it.
€ Map
Ṣ sort
Z over the columns of the input.
𝔼𝕊𝕄𝕚𝕟, 15 chars / 30 bytes
Ѩťªï)ć⇀ѨŌ$ø⬯)ø⬯
Just realized that Lodash's sortBy function works on strings, too.
Perl 6, 33 bytes
{[~] flat ([Z] @_».comb)».sort}
Example usage:
say {[~] flat ([Z] @_».comb)».sort}(< abc cba >) # acbbca
my &code = my $code = {[~] flat ([Z] @_».comb)».sort}
say code "HELLO","world","!!!!!"; # !Hw!Eo!Lr!Ll!Od
say ((<cba abc>),(<testing gnitset gttseni>)).map($code);
# (acbbac ggtentiststteisenngit)
GS2, 4 bytes
*Ü■/
This reads the strings from STDIN, separated by linefeeds.
The source code uses the CP437 encoding. Try it online!
Test run
$ xxd -r -ps <<< '2a 9a fe 2f' > zip-sort.gs2
$ echo -e 'HELLO\nworld\n!!!!!' | gs2 zip-sort.gs2
!Hw!Eo!Lr!Ll!Od
How it works
* Split the input into the array of its lines.
Ü Zip the resulting array.
■ Map the rest of the program over the resulting array.
/ Sort.
Japt, 12 bytes 20
Ny m_q n q)q
Explanation
Ny // Transpose inputs
m_ // Maps through each new string
q // Split string
n // Sort string
q // Join
)q // Join again
Ceylon, 166
String z(String+l)=>String(expand(t(l).map(sort)));[T+]n<T>(T?+i)=>[for(e in i)e else nothing];{[X+]*}t<X>([{X*}+]l)=>l[0].empty then{}else{n(*l*.first),*t(l*.rest)};
While Ceylon has a zip function, it takes only two iterables instead of an iterable of them. unzip, on the other hand, takes an iterable of tuples, and I don't want to convert my strings into tuples. So I implemented my own transpose function, inspired by a Haskell implementation which Google found for me somewhere.
// zip-sort
//
// Question: http://codegolf.stackexchange.com/q/64526/2338
// My answer: ...
// Takes a list of strings (same length), and produces
// a string made by concatenating the results of sorting
// the characters at each position.
String z(String+ l) =>
String(expand(t(l).map(sort)));
// Narrow an iterable of potential optionals to their non-optional values,
// throwing an AssertionError if a null is in there.
[T+] n<T>(T?+ i) =>
[for (e in i) e else nothing];
// Transpose a nonempty sequence of iterables, producing an iterable of
// sequences.
// If the iterables don't have the same size, either too long ones are
// cut off or too short ones cause an AssertionError while iterating.
{[X+]*} t<X>([{X*}+] l) =>
l[0].empty
then {}
else { n(*l*.first), *t(l*.rest) };
The types of n and t could be defined much more general, but this is Codegolf ;-) (n is a special case of what I proposed as assertNarrow two weeks ago).
Haskell, 39 36 bytes
import Data.List
(>>=sort).transpose
Usage example: ((>>=sort).transpose) ["HELLO","world","!!!!!"] -> "!Hw!Eo!Lr!Ll!Od".
Transpose the list of strings, map sort over it and concatenate the resulting list of strings (>>= in list context is concatMap).
Clojure/ClojureScript, 43 bytes
#(apply str(mapcat sort(apply map list %)))
Creates an anonymous function. Written in a ClojueScript REPL, should also be valid Clojure.
Enter it here, then call via (*1 ["HELLO" "world" "!!!!!"]). Or do (def f *1) and then use (f ["abc" "cba"]).
Mathematica, 51 bytes
""<>SortBy@ToCharacterCode/@Transpose@Characters@#&
String manipulation in Mathematica is expensive...
C++14, 152 bytes
#include<iostream>
#include<regex>
[](auto s){for(int i=0;i<s[0].size();++i){auto r=""s;for(auto k:s)r+=k[i];std::sort(begin(r),end(r));std::cout<<r;}};
Not using any advantage of map+zip (guess why)
Ungolfed + usage
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
int main()
{
auto lambda = [](auto s)
{
for (int i = 0; i < s[0].size(); ++i)
{
auto r = ""s;
for (auto k : s)
r += k[i];
std::sort(begin(r), end(r));
std::cout << r;
}
};
std::vector<std::string> data = { "HELLO", "world", "!!!!!" };
lambda(data);
}
TeaScript, 9 bytes
_t¡ßlp¡)µ
TeaScript has all the right built-ins implemented in all the wrong ways.
Ungolfed
_t()m(#lp())j``
Explanation
_t() // Transposes input array
m(# // Loops through inputs
lp() // Sorts characters by char code
)
j`` // Joins back into string
K, 10 bytes
,/{x@<x}'+
Join (,/) the sort of ({x@<x}) each (') of the transpose (+) of a list of strings.
In action:
,/{x@<x}'+("HELLO";"world";"!!!!!")
"!Hw!Eo!Lr!Ll!Od"
Simple, but K is hurt a bit here by not having a single-character sort function and instead dividing the operation into a scatter-gather index operator @ and a primitive which yields the permutation vector which would sort a list <.
Octave, 15 bytes
@(a)sort(a)(:)'
Example:
octave:1> (@(a)sort(a)(:)')(["abc";"cba"])
ans = acbbac
octave:2> (@(a)sort(a)(:)')(["HELLO";"world";"!!!!!"])
ans = !Hw!Eo!Lr!Ll!Od
GolfScript, 8 bytes
~zip{$}%
Try it online on Web GolfScript.
How it works
~ # Evaluate the input.
zip # Zip it.
{$}% # Map sort ($) over the resulting array.
JavaScript (ES6), 57 bytes
a=>a[0].replace(/./g,(c,i)=>a.map(w=>w[i]).sort().join``)
Minkolang 0.13, 46 bytes
$od0Z2:$zIz:$xd0G2-[i1+z[di0c*+c$r]xz$(sr$Ok].
Try it here. Expects input like "HELLO""world""!!!!!" (so no commas).
Explanation
$o Read in whole input as characters
d Duplicate top of stack (the ")
0Z Count how often this appears in the stack
2: Divide by two
$z Store this in the register (z)
Iz: Length of stack divided by z (k)
$x Dump one element from the front/bottom of stack
d Duplicate top of stack (which is k)
0G Insert it at the front/bottom of stack
2- k-2
[ Open for loop that repeats k-2 times
i1+ Loop counter + 1 (i)
z[ Open for loop that repeats z times
d Duplicate top of stack (which is i)
i Loop counter (j)
0c Copy k from front of stack
* Multiply (j*k)
+ Add (j*k + i)
c Copy character at position j*k+i to the top
$r Swap top two elements of stack (so i is on top)
] Close for loop
x Dump the top of stack (dump i)
z$( Start a new loop with the top z elements
s Sort
r$O Reverse and output the whole (loop) stack as characters
k Break - exits while loop
]. Close for loop and stop
Python, 50 48 bytes
lambda x,y=''.join:y(map(y,map(sorted,zip(*x))))
Thanks to @xnor for -2 bytes!
Julia, 46 bytes
x->(j=join)(map(i->j(sort([i...])),zip(x...)))
This creates an unnamed function that accepts an array of strings and returns a string. To call it, give it a name, e.g. f=x->....
Ungolfed:
function zipsort{T<:AbstractString}(x::Array{T,1})
# Splat the input array and zip into an iterable
z = zip(x...)
# For each tuple consisting of corresponding characters
# in the input array's elements, splat into an array,
# sort the array, and join it into a string
m = map(i -> join(sort([i...])), z)
# Take the resulting string array and join it
return join(m)
end