| Bytes | Lang | Time | Link |
|---|---|---|---|
| 012 | Uiua | 240928T222347Z | nyxbird |
| 006 | Vyxal | 240927T145404Z | pacman25 |
| 052 | Zsh | 230309T153742Z | roblogic |
| 064 | Python 3 | 230308T173224Z | GulgDev |
| 032 | Arturo | 230308T171855Z | chunes |
| 008 | Husk | 210429T111609Z | Razetime |
| 094 | Lua | 191122T143543Z | LuaNoob |
| 048 | C# Visual C# Interactive Compiler | 191114T181801Z | Malivil |
| 068 | APLNARS | 191121T184340Z | user5898 |
| 053 | Röda | 191120T214829Z | fergusq |
| 081 | Python 3 | 191120T175321Z | Cello Co |
| 5956 | Haskell | 191115T013723Z | Joseph S |
| 042 | Scala | 191114T194128Z | Layman |
| nan | 191116T130852Z | Czylabso | |
| 030 | Wolfram Language Mathematica | 191116T014857Z | Traws |
| 009 | Brachylog | 191115T231715Z | Unrelate |
| 053 | jq | 191115T220410Z | wirefox |
| 136 | SimpleTemplate | 191115T123900Z | Ismael M |
| 6010 | RPL | 191115T000243Z | Nacre |
| 023 | Retina | 191114T152545Z | the defa |
| 022 | J | 191114T112021Z | Galen Iv |
| 007 | 05AB1E | 191114T090846Z | Kevin Cr |
| 028 | Ruby | 191114T075233Z | G B |
| 062 | PHP | 191114T105942Z | Night2 |
| 015 | APL Dyalog Unicode | 191114T084909Z | Bubbler |
| 107 | Red | 191114T082752Z | Galen Iv |
| 034 | Perl 5 040n | 191113T191246Z | Nahuel F |
| 014 | K ngn/k | 191113T205153Z | scrawl |
| 129 | C gcc | 191113T224239Z | ErikF |
| 018 | PowerShell | 191114T005406Z | mazzy |
| 072 | Python 2 | 191113T224551Z | Chas Bro |
| 019 | Perl 6 | 191113T223629Z | Jo King |
| 037 | Retina 0.8.2 | 191113T214446Z | Neil |
| 007 | Japt | 191113T205535Z | AZTECCO |
| 053 | PowerShell | 191113T190343Z | AdmBorkB |
| 028 | R | 191113T193756Z | Giuseppe |
| 008 | Jelly | 191113T181210Z | Nick Ken |
| 009 | Pyth | 191113T183849Z | frank |
| 050 | JavaScript | 191113T181222Z | Shaggy |
| 053 | JavaScript ES6 | 191113T180844Z | Arnauld |
| 007 | Japt | 191113T180315Z | Shaggy |
Uiua, 12 bytes
↘1⍚⊂°⊏⊕□≡◇⧻.
↘1⍚⊂°⊏⊕□≡◇⧻.
⊕□ . # group input into boxes by
≡◇⧻ # unboxed length
°⊏ # get indices
⍚⊂ # and join to each group
↘1 # drop the first group (with length 0)
Zsh, 52 bytes
for i;printf \ $i>>$#i;(for j (*)<<<$j`<$j`)|sort -n
For each argument/word i, append to a file called $#i (length of i).
For each resulting file j (*), print the filename <<<$j and contents <$j, and sort.
Lua, 85 94 bytes
changed to to function format +9 bytes
r={}m=0 for j=1,#i do w=i[j]l=#w m=l>m and l or m c=r[l]r[l]=c and w..","..c or w end return r
C# (Visual C# Interactive Compiler), 48 bytes
a=>a.GroupBy(k=>k.Length,v=>v).OrderBy(g=>g.Key)
-1 byte thanks to @dzaima
-43 bytes if returning the raw grouping is allowed, thanks to @someone
-18 bytes by switching to the Visual C# Interactive Compiler
APL(NARS), chars 34, bytes 68
{a,⍨¨↑¨≢¨¨a←a⊂⍨≢¨a←a[⍋a←⍵⊂⍨' '≠⍵]}
test:
f←{a,⍨¨↑¨≢¨¨a←a⊂⍨≢¨a←a[⍋a←⍵⊂⍨' '≠⍵]}
⎕fmt f 'Code Golf and coding challenges Meta'
┌4──────────────────────────────────────────────────────────────────────┐
│┌2───────┐ ┌4────────────────────────┐ ┌2──────────┐ ┌2───────────────┐│
││ ┌3───┐│ │ ┌4────┐ ┌4────┐ ┌4────┐│ │ ┌6──────┐│ │ ┌10─────────┐││
││3 │ and││ │4 │ Code│ │ Golf│ │ Meta││ │6 │ coding││ │10 │ challenges│││
││~ └────┘2 │~ └─────┘ └─────┘ └─────┘2 │~ └───────┘2 │~~ └───────────┘2│
│└∊───────┘ └∊────────────────────────┘ └∊──────────┘ └∊───────────────┘3
└∊──────────────────────────────────────────────────────────────────────┘
⎕fmt f 'My v3ry 3xc13nt m0th3r 53rv3d u5 pzz@5 #Ju'
┌6─────────────────────────────────────────────────────────────────────────────────────────┐
│┌3────────────┐ ┌2───────┐ ┌2────────┐ ┌2─────────┐ ┌3────────────────────┐ ┌2───────────┐│
││ ┌2──┐ ┌2──┐│ │ ┌3───┐│ │ ┌4────┐│ │ ┌5─────┐│ │ ┌6──────┐ ┌6──────┐│ │ ┌7───────┐││
││2 │ My│ │ u5││ │3 │ #Ju││ │4 │ v3ry││ │5 │ pzz@5││ │6 │ 53rv3d│ │ m0th3r││ │7 │ 3xc13nt│││
││~ └───┘ └───┘2 │~ └────┘2 │~ └─────┘2 │~ └──────┘2 │~ └───────┘ └───────┘2 │~ └────────┘2│
│└∊────────────┘ └∊───────┘ └∊────────┘ └∊─────────┘ └∊────────────────────┘ └∊───────────┘3
└∊─────────────────────────────────────────────────────────────────────────────────────────┘
Röda, 53 bytes
{a=new map;a[#_]+=_1 if[a[#_1]?]else a[#_1]=[_1];[a]}
Explanation
{a=new map;a[#_]+=_1 if[a[#_1]?]else a[#_1]=[_1];[a]}
{ } anonymous function
a=new map; let a be a hash map
for each _1:
if[ ]else ; if
a[#_1]? a[length(_1)] exists
a[#_]+=_1 then append _1 to a[length(_1)]
a[#_1]=[_1] else a[length(_1)] = [_1]
[a] return a
Python 3, 81 bytes
Outputs a dictionary instead of a list or tuple:
lambda s:dict(sorted((len(x),list(filter(lambda y:len(y)==len(x),s)))for x in s))
Haskell, 59 56 bytes
l=length
f s=[(n,[x|x<-s,l x==n])|n<-[1..maximum$l<$>s]]
- -3 bytes by using a list comprehension instead of a lambda, thanks to 79037662
Brachylog, 9 bytes
lᵍ{hl}ᶻ¹o
Takes input as a list of words (the testing header converts from space-separated for convenience). Output is as a list of pairs [length,words], sorted in ascending order of length. Two alternative solutions of the same length, lᵒlᵍ{hl}ᶻ and lᵍ{hl}ᶻtᵒ, output pairs reversed.
SimpleTemplate, 136 bytes
Yeah, it's a long one... The order of the output is what made it longer :/
{@setM 0}{@eachargv.0}{@callstrlen intoR _}{@setL.[R]L.[R],_}{@ifM is lowerR}{@setM R}{@/}{@/}{@forfrom 1toM}{@echo_}.{@echojl" " L.[_]}
Incredibly, it is easier (and shorter) to output that to return.
You can try it on http://sandbox.onlinephpfunctions.com/code/ec4bf4b3efa93c63c6c5c9f1458330da0178b6cd
(Line 974 has the words, line 976 has the golfed/ungolfed version variable)
Ungolfed:
{@set results}
{@set max 0}
{@each argv.0 as word}
{@call strlen into length word}
{@set results.[length] results.[length], word}
{@if max is lower than length}
{@set max length}
{@/}
{@/}
{@for i from 1 to length}
{@echo i}.{@echo separator " " results.[i], "\n"}
{@/}
Most of it should be easy to understand.
RPL, 60+10 bytes
Let's explore more creative output formats:
DUP«SIZE»DOLIST SWAP 2«STR→ X ROT ^ *»DOLIST ΣLIST EXPANDMOD
turns the list {"Code" "Golf" "and" "Coding" "Challenges" "Meta"} into the polynomial Challenges·X10+Coding·X6+(Code+Golf+Meta)·X4+and·X3 thanks to EXPANDMOD.
Sadly to allow exotic names like pizz@5 – just for you to know, @ introduces comments – STR→ must be replaced by #5B15h SYSEVAL adding 10 bytes to the source code, and obfuscating the call. That does however allow printable and even non printable chars, the latters only displayed as black squares but not lost. So the garbage resistant code is
DUP«SIZE»DOLIST SWAP 2«#5B15h SYSEVAL X ROT ^ *»DOLIST ΣLIST EXPANDMOD
(EXPANDMOD is present in HP50g at least. Tested with Emu48 in 50g mode. The code page is documented here).
Retina, 31 27 23 bytes
Takes input as a newline-separated list of words (I haven't noticed that's allowed at first).
.+
$.& $&
N`
D`\d+
¶
I'll add the explanation later (for now, the previous revision's explanation without the first line works perfectly). Try it online!
J, 22 bytes
-2 bytes thaks to FrownyFrog
If the output can be a table with some empty boxes:
[:/:~#@>(,~#&.>@{.)/.]
J, 24 bytes
/:~@(#@><@(#@>@{.;])/.])
Just made it work - no doubt it can be golfed further.
05AB1E, 9 7 bytes
€gêεùy‚
-2 bytes thanks to @Grimy.
Outputs a list of lists from lowest to highest, with the label at the right side instead of left. I.e. [[["and"],3],[["Code","Golf","Meta"],4],[["Coding"],6],[["Challenges"],10]].
Try it online or verify all test cases.
Explanation:
€g # Get the length of each string in the (implicit) input-list
ê # Sort and uniquify this list of lengths
ε # Map each length `y` to:
ù # Keep strings from the (implicit) input-list equal to this length
y‚ # And pair it with the current length `y`
# (after which the result is output implicitly)
APL (Dyalog Unicode), 15 bytes
(⍋⊃¨⊂)≢¨{⊂⍺⍵}⌸⊢
APL is not particularly good at simply sorting.
How it works
(⍋⊃¨⊂)≢¨{⊂⍺⍵}⌸⊢
≢¨ ⌸⊢ Group the arg's elements by their lengths
{⊂⍺⍵} Wrap each list of items, paired with the length
(⍋⊃¨⊂) Idiom for sorting:
⍋ Grade up; gives indexes that will make the array sorted
⊃¨⊂ Map the indexes to the items
Red, 107 bytes
func[a][m: copy#()foreach w sort a[k: length? w
unless m/:k[put m k copy[]]append m/:k w]sort/skip to[]m 2]
K (ngn/k), 12 14 bytes
{x@=#'x@:<#'x}
this returns a k dictionary. lengths are key, words are value. let me know if this output format is acceptable.
in q (wrapper around the k4 dialect), we can evaluate using the k interpreter and get q output formatting:
q)k){x@=#:'x@:<#:'x}("Code"; "Golf"; "and"; "Coding"; "Challenges"; "Meta")
3 | ,"and"
4 | ("Meta";"Golf";"Code")
6 | ,"Coding"
10| ,"Challenges"
note the extra colons, which aren't required for "eached" monads in the ngn implementation
C (gcc), 147 129 bytes
Thanks to girobuz and ceilingcat for the suggestions.
This routine first finds the maximum string length of an input array of strings, then prints the words by length in reverse.
m,*t;f(int**s){for(t=s;*s;m=fmax(m,strlen(*s++)+1));for(;--m;)for(printf("\n%d",m),s=t;*s;)printf(" %s"+3*(strlen(*s++)!=m),*s);}
Python 2, 76 74 72 bytes
lambda a:sorted((l,[d for d in a if len(d)==l])for l in set(map(len,a)))
Perl 6, 19 bytes
*.classify(*.chars)
Pretty much does exactly as asked.
*.classify( ) # Classify the list
*.chars # By number of characters
Retina 0.8.2, 37 bytes
S`
.+
$.& $&
O#`
r`(?<=\1.+)¶(.+ )
Try it online! Explanation:
S`
Split the input on spaces.
.+
$.& $&
Precede each word by its length.
O#`
Sort numerically.
r`(?<=\1.+)¶(.+ )
If two lines start with the same length, delete the newline and the length.
Japt, 7 bytes
üÊ®uZÎl
üÊ®uZÎl // input as array of words
üÊ // group by length
® // for each group
uZÎl // append length of 1st word
PowerShell, 63 53 bytes
$a=@{};$args|%{$a[$_.length]+=" $_"};$a|% *or|sort N*
(-10 bytes thanks to mazzy)
Takes arguments via splatting, which on TIO manifests as separate command-line arguments.
We first construct an empty hashtable $a, then loop through the input arguments. Each item is tacked onto $a in the appropriate $_.length slot. Then comes the lengthy .GetEnumerator() followed by a sort to get the hashtable to print out in order. That's left on the pipeline and output is implicit.
R, 28 bytes
split(w<-scan(,""),nchar(w))
split does the trick; results in a list() where the element names are the lengths and the elements are vectors containing the words.
Jelly, 6 8 bytes
ẈẈḢ,Ɗƙ⁸Ṣ
A monadic link which takes a list of Jelly strings and returns a list of lists where the first member of each list is the length and the second is a list of Jelly strings of that length. Plus 2 bytes now it’s been clarified that ordering of the list is mandatory.
Pyth, 9 bytes
m+lhdd.gl
Port of @Shaggy's answer, so I cant really take credit for this (lol)
Pyth, 14 bytes
m+dfqdlTQSleol
Saves a few bytes by mapping a filtered list to each number in a 1-indexed range. This only saves 2 bytes due to the fact that the last two bytes can be implicit (would be m+dfqdlTQSleolNQ otherwise)
How it works
m+dfqdlTQSleol
m - Map
+d - The sum of the element and...
fqdlTQ - The filtered input where each element of the input is length d
Sl - To the range [1, length]
eol - of the last element of the ordered list by key=length
- Print implicitly
Pyth, 16 bytes
FkSleolNQkfqklTQ
16 bytes seems a bit high for a challenge like this but oh well. Would be 14 bytes but it looks like the last 2 bytes cant be implicit due to how filter works in pyth
How it works
FkSleolNQkfqklTQ
Fk - For k in...
Sl - The range [1, length]
eolN - Of the last element of the sorted list by key=length
Q - Of the input
k - Print k
fqklT - Filter by key k == length...
Q - The input (prints implicitly)
Sorry if this answer is too long, I can cut it a bit if needed
JavaScript, 50 bytes
Input as an array of words, output as an object where the keys are the word lengths and the values are arrays of words.
a=>a.map(w=>o[l=w.length]=[...o[l]||[],w],o={})&&o
JavaScript (ES6), 53 bytes
Takes input as a list of words. Returns an object whose keys are the lengths and whose values are the lists of corresponding words.
a=>a.map(w=>(o[n=w.length]=o[n]||[]).push(w),o={})&&o
Japt, 7 bytes
Input as an array of words, output as a 2D-array.
üÊËiDÎÊ
üÊËiDÎÊ :Implicit input of array
ü :Group and sort by
Ê : Length
Ë :Map each sub-array D
i : Prepend
DÎÊ : Length of first element of D