Arrow those variables!I used to solve code golf puzzles like you, but then I took an arrow in the kneeOutput a Dance Dance Revolution arrow chartSorting a list of strings without using any built-in sort methodSolve a reverse arrow mazePost-determined Array SortingTranspile these ES6 arrow functions!The next colourPronunciationSort™Draw some expanding arrowsGreatest common substring

Why was the shrinking from 8″ made only to 5.25″ and not smaller (4″ or less)?

Took a trip to a parallel universe, need help deciphering

Blender 2.8 I can't see vertices, edges or faces in edit mode

In Romance of the Three Kingdoms why do people still use bamboo sticks when papers are already invented?

Where does SFDX store details about scratch orgs?

I would say: "You are another teacher", but she is a woman and I am a man

Can one be a co-translator of a book, if he does not know the language that the book is translated into?

Why is consensus so controversial in Britain?

Can a virus destroy the BIOS of a modern computer?

Why is Collection not simply treated as Collection<?>

Today is the Center

What killed these X2 caps?

Fully-Firstable Anagram Sets

Can a rocket refuel on Mars from water?

What is the most common color to indicate the input-field is disabled?

Infinite Abelian subgroup of infinite non Abelian group example

Why can't we play rap on piano?

I'm flying to France today and my passport expires in less than 2 months

Does a druid starting with a bow start with no arrows?

Assassin's bullet with mercury

CEO ridiculed me with gay jokes and grabbed me and wouldn't let go - now getting pushed out of company

AES: Why is it a good practice to use only the first 16bytes of a hash for encryption?

SSH "lag" in LAN on some machines, mixed distros

Why does Kotter return in Welcome Back Kotter



Arrow those variables!


I used to solve code golf puzzles like you, but then I took an arrow in the kneeOutput a Dance Dance Revolution arrow chartSorting a list of strings without using any built-in sort methodSolve a reverse arrow mazePost-determined Array SortingTranspile these ES6 arrow functions!The next colourPronunciationSort™Draw some expanding arrowsGreatest common substring













19












$begingroup$


Challenge



Robin likes having his variables declaration in the shape of an arrow. Here's how he does it:



  • Input any number of strings

  • Order them by ascending length


  • Output them ordered by the middle to roughly form a negative arrowhead, like this (whichever order golfs the best):



    5 or 4
    3 2
    1 1
    2 3
    4 5


Test Cases



Input:



bow
arrows
sheriffOfNottingham
kingRichard
maidMarian
princeJohn
sherwoodForest


Output:



sheriffOfNottingham
kingRichard
maidMarian
bow
arrows
princeJohn
sherwoodForest


Input:



a
bb
cc


Output (both are valid):



bb
a
cc

cc
a
bb


Input:



one
four
seven
fifteen


Possible output (the only other valid output is its vertical mirror):



seven
one
four
fifteen


Notes



  • The strings are in camelCase and have no numbers or special characters, only lowercase and uppercase letters.


  • The input can be anything you like: comma-separated as one string, array, ... Any I/O format is allowed.


  • Between strings with the same length, any order is accepted.









share|improve this question









New contributor




Teleporting Goat is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.







$endgroup$











  • $begingroup$
    I feel like there was a very similar challenge before...but welcome to PPCG!
    $endgroup$
    – Giuseppe
    yesterday











  • $begingroup$
    @Giuseppe Yeah that's what I thought after posting, there's no way it hasn't been done before. Would you be ok with me deleting it now that you've answered it?
    $endgroup$
    – Teleporting Goat
    yesterday











  • $begingroup$
    well I've been searching for a dupe but I'm not very good at the search...we do have a sandbox for posting challenges which can often catch things like that. I'm perfectly OK with you deleting it if you're worried about it being a dupe.
    $endgroup$
    – Giuseppe
    yesterday







  • 1




    $begingroup$
    It's OK, we all start from the beginning :-)
    $endgroup$
    – Giuseppe
    yesterday






  • 1




    $begingroup$
    Could you add a test case with an even number of strings?
    $endgroup$
    – Sherlock9
    yesterday















19












$begingroup$


Challenge



Robin likes having his variables declaration in the shape of an arrow. Here's how he does it:



  • Input any number of strings

  • Order them by ascending length


  • Output them ordered by the middle to roughly form a negative arrowhead, like this (whichever order golfs the best):



    5 or 4
    3 2
    1 1
    2 3
    4 5


Test Cases



Input:



bow
arrows
sheriffOfNottingham
kingRichard
maidMarian
princeJohn
sherwoodForest


Output:



sheriffOfNottingham
kingRichard
maidMarian
bow
arrows
princeJohn
sherwoodForest


Input:



a
bb
cc


Output (both are valid):



bb
a
cc

cc
a
bb


Input:



one
four
seven
fifteen


Possible output (the only other valid output is its vertical mirror):



seven
one
four
fifteen


Notes



  • The strings are in camelCase and have no numbers or special characters, only lowercase and uppercase letters.


  • The input can be anything you like: comma-separated as one string, array, ... Any I/O format is allowed.


  • Between strings with the same length, any order is accepted.









share|improve this question









New contributor




Teleporting Goat is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.







