28
\$\begingroup\$

In as few bytes as possible, sort the input, a delimited string OR list/vector/array of words, words contain printable ASCII except space (ASCII values 33-126) into a numbered list, table, or something resembling a table, by length.

Table rules are as follows:

  • Order is mandatory, direction is optional, either labelled rows from shortest to longest or vice versa,
  • Formatting is not the challenge. So as long as the output is some form of numerically labelled rows of words, a numbered list, or a list of lists, or similar output, then it is a satisfactory answer.
  • including/excluding gaps (NA values, see below examples for both methods of output)
  • Word case is untouched. How the word appears in input should be shown in output.

Input 1:

Code Golf and Coding Challenges Meta

or

("Code","Golf","and","Coding","Challenges","Meta")

or similar

Output 1:

 1. NA
 2. NA
 3. and
 4. Code Golf Meta
 5. NA
 6. Coding
 7. NA
 8. NA
 9. NA
 10. Challenges

or

3. and
4. Code Golf Meta
6. Coding
10. Challenges

or

[[3, ['and']], [4, ['Code', 'Golf', 'Meta']], [6, ['Coding']], [10, ['Challenges']]]

Input 2:

My v3ry 3xc3113nt m0th3r ju5t 53rv3d u5 nin3 pizz@5 #JusticeForPluto

Output 2:

1. NA
2. My u5
3. NA
4. v3ry ju5t nin3
5. NA
6. m0th3r 53rv3d pizz@5
7. NA
8. NA
9. 3xc3113nt
10. NA
11. NA
12. NA
13. NA
14. NA
15. NA
16. #JusticeForPluto

or

2. My u5
4. v3ry ju5t nin3
6. m0th3r 53rv3d pizz@5
9. 3xc3113nt
16. #JusticeForPluto

or

[[2, ['My', 'u5']], [4, ['v3ry', 'ju5t', 'nin3']], [6, ['m0th3r', '53rv3d', 'pizz@5']], [9, ['3xc3113nt']], [16, ['#JusticeForPluto']]]

More examples can be provided if necessary but I think this should suffice for now. Please ask questions if you have them, this is my second attempt at a challenge. (the first failed dramatically)

\$\endgroup\$
4
  • \$\begingroup\$ In your second example, it seems that @ is part of a word, but . is not, and # is. Could you please define what a "word" means? Thanks. \$\endgroup\$
    – hyper-neutrino
    Commented Nov 13, 2019 at 18:02
  • \$\begingroup\$ @HyperNeutrino Sorry, I meant to delete that period. I'll make some edits \$\endgroup\$
    – Sumner18
    Commented Nov 13, 2019 at 18:06
  • 1
    \$\begingroup\$ Can the length be in unary? \$\endgroup\$ Commented Nov 14, 2019 at 2:14
  • \$\begingroup\$ @someone I'm unfamiliar with unary outputs. I'd have to see it to confirm, but I imagine it can be a valid answer. \$\endgroup\$
    – Sumner18
    Commented Nov 14, 2019 at 13:54

39 Answers 39

1
2
1
\$\begingroup\$

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))

Try it online!

\$\endgroup\$
1
\$\begingroup\$

Röda, 53 bytes

{a=new map;a[#_]+=_1 if[a[#_1]?]else a[#_1]=[_1];[a]}

Try it online!

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
\$\endgroup\$
1
\$\begingroup\$

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
└∊─────────────────────────────────────────────────────────────────────────────────────────┘
\$\endgroup\$
1
\$\begingroup\$

C# (Visual C# Interactive Compiler), 48 bytes

a=>a.GroupBy(k=>k.Length,v=>v).OrderBy(g=>g.Key)

Try it online!

-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

\$\endgroup\$
2
  • 1
    \$\begingroup\$ I think you can simply return the results of the OrderBy. \$\endgroup\$ Commented Nov 15, 2019 at 1:03
  • \$\begingroup\$ @someone, It's kind of unclear but I'll add that as a third option too \$\endgroup\$
    – Malivil
    Commented Nov 15, 2019 at 14:04
1
\$\begingroup\$

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

Try it online!

\$\endgroup\$
2
  • \$\begingroup\$ Welcome to the site! The output format in this challenge is pretty loose so you could probably save some bytes if you move the print part to the footer in TIO. \$\endgroup\$
    – Malivil
    Commented Nov 22, 2019 at 15:03
  • 1
    \$\begingroup\$ Allright then, thanks for the hint. Im new to this so im learning :D \$\endgroup\$
    – LuaNoob
    Commented Nov 22, 2019 at 15:34
1
\$\begingroup\$

Husk, 8 bytes

mṠ,oL←kL

Try it online!

so close..

\$\endgroup\$
0
\$\begingroup\$

Arturo, 32 bytes

$=>[gather arrange&=>size=>size]

Try it

\$\endgroup\$
0
\$\begingroup\$

Python 3, 64 bytes

lambda x:{i:[*filter(lambda a:len(a)==i,x)]for i in range(1,11)}

Try it online!

\$\endgroup\$
0
\$\begingroup\$

Zsh, 52 bytes

for i;printf \ $i>>$#i;(for j (*)<<<$j`<$j`)|sort -n

Try it online!

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.

\$\endgroup\$
1
2

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.