$endgroup$











  • $begingroup$
    I feel like there was a very similar challenge before...but welcome to PPCG!
    $endgroup$
    – Giuseppe
    yesterday











  • $begingroup$
    @Giuseppe Yeah that's what I thought after posting, there's no way it hasn't been done before. Would you be ok with me deleting it now that you've answered it?
    $endgroup$
    – Teleporting Goat
    yesterday











  • $begingroup$
    well I've been searching for a dupe but I'm not very good at the search...we do have a sandbox for posting challenges which can often catch things like that. I'm perfectly OK with you deleting it if you're worried about it being a dupe.
    $endgroup$
    – Giuseppe
    yesterday







  • 1




    $begingroup$
    It's OK, we all start from the beginning :-)
    $endgroup$
    – Giuseppe
    yesterday






  • 1




    $begingroup$
    Could you add a test case with an even number of strings?
    $endgroup$
    – Sherlock9
    yesterday













19












19








19


1



$begingroup$


Challenge



Robin likes having his variables declaration in the shape of an arrow. Here's how he does it:



  • Input any number of strings

  • Order them by ascending length


  • Output them ordered by the middle to roughly form a negative arrowhead, like this (whichever order golfs the best):



    5 or 4
    3 2
    1 1
    2 3
    4 5


Test Cases



Input:



bow
arrows
sheriffOfNottingham
kingRichard
maidMarian
princeJohn
sherwoodForest


Output:



sheriffOfNottingham
kingRichard
maidMarian
bow
arrows
princeJohn
sherwoodForest


Input:



a
bb
cc


Output (both are valid):



bb
a
cc

cc
a
bb


Input:



one
four
seven
fifteen


Possible output (the only other valid output is its vertical mirror):



seven
one
four
fifteen


Notes



  • The strings are in camelCase and have no numbers or special characters, only lowercase and uppercase letters.


  • The input can be anything you like: comma-separated as one string, array, ... Any I/O format is allowed.


  • Between strings with the same length, any order is accepted.









share|improve this question









New contributor




Teleporting Goat is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.







$endgroup$




Challenge



Robin likes having his variables declaration in the shape of an arrow. Here's how he does it:



  • Input any number of strings

  • Order them by ascending length


  • Output them ordered by the middle to roughly form a negative arrowhead, like this (whichever order golfs the best):



    5 or 4
    3 2
    1 1
    2 3
    4 5


Test Cases



Input:



bow
arrows
sheriffOfNottingham
kingRichard
maidMarian
princeJohn
sherwoodForest


Output:



sheriffOfNottingham
kingRichard
maidMarian
bow
arrows
princeJohn
sherwoodForest


Input:



a
bb
cc


Output (both are valid):



bb
a
cc

cc
a
bb


Input:



one
four
seven
fifteen


Possible output (the only other valid output is its vertical mirror):



seven
one
four
fifteen


Notes



  • The strings are in camelCase and have no numbers or special characters, only lowercase and uppercase letters.


  • The input can be anything you like: comma-separated as one string, array, ... Any I/O format is allowed.


  • Between strings with the same length, any order is accepted.






code-golf string sorting






share|improve this question









New contributor




Teleporting Goat is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











share|improve this question









New contributor




Teleporting Goat is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









share|improve this question




share|improve this question








edited yesterday







Teleporting Goat













New contributor




Teleporting Goat is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









asked yesterday









Teleporting GoatTeleporting Goat

1965




1965




New contributor




Teleporting Goat is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.





New contributor





Teleporting Goat is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.






Teleporting Goat is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











  • $begingroup$
    I feel like there was a very similar challenge before...but welcome to PPCG!
    $endgroup$
    – Giuseppe
    yesterday











  • $begingroup$
    @Giuseppe Yeah that's what I thought after posting, there's no way it hasn't been done before. Would you be ok with me deleting it now that you've answered it?
    $endgroup$
    – Teleporting Goat
    yesterday











  • $begingroup$
    well I've been searching for a dupe but I'm not very good at the search...we do have a sandbox for posting challenges which can often catch things like that. I'm perfectly OK with you deleting it if you're worried about it being a dupe.
    $endgroup$
    – Giuseppe
    yesterday







  • 1




    $begingroup$
    It's OK, we all start from the beginning :-)
    $endgroup$
    – Giuseppe
    yesterday






  • 1




    $begingroup$
    Could you add a test case with an even number of strings?
    $endgroup$
    – Sherlock9
    yesterday
















  • $begingroup$
    I feel like there was a very similar challenge before...but welcome to PPCG!
    $endgroup$
    – Giuseppe
    yesterday











  • $begingroup$
    @Giuseppe Yeah that's what I thought after posting, there's no way it hasn't been done before. Would you be ok with me deleting it now that you've answered it?
    $endgroup$
    – Teleporting Goat
    yesterday











  • $begingroup$
    well I've been searching for a dupe but I'm not very good at the search...we do have a sandbox for posting challenges which can often catch things like that. I'm perfectly OK with you deleting it if you're worried about it being a dupe.
    $endgroup$
    – Giuseppe
    yesterday







  • 1




    $begingroup$
    It's OK, we all start from the beginning :-)
    $endgroup$
    – Giuseppe
    yesterday






  • 1




    $begingroup$
    Could you add a test case with an even number of strings?
    $endgroup$
    – Sherlock9
    yesterday















$begingroup$
I feel like there was a very similar challenge before...but welcome to PPCG!
$endgroup$
– Giuseppe
yesterday





$begingroup$
I feel like there was a very similar challenge before...but welcome to PPCG!
$endgroup$
– Giuseppe
yesterday













$begingroup$
@Giuseppe Yeah that's what I thought after posting, there's no way it hasn't been done before. Would you be ok with me deleting it now that you've answered it?
$endgroup$
– Teleporting Goat
yesterday





$begingroup$
@Giuseppe Yeah that's what I thought after posting, there's no way it hasn't been done before. Would you be ok with me deleting it now that you've answered it?
$endgroup$
– Teleporting Goat
yesterday













$begingroup$
well I've been searching for a dupe but I'm not very good at the search...we do have a sandbox for posting challenges which can often catch things like that. I'm perfectly OK with you deleting it if you're worried about it being a dupe.
$endgroup$
– Giuseppe
yesterday





$begingroup$
well I've been searching for a dupe but I'm not very good at the search...we do have a sandbox for posting challenges which can often catch things like that. I'm perfectly OK with you deleting it if you're worried about it being a dupe.
$endgroup$
– Giuseppe
yesterday





1




1




$begingroup$
It's OK, we all start from the beginning :-)
$endgroup$
– Giuseppe
yesterday




$begingroup$
It's OK, we all start from the beginning :-)
$endgroup$
– Giuseppe
yesterday




1




1




$begingroup$
Could you add a test case with an even number of strings?
$endgroup$
– Sherlock9
yesterday




$begingroup$
Could you add a test case with an even number of strings?
$endgroup$
– Sherlock9
yesterday










24 Answers
24






active

oldest

votes


















11












$begingroup$


Python 2, 47 bytes





lambda l:l.sort(key=len)or l[1::2][::-1]+l[::2]


Try it online!






share|improve this answer









$endgroup$












  • $begingroup$
    You'll need to rearrange some stuff, but you can use [::-2] directly to save 5 bytes.
    $endgroup$
    – Sherlock9
    yesterday










  • $begingroup$
    @Sherlock9 I tried that, but then I had to check for the length, as lists with even / uneven lengths have to be handled differently.
    $endgroup$
    – ovs
    yesterday


















9












$begingroup$


R, 63 48 bytes





function(L)c(rev(o<-L[order(nchar(L))]),o)[!0:1]


Try it online!



Sort by string lengths, then combine the reversed list with the sorted list, finally, take every 2nd element, starting at 1-based index 1.






share|improve this answer











$endgroup$












  • $begingroup$
    o<-L[... The other way to 'arrow variables'. A less important aside, pryr::f(...) works here for 46. Try it online!
    $endgroup$
    – CriminallyVulgar
    20 hours ago


















5












$begingroup$


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





n=>(n=n.OrderBy(x=>x.Length)).Where((a,b)=>b%2>0).Reverse().Concat(n.Where((a,b)=>b%2<1))


Try it online!






share|improve this answer









$endgroup$




















    5












    $begingroup$


    K (oK), 24 bytes



    Solution:



    x(<#:'x)(|&~w),&w:2!!#x:


    Try it online!



    Explanation:



    Generate the 6 4 2 0 1 3 5 sequence, use that to index into the ascending lengths of input, and use that to index into the original array:



    x(<#:'x)(|&~w),&w:2!!#x: / the solution
    x: / save input as x
    # / count (#) of x
    ! / range 0 to ...
    2! / modulo 2
    w: / save as w
    & / indices where true
    , / join with
    ( ) / do this together
    ~w / not (~) w
    & / indices where true
    | / reverse
    ( ) / do this together
    #:'x / count (#:) of each (') x
    < / indices to sort ascending
    x / index into x





    share|improve this answer











    $endgroup$




















      5












      $begingroup$


      Jelly, 9 8 bytes



      LÞŒœm"-Ẏ


      Try it online!



      LÞŒœṚ;¥/


      is also 8 bytes.



      Thanks to @EriktheOutgolfer and @JonathanAllan for both offering golfs to save a byte.






      share|improve this answer











      $endgroup$












      • $begingroup$
        Nice! Clever golf: Ṛ€1¦ can become m"-.
        $endgroup$
        – Erik the Outgolfer
        yesterday










      • $begingroup$
        Or you could go for LÞŒœṚ;¥/
        $endgroup$
        – Jonathan Allan
        yesterday


















      5












      $begingroup$


      05AB1E, 6 5 bytes



      Saved 1 byte thanks to Kevin Cruijssen



      I/O is a list of strings.

      Link is modified for newline separated I/O for easier testing.



      éι`Rì


      Try it online!



      Explanation



      é # sort by length ascending
      ι # uninterleave into 2 parts, both sorted ascending
      ` # push the 2 parts separately to the stack
      R # reverse the second part
      ì # and append it to the first





      share|improve this answer











      $endgroup$












      • $begingroup$
        You can remove the first R and replace « with i to save a byte, since the third bullet-point rule allows both versions of uninterleaving.
        $endgroup$
        – Kevin Cruijssen
        21 hours ago










      • $begingroup$
        @KevinCruijssen: Oh yeah, Thanks!
        $endgroup$
        – Emigna
        19 hours ago


















      4












      $begingroup$


      PowerShell, 66 bytes





      1..($a=$args|sort l*).count|?$_%2|%$a[-$_];$x=,$a[-++$_]+$x;$x


      Try it online!



      Takes input via splatting, which manifests on TIO as separate command-line arguments. sorts on the length, stores that into $a, and constructs a range from 1 up to the count of input strings. We then pull out only the odd ones ?$_%2 and feed those into a loop |%.... Each iteration, we put the "last", then the "third from last", and so on onto the pipeline with $a[-$_]. Separately, we also accumulate into $x the "second from last", "fourth from last", etc. Out of the loop and the pipeline is flushed (so those elements are output) and then we output $x. In both instances, the default output gives us newlines between items automatically.






      share|improve this answer









      $endgroup$




















        4












        $begingroup$


        Ruby, 51 bytes





        ->lr=1;l.sort_by!(&:size).map


        Try it online!






        share|improve this answer









        $endgroup$




















          4












          $begingroup$


          J, 11 bytes



          ,~`,/@:#&>


          Try it online!



          We sort it down first.



          Then we reduce the list form right to left, but alternating which side we put the new element on. Done.






          share|improve this answer











          $endgroup$












          • $begingroup$
            Very nice! You have a space at the end though, remove it for 11 bytes :)
            $endgroup$
            – Galen Ivanov
            22 hours ago






          • 1




            $begingroup$
            Thanks Galen. Fixed!
            $endgroup$
            – Jonah
            18 hours ago


















          4












          $begingroup$

          Javascript 77 bytes



          Takes input as an array of strings, outputs an arrow-sorted array of strings.



          s=>s.sort((a,b)=>a.length-b.length).reduce((m,x,i)=>i%2?[...m,x]:[x,...m],[])


          Explanation



          s => // take input as an array of strings s
          s.sort((a,b)=>a.length-b.length) // sort input by string length
          .reduce( // reduce
          (m,x,i)=>i%2?[...m,x]:[x,...m], // if index is even, stick string x at the end of the memo
          // array, else at the beginning
          [] // memo initialized to empty array
          )





          share|improve this answer











          $endgroup$












          • $begingroup$
            I don't think you have to count f=. 77
            $endgroup$
            – dana
            16 hours ago










          • $begingroup$
            That is inconsistent in the js code golf submissions from what I have seen. I'm happy to exclude it if it doesn't count.
            $endgroup$
            – asgallant
            12 hours ago










          • $begingroup$
            I think it depends whether your function uses recursion. i.e. f=x=>x?f(x-1). If so, you need to include f since you are calling it in your function. However, since you are not using recursion, you shouldn't have to include f. There are several posts in Meta, this one seems to explain it a little better. codegolf.meta.stackexchange.com/a/9032/8340
            $endgroup$
            – dana
            11 hours ago










          • $begingroup$
            That would explain the inconsistencies I've seen.
            $endgroup$
            – asgallant
            11 hours ago


















          3












          $begingroup$


          PHP, 144 bytes





          function($a)usort($a,function($b,$c)return strlen($b)-strlen($c););$e=[];foreach($a as$d)[array_unshift,array_push][++$i%2]($e,$d);return$e;


          Try it online!



          Sadly, PHP just doesn't have a lot of syntactic sugar to make this shorter. Submitting it anyway!






          share|improve this answer









          $endgroup$












          • $begingroup$
            nice one. Where can I read more about [array_unshift,array_push][++$i%2]($e,$d)?
            $endgroup$
            – abhig10
            18 hours ago






          • 1




            $begingroup$
            @abhig10 sure. It's an array with the two function names ['array_push','array_unshift'] with [++$i%2] as the index of the array alternating between a 0 or 1 so will evaluate to the other function each time. PHP's "variable functions" let you assign a varible to a function and execute by calling with parenthesis (ex: $f='array_push'; $f($e,$d); == array_push($e,$d)) so the ($e,$d) is then calling the evaluated element of the array. Just a shorter way to do if (++$i%2) array_push($e,$d); else array_unshift($e,$e);. Guess there was some PHP syntactic sugar after all!
            $endgroup$
            – gwaugh
            13 hours ago











          • $begingroup$
            Okay, it took me sometime to understand this. Awesome.
            $endgroup$
            – abhig10
            13 hours ago


















          2












          $begingroup$

          APL+WIN, 31 38 bytes



          See Adams comment



          ⊃n[(⍳⍴n)~a],⌽n[a←2×⍳⌊.5×⍴n←n[⍒∊⍴¨n←⎕]]


          Try it online Courtesy of Dyalog Classic!



          Prompts for a nested vector of strings






          share|improve this answer











          $endgroup$












          • $begingroup$
            Does APL+ not have Monadic "tally" to replace ∊⍴ ?
            $endgroup$
            – Adám
            yesterday







          • 1




            $begingroup$
            Fails on '12' '1234' '1234' '1234' '1234' '12345678' '12345678' '12345678' '12345678'. Clearly, the result should have been '12345678' '12345678' '1234' '1234' '12' '1234' '1234' '12345678' '12345678'
            $endgroup$
            – Adám
            yesterday










          • $begingroup$
            @Adám My ancient version of APL+ does not have ≢. Agreed on your second comment I will take a look at it tomorrow.
            $endgroup$
            – Graham
            yesterday


















          2












          $begingroup$


          Retina, 26 bytes



          N$`
          $.&
          *,2,^A`.+
          ,2,G`.+


          Try it online! Explanation:



          N$`
          $.&


          Sort the lines in ascending order of length ($.& returns the length of the line).



          *,2,^A`.+


          Temporarily delete alternate lines and output the remaining lines in reverse order.



          ,2,G`.+


          Keep the only lines that were temporarily deleted and output them.






          share|improve this answer









          $endgroup$




















            2












            $begingroup$


            Gaia, 10 bytes



            el∫v:v+2%ụ


            Try it online!



            e		| eval as Gaia code (list of strings)
            l∫ | ∫ort by lengths (ascending)
            v:v | reverse, dup, reverse
            + | concatenate lists
            2% | take every other element
            ụ | join by newlines and output





            share|improve this answer









            $endgroup$








            • 3




              $begingroup$
              i like that your comments in unwrapped code form an arrow of strings
              $endgroup$
              – aaaaaa
              yesterday


















            2












            $begingroup$

            Japt, 8 bytes



            ñÊó g0_w


            -3 bytes thanks to Shaggy!



            Try it






            share|improve this answer











            $endgroup$












            • $begingroup$
              10 bytes with output as a 2D-array, which would seem to be allowed.
              $endgroup$
              – Shaggy
              yesterday










            • $begingroup$
              Or, maybe, 8 bytes? On my phone so haven't tested it properly.
              $endgroup$
              – Shaggy
              yesterday










            • $begingroup$
              @Shaggy I was looking for a function to find every nth element, but I couldn't find it. Thanks!
              $endgroup$
              – Embodiment of Ignorance
              yesterday










            • $begingroup$
              there's also A.ë() but I don't know if that'll lead to a shorter solution.
              $endgroup$
              – Shaggy
              yesterday


















            2












            $begingroup$


            PowerShell, 49 bytes





            $args|sort l*|sort$_.Length*($global:x=-$x*2+1)


            Try it online!



            The double distillation.






            share|improve this answer











            $endgroup$




















              2












              $begingroup$

              T-SQL, 84 bytes



              Input is a table variable



              SELECT a FROM(SELECT*,row_number()over(order by len(a))r
              FROM @)x order by(r%2-.5)*r


              Try it online






              share|improve this answer











              $endgroup$




















                2












                $begingroup$

                MATLAB, 95 bytes



                function z=f(y);[B,I]=sort(cellfun(@(x)length(x),y));z=yflip(I(1:2:end)),yI(2:2:end)';end


                Takes input as cell array of strings, outputs column of strings (not sure if that's legal)



                > s = 'qweq qwe qw','qweqw','12132132131231231','asdasdasda','qwe','w';
                > f(s)
                >
                > function z=f(y);[B,I]=sort(cellfun(@(x)length(x),y));z=yflip(I(1:2:end)),yI(2:2:end)';end
                >
                > >>
                > ans =
                >
                > 6×1 cell array
                >
                > 'qweq qwe qw'
                > 'qweqw'
                > 'qwe'
                > '1234'
                > 'asdasdasda'
                > '12132132131231231'


                PS: Thanks Sanchises for pointing to a bug with odd-length inputs






                share|improve this answer











                $endgroup$












                • $begingroup$
                  This fails on odd number of input strings, e.g. f('loooooooong','medium','short')
                  $endgroup$
                  – Sanchises
                  18 hours ago










                • $begingroup$
                  Also some general golfing tips: the end is optional for a function. Using function x=f(y);x=...' is shorter than function f(y);disp(...').
                  $endgroup$
                  – Sanchises
                  18 hours ago










                • $begingroup$
                  If you're stuck, here's how I would do it.
                  $endgroup$
                  – Sanchises
                  18 hours ago










                • $begingroup$
                  @Sanchises thanks for pointing bug out. I did fix it exactly like you did. My issue with disp is i am not sure what output rules are. Should it be pure text or not? or disp(...) is okay or even just x=... as you suggest
                  $endgroup$
                  – aaaaaa
                  11 hours ago










                • $begingroup$
                  That question can be quite tricky to answer. In general however, input/output is as flexible as possible so you can focus on the main challenge (there's a list of allowed I/O by default on meta) and in this case, no extra restrictions are specified by the OP. In my experience, just y=input('');doSomething() (without trailing semicolon to output the result) is shortest in MATLAB
                  $endgroup$
                  – Sanchises
                  11 hours ago


















                1












                $begingroup$

                Javascript 95 Bytes



                s=>s.sort((x,y)=>x.length-y.length).reduce((a,e,i)=>i%2?a.push(e):a.unshift(e);return a;,[]);





                share|improve this answer










                New contributor




                somsom is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                Check out our Code of Conduct.






                $endgroup$












                • $begingroup$
                  -1 s.sort() sorts the strings lexicographically, not by string length.
                  $endgroup$
                  – asgallant
                  yesterday










                • $begingroup$
                  Right, (x,y)=>x.length-y.length, should fix that.
                  $endgroup$
                  – somsom
                  yesterday


















                1












                $begingroup$


                Red, 116 101 bytes



                func[b][sort/compare b func[x y][(length? x)> length? y]collect[forall b[keep take b]keep reverse b]]


                Try it online!






                share|improve this answer











                $endgroup$




















                  1












                  $begingroup$

                  perl 5 (-p0777F/n/ -M5.01), 59 bytes



                  for$x(sort$b=~y///c-length$a@F)--$} join by newlines and output





                  share 











                  1












                  $begingroup$

                  perl 5 (-p0777F/n/ -M5.01), 59 bytes



                  for$x(sort$b=~y///c-length$a@F)--$


                  TIO






                  shareimprove this answer











                  $endgroup$



                  perl 5 (-p0777F/n/ -M5.01), 59 bytes



                  for$x(sort$b=~y///c-length$a@F)--${


                  TIO







                  share|improve this answer














                  share|improve this answer



                  share|improve this answer








                  edited 19 hours ago

























                  answered 20 hours ago









                  Nahuel FouilleulNahuel Fouilleul

                  3,015211




                  3,015211





















                      1












                      $begingroup$


                      C (gcc), 136 bytes





                      S(a,b)char**a,**b;a=strlen(*b)-strlen(*a);f(l,s,o,t,i,b,e)char**s,**o,*t;qsort(s,l,8,S);e=l-1;for(i=b=0;i-l;++i)o[i%2?b++:e--]=s[i];


                      Try it online!



                      The function f is the solution. It takes the number of strings, the strings themselves, and the output buffer as arguments (plus four more used internally).






                      share|improve this answer











                      $endgroup$












                      • $begingroup$
                        Why is ./.bin.tio in the output?
                        $endgroup$
                        – Teleporting Goat
                        yesterday










                      • $begingroup$
                        @TeleportingGoat Probably because their footer is using all of argv, which includes the filename
                        $endgroup$
                        – Jo King
                        yesterday










                      • $begingroup$
                        Exactly, it was just a quick test. One can construct any data that takes appropriate format. I'll update the TIO link later.
                        $endgroup$
                        – LambdaBeta
                        14 hours ago















                      1












                      $begingroup$


                      C (gcc), 136 bytes





                      S(a,b)char**a,**b;a=strlen(*b)-strlen(*a);f(l,s,o,t,i,b,e)char**s,**o,*t;qsort(s,l,8,S);e=l-1;for(i=b=0;i-l;++i)o[i%2?b++:e--]=s[i];


                      Try it online!



                      The function f is the solution. It takes the number of strings, the strings themselves, and the output buffer as arguments (plus four more used internally).






                      share|improve this answer











                      $endgroup$












                      • $begingroup$
                        Why is ./.bin.tio in the output?
                        $endgroup$
                        – Teleporting Goat
                        yesterday










                      • $begingroup$
                        @TeleportingGoat Probably because their footer is using all of argv, which includes the filename
                        $endgroup$
                        – Jo King
                        yesterday










                      • $begingroup$
                        Exactly, it was just a quick test. One can construct any data that takes appropriate format. I'll update the TIO link later.
                        $endgroup$
                        – LambdaBeta
                        14 hours ago













                      1












                      1








                      1





                      $begingroup$


                      C (gcc), 136 bytes





                      S(a,b)char**a,**b;a=strlen(*b)-strlen(*a);f(l,s,o,t,i,b,e)char**s,**o,*t;qsort(s,l,8,S);e=l-1;for(i=b=0;i-l;++i)o[i%2?b++:e--]=s[i];


                      Try it online!



                      The function f is the solution. It takes the number of strings, the strings themselves, and the output buffer as arguments (plus four more used internally).






                      share|improve this answer











                      $endgroup$




                      C (gcc), 136 bytes





                      S(a,b)char**a,**b;a=strlen(*b)-strlen(*a);f(l,s,o,t,i,b,e)char**s,**o,*t;qsort(s,l,8,S);e=l-1;for(i=b=0;i-l;++i)o[i%2?b++:e--]=s[i];


                      Try it online!



                      The function f is the solution. It takes the number of strings, the strings themselves, and the output buffer as arguments (plus four more used internally).







                      share|improve this answer














                      share|improve this answer



                      share|improve this answer








                      edited 14 hours ago

























                      answered yesterday









                      LambdaBetaLambdaBeta

                      2,149418




                      2,149418











                      • $begingroup$
                        Why is ./.bin.tio in the output?
                        $endgroup$
                        – Teleporting Goat
                        yesterday










                      • $begingroup$
                        @TeleportingGoat Probably because their footer is using all of argv, which includes the filename
                        $endgroup$
                        – Jo King
                        yesterday










                      • $begingroup$
                        Exactly, it was just a quick test. One can construct any data that takes appropriate format. I'll update the TIO link later.
                        $endgroup$
                        – LambdaBeta
                        14 hours ago
















                      • $begingroup$
                        Why is ./.bin.tio in the output?
                        $endgroup$
                        – Teleporting Goat
                        yesterday










                      • $begingroup$
                        @TeleportingGoat Probably because their footer is using all of argv, which includes the filename
                        $endgroup$
                        – Jo King
                        yesterday










                      • $begingroup$
                        Exactly, it was just a quick test. One can construct any data that takes appropriate format. I'll update the TIO link later.
                        $endgroup$
                        – LambdaBeta
                        14 hours ago















                      $begingroup$
                      Why is ./.bin.tio in the output?
                      $endgroup$
                      – Teleporting Goat
                      yesterday




                      $begingroup$
                      Why is ./.bin.tio in the output?
                      $endgroup$
                      – Teleporting Goat
                      yesterday












                      $begingroup$
                      @TeleportingGoat Probably because their footer is using all of argv, which includes the filename
                      $endgroup$
                      – Jo King
                      yesterday




                      $begingroup$
                      @TeleportingGoat Probably because their footer is using all of argv, which includes the filename
                      $endgroup$
                      – Jo King
                      yesterday












                      $begingroup$
                      Exactly, it was just a quick test. One can construct any data that takes appropriate format. I'll update the TIO link later.
                      $endgroup$
                      – LambdaBeta
                      14 hours ago




                      $begingroup$
                      Exactly, it was just a quick test. One can construct any data that takes appropriate format. I'll update the TIO link later.
                      $endgroup$
                      – LambdaBeta
                      14 hours ago











                      1












                      $begingroup$


                      APL (Dyalog Unicode), 18 bytesSBCS





                      ⍪⍵[⍋-@(2∘


                      Try it online!



                      Explanation:



                      ⍪⍵[⍋-@(2∘
                      ⍝ Function. Takes a single argument: ⍵, list of strings
                      ≢¨⍵ ⍝ The length of each element in the list
                      ⍋ ⍝ Grade: return the indices of the sorted list
                      -@(2∘|) ⍝ At (@) elements divisible by 2 (|), negate (-)
                      ⍝ gives -1 2 -3 4 -5
                      ⍋ ⍝ Sort this list again, gives the indices of that list ^ sorted
                      ⍵[ ] ⍝ Use these indices to index into the argument
                      ⍪ ⍝ Table-ify the result



                      ¹






                      share|improve this answer











                      $endgroup$

















                        1












                        $begingroup$


                        APL (Dyalog Unicode), 18 bytesSBCS





                        ⍪⍵[⍋-@(2∘


                        Try it online!



                        Explanation:



                        ⍪⍵[⍋-@(2∘
                        ⍝ Function. Takes a single argument: ⍵, list of strings
                        ≢¨⍵ ⍝ The length of each element in the list
                        ⍋ ⍝ Grade: return the indices of the sorted list
                        -@(2∘|) ⍝ At (@) elements divisible by 2 (|), negate (-)
                        ⍝ gives -1 2 -3 4 -5
                        ⍋ ⍝ Sort this list again, gives the indices of that list ^ sorted
                        ⍵[ ] ⍝ Use these indices to index into the argument
                        ⍪ ⍝ Table-ify the result



                        ¹






                        share|improve this answer











                        $endgroup$















                          1












                          1








                          1





                          $begingroup$


                          APL (Dyalog Unicode), 18 bytesSBCS





                          ⍪⍵[⍋-@(2∘


                          Try it online!



                          Explanation:



                          ⍪⍵[⍋-@(2∘
                          ⍝ Function. Takes a single argument: ⍵, list of strings
                          ≢¨⍵ ⍝ The length of each element in the list
                          ⍋ ⍝ Grade: return the indices of the sorted list
                          -@(2∘|) ⍝ At (@) elements divisible by 2 (|), negate (-)
                          ⍝ gives -1 2 -3 4 -5
                          ⍋ ⍝ Sort this list again, gives the indices of that list ^ sorted
                          ⍵[ ] ⍝ Use these indices to index into the argument
                          ⍪ ⍝ Table-ify the result



                          ¹






                          share|improve this answer











                          $endgroup$




                          APL (Dyalog Unicode), 18 bytesSBCS





                          ⍪⍵[⍋-@(2∘


                          Try it online!



                          Explanation:



                          ⍪⍵[⍋-@(2∘
                          ⍝ Function. Takes a single argument: ⍵, list of strings
                          ≢¨⍵ ⍝ The length of each element in the list
                          ⍋ ⍝ Grade: return the indices of the sorted list
                          -@(2∘|) ⍝ At (@) elements divisible by 2 (|), negate (-)
                          ⍝ gives -1 2 -3 4 -5
                          ⍋ ⍝ Sort this list again, gives the indices of that list ^ sorted
                          ⍵[ ] ⍝ Use these indices to index into the argument
                          ⍪ ⍝ Table-ify the result



                          ¹







                          share|improve this answer














                          share|improve this answer



                          share|improve this answer








                          edited 11 hours ago

























                          answered 16 hours ago









                          VenVen

                          2,50511223




                          2,50511223





















                              0












                              $begingroup$


                              Japt, 8 bytes



                              Input as an array of lines, output as an array of 2 arrays of lines, one for each half of the list.



                              ñÊó
                              hUÎÔ


                              Try it (Additional code to allow for I/O as newline separated string)



                              ñÊó :Implicit input of array U
                              ñ :Sort by
                              Ê : Length
                              ó :Uninterleave

                              hUÎÔ :Newline reassigns to U
                              h :Set the first element in U to
                              UÎ : The first element in U
                              Ô : Reversed





                              share|improve this answer









                              $endgroup$

















                                0












                                $begingroup$


                                Japt, 8 bytes



                                Input as an array of lines, output as an array of 2 arrays of lines, one for each half of the list.



                                ñÊó
                                hUÎÔ


                                Try it (Additional code to allow for I/O as newline separated string)



                                ñÊó :Implicit input of array U
                                ñ :Sort by
                                Ê : Length
                                ó :Uninterleave

                                hUÎÔ :Newline reassigns to U
                                h :Set the first element in U to
                                UÎ : The first element in U
                                Ô : Reversed





                                share|improve this answer









                                $endgroup$















                                  0












                                  0








                                  0





                                  $begingroup$


                                  Japt, 8 bytes



                                  Input as an array of lines, output as an array of 2 arrays of lines, one for each half of the list.



                                  ñÊó
                                  hUÎÔ


                                  Try it (Additional code to allow for I/O as newline separated string)



                                  ñÊó :Implicit input of array U
                                  ñ :Sort by
                                  Ê : Length
                                  ó :Uninterleave

                                  hUÎÔ :Newline reassigns to U
                                  h :Set the first element in U to
                                  UÎ : The first element in U
                                  Ô : Reversed





                                  share|improve this answer









                                  $endgroup$




                                  Japt, 8 bytes



                                  Input as an array of lines, output as an array of 2 arrays of lines, one for each half of the list.



                                  ñÊó
                                  hUÎÔ


                                  Try it (Additional code to allow for I/O as newline separated string)



                                  ñÊó :Implicit input of array U
                                  ñ :Sort by
                                  Ê : Length
                                  ó :Uninterleave

                                  hUÎÔ :Newline reassigns to U
                                  h :Set the first element in U to
                                  UÎ : The first element in U
                                  Ô : Reversed






                                  share|improve this answer












                                  share|improve this answer



                                  share|improve this answer










                                  answered 18 hours ago









                                  ShaggyShaggy

                                  18.8k21768




                                  18.8k21768




















                                      Teleporting Goat is a new contributor. Be nice, and check out our Code of Conduct.









                                      draft saved

                                      draft discarded


















                                      Teleporting Goat is a new contributor. Be nice, and check out our Code of Conduct.












                                      Teleporting Goat is a new contributor. Be nice, and check out our Code of Conduct.











                                      Teleporting Goat is a new contributor. Be nice, and check out our Code of Conduct.














                                      If this is an answer to a challenge…



                                      • …Be sure to follow the challenge specification. However, please refrain from exploiting obvious loopholes. Answers abusing any of the standard loopholes are considered invalid. If you think a specification is unclear or underspecified, comment on the question instead.


                                      • …Try to optimize your score. For instance, answers to code-golf challenges should attempt to be as short as possible. You can always include a readable version of the code in addition to the competitive one.
                                        Explanations of your answer make it more interesting to read and are very much encouraged.


                                      • …Include a short header which indicates the language(s) of your code and its score, as defined by the challenge.


                                      More generally…



                                      • …Please make sure to answer the question and provide sufficient detail.


                                      • …Avoid asking for help, clarification or responding to other answers (use comments instead).




                                      draft saved


                                      draft discarded














                                      StackExchange.ready(
                                      function ()
                                      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodegolf.stackexchange.com%2fquestions%2f182615%2farrow-those-variables%23new-answer', 'question_page');

                                      );

                                      Post as a guest















                                      Required, but never shown





















































                                      Required, but never shown














                                      Required, but never shown












                                      Required, but never shown







                                      Required, but never shown

































                                      Required, but never shown














                                      Required, but never shown












                                      Required, but never shown







                                      Required, but never shown







                                      Popular posts from this blog

                                      Get product attribute by attribute group code in magento 2get product attribute by product attribute group in magento 2Magento 2 Log Bundle Product Data in List Page?How to get all product attribute of a attribute group of Default attribute set?Magento 2.1 Create a filter in the product grid by new attributeMagento 2 : Get Product Attribute values By GroupMagento 2 How to get all existing values for one attributeMagento 2 get custom attribute of a single product inside a pluginMagento 2.3 How to get all the Multi Source Inventory (MSI) locations collection in custom module?Magento2: how to develop rest API to get new productsGet product attribute by attribute group code ( [attribute_group_code] ) in magento 2

                                      Category:9 (number) SubcategoriesMedia in category "9 (number)"Navigation menuUpload mediaGND ID: 4485639-8Library of Congress authority ID: sh85091979ReasonatorScholiaStatistics

                                      Magento 2.3: How do i solve this, Not registered handle, on custom form?How can i rewrite TierPrice Block in Magento2magento 2 captcha not rendering if I override layout xmlmain.CRITICAL: Plugin class doesn't existMagento 2 : Problem while adding custom button order view page?Magento 2.2.5: Overriding Admin Controller sales/orderMagento 2.2.5: Add, Update and Delete existing products Custom OptionsMagento 2.3 : File Upload issue in UI Component FormMagento2 Not registered handleHow to configured Form Builder Js in my custom magento 2.3.0 module?Magento 2.3. How to create image upload field in an admin form