Split into three!





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ margin-bottom:0;
}







16












$begingroup$



Given a string, you've to split it into groups of three characters (by padding _ at the end).



Related, but still it's different.






Sample I/O:




  • 'abcde' -> 'abc', 'de_'


  • '1234' -> '123', '4__'


  • '' -> or falsey value


  • 'Three spree!' -> 'Thr', 'ee ', 'spr', 'ee!'


  • 6 MB string



This is a code-golf, so fewest bytes will win!



Edit: Finally, output is unrestricted.










share|improve this question











$endgroup$








  • 10




    $begingroup$
    Why special case the empty string? May we choose which character to use for the padding?
    $endgroup$
    – Shaggy
    May 19 at 14:49






  • 12




    $begingroup$
    So the task is actually: Given a string, return a falsey value if it is empty, otherwise split it into groups of three, padding with underscores if necessary? Seems like an odd pair-up of two unrelated tasks (checking string length and splitting).
    $endgroup$
    – Adám
    May 19 at 15:27






  • 14




    $begingroup$
    Things to avoid: Exceptional edge cases. In this case, an empty string should returnan empty array or equivalent, not a falsey value
    $endgroup$
    – Jo King
    May 19 at 22:05








  • 6




    $begingroup$
    Lots of statically-typed languages cannot return more than one type from a function
    $endgroup$
    – Embodiment of Ignorance
    May 19 at 23:30






  • 4




    $begingroup$
    @manassehkatz Yes, but only in those languages. In some languages it makes solutions far more complicated, or even impossible (e.g statically typed languages).
    $endgroup$
    – Jo King
    May 20 at 22:01


















16












$begingroup$



Given a string, you've to split it into groups of three characters (by padding _ at the end).



Related, but still it's different.






Sample I/O:




  • 'abcde' -> 'abc', 'de_'


  • '1234' -> '123', '4__'


  • '' -> or falsey value


  • 'Three spree!' -> 'Thr', 'ee ', 'spr', 'ee!'


  • 6 MB string



This is a code-golf, so fewest bytes will win!



Edit: Finally, output is unrestricted.










share|improve this question











$endgroup$








  • 10




    $begingroup$
    Why special case the empty string? May we choose which character to use for the padding?
    $endgroup$
    – Shaggy
    May 19 at 14:49






  • 12




    $begingroup$
    So the task is actually: Given a string, return a falsey value if it is empty, otherwise split it into groups of three, padding with underscores if necessary? Seems like an odd pair-up of two unrelated tasks (checking string length and splitting).
    $endgroup$
    – Adám
    May 19 at 15:27






  • 14




    $begingroup$
    Things to avoid: Exceptional edge cases. In this case, an empty string should returnan empty array or equivalent, not a falsey value
    $endgroup$
    – Jo King
    May 19 at 22:05








  • 6




    $begingroup$
    Lots of statically-typed languages cannot return more than one type from a function
    $endgroup$
    – Embodiment of Ignorance
    May 19 at 23:30






  • 4




    $begingroup$
    @manassehkatz Yes, but only in those languages. In some languages it makes solutions far more complicated, or even impossible (e.g statically typed languages).
    $endgroup$
    – Jo King
    May 20 at 22:01














16












16








16


3



$begingroup$



Given a string, you've to split it into groups of three characters (by padding _ at the end).



Related, but still it's different.






Sample I/O:




  • 'abcde' -> 'abc', 'de_'


  • '1234' -> '123', '4__'


  • '' -> or falsey value


  • 'Three spree!' -> 'Thr', 'ee ', 'spr', 'ee!'


  • 6 MB string



This is a code-golf, so fewest bytes will win!



Edit: Finally, output is unrestricted.










share|improve this question











$endgroup$





Given a string, you've to split it into groups of three characters (by padding _ at the end).



Related, but still it's different.






Sample I/O:




  • 'abcde' -> 'abc', 'de_'


  • '1234' -> '123', '4__'


  • '' -> or falsey value


  • 'Three spree!' -> 'Thr', 'ee ', 'spr', 'ee!'


  • 6 MB string



This is a code-golf, so fewest bytes will win!



Edit: Finally, output is unrestricted.







code-golf string array






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited May 20 at 14:54









Community

1




1










asked May 19 at 12:09









rv7rv7

3562 silver badges11 bronze badges




3562 silver badges11 bronze badges








  • 10




    $begingroup$
    Why special case the empty string? May we choose which character to use for the padding?
    $endgroup$
    – Shaggy
    May 19 at 14:49






  • 12




    $begingroup$
    So the task is actually: Given a string, return a falsey value if it is empty, otherwise split it into groups of three, padding with underscores if necessary? Seems like an odd pair-up of two unrelated tasks (checking string length and splitting).
    $endgroup$
    – Adám
    May 19 at 15:27






  • 14




    $begingroup$
    Things to avoid: Exceptional edge cases. In this case, an empty string should returnan empty array or equivalent, not a falsey value
    $endgroup$
    – Jo King
    May 19 at 22:05








  • 6




    $begingroup$
    Lots of statically-typed languages cannot return more than one type from a function
    $endgroup$
    – Embodiment of Ignorance
    May 19 at 23:30






  • 4




    $begingroup$
    @manassehkatz Yes, but only in those languages. In some languages it makes solutions far more complicated, or even impossible (e.g statically typed languages).
    $endgroup$
    – Jo King
    May 20 at 22:01














  • 10




    $begingroup$
    Why special case the empty string? May we choose which character to use for the padding?
    $endgroup$
    – Shaggy
    May 19 at 14:49






  • 12




    $begingroup$
    So the task is actually: Given a string, return a falsey value if it is empty, otherwise split it into groups of three, padding with underscores if necessary? Seems like an odd pair-up of two unrelated tasks (checking string length and splitting).
    $endgroup$
    – Adám
    May 19 at 15:27






  • 14




    $begingroup$
    Things to avoid: Exceptional edge cases. In this case, an empty string should returnan empty array or equivalent, not a falsey value
    $endgroup$
    – Jo King
    May 19 at 22:05








  • 6




    $begingroup$
    Lots of statically-typed languages cannot return more than one type from a function
    $endgroup$
    – Embodiment of Ignorance
    May 19 at 23:30






  • 4




    $begingroup$
    @manassehkatz Yes, but only in those languages. In some languages it makes solutions far more complicated, or even impossible (e.g statically typed languages).
    $endgroup$
    – Jo King
    May 20 at 22:01








10




10




$begingroup$
Why special case the empty string? May we choose which character to use for the padding?
$endgroup$
– Shaggy
May 19 at 14:49




$begingroup$
Why special case the empty string? May we choose which character to use for the padding?
$endgroup$
– Shaggy
May 19 at 14:49




12




12




$begingroup$
So the task is actually: Given a string, return a falsey value if it is empty, otherwise split it into groups of three, padding with underscores if necessary? Seems like an odd pair-up of two unrelated tasks (checking string length and splitting).
$endgroup$
– Adám
May 19 at 15:27




$begingroup$
So the task is actually: Given a string, return a falsey value if it is empty, otherwise split it into groups of three, padding with underscores if necessary? Seems like an odd pair-up of two unrelated tasks (checking string length and splitting).
$endgroup$
– Adám
May 19 at 15:27




14




14




$begingroup$
Things to avoid: Exceptional edge cases. In this case, an empty string should returnan empty array or equivalent, not a falsey value
$endgroup$
– Jo King
May 19 at 22:05






$begingroup$
Things to avoid: Exceptional edge cases. In this case, an empty string should returnan empty array or equivalent, not a falsey value
$endgroup$
– Jo King
May 19 at 22:05






6




6




$begingroup$
Lots of statically-typed languages cannot return more than one type from a function
$endgroup$
– Embodiment of Ignorance
May 19 at 23:30




$begingroup$
Lots of statically-typed languages cannot return more than one type from a function
$endgroup$
– Embodiment of Ignorance
May 19 at 23:30




4




4




$begingroup$
@manassehkatz Yes, but only in those languages. In some languages it makes solutions far more complicated, or even impossible (e.g statically typed languages).
$endgroup$
– Jo King
May 20 at 22:01




$begingroup$
@manassehkatz Yes, but only in those languages. In some languages it makes solutions far more complicated, or even impossible (e.g statically typed languages).
$endgroup$
– Jo King
May 20 at 22:01










37 Answers
37






active

oldest

votes













1 2
next












9












$begingroup$


05AB1E, 9 8 bytes



…___«3ô¨


Try it online!
or as a Test Suite



Explanation



…___«      # append "___" to input
3ô # split into groups of 3
¨ # discard the last group





share|improve this answer











$endgroup$





















    8












    $begingroup$

    Python 3, 58 47 34 bytes



    I'm sure someone else can do better Someone else did better. Thanks Jo King for -11 -24 bytes!



    Output is unrestricted, welcome to tuple hell. Returns empty list (falsy) on empty input



    lambda x:[*zip(*[iter(x+"__")]*3)]


    TIO






    share|improve this answer











    $endgroup$





















      6












      $begingroup$

      JavaScript, 25 bytes



      s=>`${s}__`.match(/.../g)


      Try it






      share|improve this answer









      $endgroup$





















        5












        $begingroup$


        Perl 5, 16 15 bytes





        "@___"=~/.../g


        Try it online!






        share|improve this answer











        $endgroup$









        • 1




          $begingroup$
          15 with "@___"=~/.../g. There were other 16s: (pop.__)=~/.../g or map/.../g,pop.__.
          $endgroup$
          – Grimy
          May 20 at 11:50






        • 1




          $begingroup$
          Thx to @Grimy for the tip on . It shaved off 1 byte and I learned something new.
          $endgroup$
          – Kjetil S.
          May 20 at 13:30





















        4












        $begingroup$

        APL+WIN 36 24 22 bytes



        12 bytes saved as a result of output now being de-restricted and using the code in @Adám's first comment modified to work in APL+WIN and a further 2 with his second comment. Thanks.



        (⌈(↑⍴s)÷3)3⍴(s←⎕),'__'


        Prompts for input of the string and outputs the result as a nx3 array



        Try it online! Courtesy of Dyalog Classic






        share|improve this answer











        $endgroup$













        • $begingroup$
          @Adám. Throws a domain error in APL+WIN at the right most ⍴
          $endgroup$
          – Graham
          May 19 at 13:45










        • $begingroup$
          Fails on '', no? I think OP (for some strange reason) requires the result to be 0 (with any rank).
          $endgroup$
          – Adám
          May 19 at 15:47








        • 1




          $begingroup$
          @Adám It produces a 0 x 3 array. The OP now appears to want "falsey" for a null input. With the spec keeping on changing I am going to bow out at this point and leave my answer as its stands! Thanks for your improvements.
          $endgroup$
          – Graham
          May 19 at 16:12



















        4












        $begingroup$

        JavaScript, 51 50 48 27 25



        b=>(b+"__").match(/.../g)


        Try it online!






        share|improve this answer











        $endgroup$













        • $begingroup$
          Welcome to PPCG! :) But ... codegolf.stackexchange.com/a/185808/58974
          $endgroup$
          – Shaggy
          May 24 at 16:51










        • $begingroup$
          @Shaggy I didn't even see that ¯_(ツ)_/¯
          $endgroup$
          – VFDan
          May 24 at 17:21












        • $begingroup$
          No worries, it happens.
          $endgroup$
          – Shaggy
          May 24 at 17:24



















        3












        $begingroup$


        Perl 6, 19 bytes





        {$_~"__"~~m:g/.../}


        Try it online!



        Pads the string by two underscores then splits the string into chunks of three characters. Returns as an array of Match objects.






        share|improve this answer









        $endgroup$





















          3












          $begingroup$


          Japt, 8 bytes



          +1 byte to special case the empty string. Can save 2 if we can choose our padding character.



          ©ò3 ú'_3


          Try it



          ©ò3 ú'_3     :Implicit input of string
          © :Logical AND with
          ò3 :Split into chunks of 3
          ú'_3 :Right pad each with "_" to length 3





          share|improve this answer











          $endgroup$





















            2












            $begingroup$


            Stax, 7 bytes



            é☻εgP▀╪


            Run and debug it



            For an empty string input, the result is an empty array, which is a falsey value in stax.






            share|improve this answer









            $endgroup$





















              2












              $begingroup$


              CJam, 11 bytes



              q'_3*+3/);p


              Try it online!



              For empty input this gives an empty string, which is falsy.



              How it works



              q     e# Read input as a string
              '_ e# Push char '_'
              3* e# String formed by that char repeated 3 times
              + e# Concatenate to input string
              3/ e# Split in groups of 3, the last of which may be shorter. Gives array of strings
              ); e# Detach last string from the array and delete it
              p e# Print string representation of the array





              share|improve this answer











              $endgroup$





















                2












                $begingroup$


                Retina 0.8.2, 10 bytes



                $
                __
                !`...


                Try it online! Link includes test cases. Explanation:



                $
                __


                Append two _s, in case the last group needs to be padded.



                !`...


                Match as many groups of three as possible, outputting the matches themselves rather than the count. (In Retina 1 this would be L instead of !.)






                share|improve this answer









                $endgroup$





















                  2












                  $begingroup$


                  C (gcc), 67 bytes





                  i;f(char*_){for(;*_;puts(""))for(i=3;i--;)putchar(*_?*_++:95);_=0;}


                  Try it online!



                  Always returns a falsey value (0).






                  share|improve this answer









                  $endgroup$









                  • 1




                    $begingroup$
                    Do you even need to return anything?
                    $endgroup$
                    – ceilingcat
                    May 20 at 14:11










                  • $begingroup$
                    63 bytes
                    $endgroup$
                    – Johan du Toit
                    May 21 at 10:28



















                  2












                  $begingroup$


                  Wolfram Language (Mathematica), 28 21 bytes



                  -7: No longer requires falsy (False) value on empty input



                  Partition[#,3,1,1,_]&


                  Try it online!



                  Takes a list of characters as input. Returns a list of 3-tuples of characters padded with Blanks (_).






                  34 27 bytes



                  StringPartition[#<>"__",3]&


                  Try it online!



                  String input, list of strings output






                  share|improve this answer











                  $endgroup$





















                    1












                    $begingroup$


                    Jelly, 9 bytes



                    s3o€“___”


                    A monadic Link accepting a list of characters which yields a list of lists of characters (an empty input yields empty output).



                    Try it online!



                    How?



                    s3o€“___” - Link: list of characters
                    s3 - split into chunks of three
                    € - for each chunk:
                    o - OR (vectorises):
                    “___” - list of characters = ['_', '_', '_']


                    Notes:

                    The is only necessary to handle the edge case of an empty input.

                    A full program can drop a trailing , but here we can't do that as the printing behaviour of a full program smashes everything together.





                    Equivalent 9:



                    o3ÐƤ“___”


                    Try it





                    Alternative 9:



                    ;“___”s3Ṗ


                    Try it






                    share|improve this answer











                    $endgroup$





















                      1












                      $begingroup$


                      J, 16 bytes



                      [:}:_3]'___',~]


                      Try it online!




                      K (oK), 19 17 bytes



                      -2 bytes thanks to ngn!



                      {-1_0N 3#x,"___"}


                      Try it online!






                      share|improve this answer











                      $endgroup$









                      • 1




                        $begingroup$
                        k: (0N;3) -> 0N 3
                        $endgroup$
                        – ngn
                        May 20 at 7:21












                      • $begingroup$
                        @ngn Thank you!
                        $endgroup$
                        – Galen Ivanov
                        May 20 at 7:28



















                      1












                      $begingroup$

                      Java 10, 116 113 bytes





                      s->{s+="__";int l=s.length()/3,i=l;var r=new String[l];for(;i-->0;)r[i]=s.substring(i*3,i*3+3);return l<1?0>1:r;}


                      Try it online.



                      Or 104 101 bytes if an empty array instead of false is allowed as output..



                      s->{s+="__";int l=s.length()/3;var r=new String[l];for(;l-->0;)r[l]=s.substring(l*3,l*3+3);return r;}


                      Try it online.



                      Explanation:



                      s->{                             // Method with String as both parameter and return-type
                      s+="__"; // Append two "_" to the input-String
                      int l=s.length()/3; // Get the length, integer-divided by 3
                      var r=new String[l]; // Create a string-array with that many parts
                      for(;l-->0;) // Loop `l` in the range (l, 0]:
                      r[l]= // Set the `l`'th value of the array to:
                      s.substring(l*3,l*3+3); // Get the substring of size 3 from index `l*3` from `s`
                      return r;} // Return the array





                      share|improve this answer









                      $endgroup$













                      • $begingroup$
                        An empty array is now allowed
                        $endgroup$
                        – Benjamin Urquhart
                        May 26 at 3:57



















                      1












                      $begingroup$

                      Ruby, 73 42 bytes



                      a=gets
                      a.length!=0?a.scan(/.{1,3}/).map{|s|(s+'_'*3)[0,3]}:'falsey value'


                      Edit: As falsey value looks like it's not required:



                      gets.scan(/.{1,3}/).map{|s|(s+'_'*3)[0,3]}





                      share|improve this answer











                      $endgroup$









                      • 1




                        $begingroup$
                        The maximum padding is of 2 characters, so '_'*2 would be enough, for which a literal '__' is shorter. But if you add the padding in advance then simply not match the pieces shorter than 3 characters, is shorter: puts"#{gets}__".scan /.../. (Note that without the explicit printing that is considered irb not ruby.)
                        $endgroup$
                        – manatwork
                        May 20 at 15:06





















                      1












                      $begingroup$


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



                      Just append two underscores '_' at the end of the input to make sure they get printed if the length of the input isn't a factor of 3.



                      s=>Enumerable.Range(0,(s.Length+2)/3).Select(i=>(s+"__").Substring(i*3,3))


                      Try it online!






                      share|improve this answer









                      $endgroup$













                      • $begingroup$
                        67
                        $endgroup$
                        – dana
                        May 22 at 5:20










                      • $begingroup$
                        57
                        $endgroup$
                        – someone
                        May 25 at 1:22





















                      1












                      $begingroup$


                      Kotlin, 34 bytes



                      {"${it}__".chunked(3).dropLast(1)}


                      Try it online!






                      share|improve this answer









                      $endgroup$













                      • $begingroup$
                        this does not work, try {"${it}___".chunked(3).dropLast(1)}
                        $endgroup$
                        – pme
                        May 21 at 6:45



















                      1












                      $begingroup$


                      C (gcc), 55 bytes





                      i;f(char*s){for(;i%4|*s;)putchar(++i%4?*s?*s++:95:10);}


                      Try it online!






                      share|improve this answer











                      $endgroup$













                      • $begingroup$
                        Using 9(t) instead of 10(n) should be fine, but that's not main point
                        $endgroup$
                        – l4m2
                        May 20 at 15:23



















                      1












                      $begingroup$


                      C (clang), 128 126 94 67 bytes



                      67 bytes thanks to @ceilingcat





                      f(char*k){for(;*k;k++)printf("%c%c%cn",*k,*++k?*k:95,*++k?*k:95);}


                      Try it online!






                      share|improve this answer











                      $endgroup$





















                        1












                        $begingroup$


                        Bash, 90 bytes



                        This uses Bash features rather than a combination of more traditional Bourne shell plus *nix commands (which one version I created ended up at 205 bytes). I cheated by using the dodge of adding two _ characters to the string.



                        c=;read a;a=${a}__;while (($(echo ${#a})>2));do b=${a:0:3};c=$c $b;a=${a#$b};done;echo $c


                        Try it online!






                        share|improve this answer









                        $endgroup$





















                          1












                          $begingroup$


                          PowerShell, 58 35 bytes



                          $args-split'(...)'-ne''|% *ht 3 '_'


                          -23 bytes thanks to mazzy.



                          Try it online!






                          share|improve this answer











                          $endgroup$













                          • $begingroup$
                            Nice. 1) You can count a code that can be extracted into a ps1-file and executed. 2) See shortcuts. 3) Try to golf more
                            $endgroup$
                            – mazzy
                            May 25 at 5:18



















                          1












                          $begingroup$


                          GNU sed, 27 bytes



                          s:$:__:
                          s:...:& :g
                          s: _*$::


                          Try it online!



                          It gets a bit tricky regarding the empty string input, since sed has no meaning of a falsy value. So to deal with this, I provide you with two possible interpretations of the rules to validate my submission:





                          A. You essentially provide nothing as input, not even a trailing newline (as it is the case with all the examples, including that 6 Mb file).



                          Usage:



                          echo -n ""|sed -f script


                          Output: nothing is printed, because sed doesn't even run the script without input.





                          B. One could consider as falsy value for sed to be an unique string, i.e., returned only when the input is an empty string.



                          Usage:



                          echo ""|sed -f script


                          Output:



                          __




                          I prefer the first interpretation so much more, as I believe it to be the closest to the intended rule, but the last one helps if you run the script using that TIO link.






                          share|improve this answer









                          $endgroup$





















                            0












                            $begingroup$


                            JavaScript (Babel Node), 45 bytes





                            _=>_.match(/.{1,3}/g).map(a=>a.padEnd(3,`_`))


                            Try it online!






                            share|improve this answer









                            $endgroup$













                            • $begingroup$
                              44
                              $endgroup$
                              – Shaggy
                              May 19 at 15:13










                            • $begingroup$
                              Doesn't work for me
                              $endgroup$
                              – VFDan
                              May 22 at 21:55



















                            0












                            $begingroup$


                            Jelly, 10 bytes



                            s3;€⁾__ḣ€3


                            Try it online!



                            It feels like an 8 or 9 should be possible, but haven’t found one yet.






                            share|improve this answer









                            $endgroup$





















                              0












                              $begingroup$


                              Attache, 34 23 bytes



                              PadRight&"_"&3=>@Chop&3


                              Try it online!



                              Explanation (outdated)



                              {On[#_-1,PadRight&"_"&3,_]}@Chop&3
                              @Chop&3 chop the input string into groups of 3s
                              {On[#_-1 ,_]} on the last group
                              ,PadRight pad it
                              &3 to length three
                              &"_" with underscores





                              share|improve this answer











                              $endgroup$













                              • $begingroup$
                                Would you save anything by padding all the elements instead of just the last one?
                                $endgroup$
                                – Shaggy
                                May 19 at 20:18










                              • $begingroup$
                                @Shaggy Good point! I’ll look into it
                                $endgroup$
                                – Conor O'Brien
                                May 19 at 20:19



















                              0












                              $begingroup$


                              Charcoal, 10 bytes



                              E⪪S³…⁺ι__³


                              Try it online! Link is to verbose version of code. Explanation:



                                S         Input string
                              ⪪ ³ Split into groups of up to 3 characters
                              E Map over each group
                              ι Current group
                              ⁺ Concatenated with
                              __ Literal `__`
                              … ³ Moulded to length 3
                              Each group implicitly printed on its own line





                              share|improve this answer









                              $endgroup$





















                                0












                                $begingroup$


                                Scala, 31 bytes





                                (s+"___").grouped(3).toSeq.init


                                Try it online!



                                Explanation



                                (s+"___")       // add "___"
                                .grouped(3) // make groups of 3
                                .toSeq // change to Seq
                                .init // take all but last





                                share|improve this answer











                                $endgroup$





















                                  0












                                  $begingroup$


                                  Befunge-93, 30 29 bytes



                                  ~:1+%,~:1+!"`"*+,~:1+!"`"*+,,


                                  Try it online!



                                  Outputs nothing for an empty input, otherwise outputs strings of length 3 separated by NUL characters.



                                  Explanation:




                                  ~ Push character of input to stack
                                  :1+ Duplicate input and add 1
                                  % Modulo top 2 values of stack and push result
                                  If input was -1 (end of stream), calculate -1%0 -> halt
                                  Otherwise calculate input%(input+1) -> input
                                  , Pop and output character
                                  ~ Push character of input to stack
                                  :1+! Duplicate input, add 1 and perform logical NOT
                                  "`"* Multiply by 96 (ASCII code for '`')
                                  This returns 96 or 0 depending on the result of the NOT
                                  + Add the top 2 values from the stack and push the result
                                  If the input was -1 (end of stream), pushes -1+96=95, or the ASCII code for '_'
                                  Otherwise pushes input+0
                                  , Pop and output character
                                  ~:1+!"`"*+, Same block again to handle the third character
                                  , Output a NUL character (stack is empty, so popping from stack just returns 0)

                                  The instruction pointer wraps around at the end, looping the entire line.





                                  share|improve this answer











                                  $endgroup$

















                                    1 2
                                    next






                                    Your Answer






                                    StackExchange.ifUsing("editor", function () {
                                    StackExchange.using("externalEditor", function () {
                                    StackExchange.using("snippets", function () {
                                    StackExchange.snippets.init();
                                    });
                                    });
                                    }, "code-snippets");

                                    StackExchange.ready(function() {
                                    var channelOptions = {
                                    tags: "".split(" "),
                                    id: "200"
                                    };
                                    initTagRenderer("".split(" "), "".split(" "), channelOptions);

                                    StackExchange.using("externalEditor", function() {
                                    // Have to fire editor after snippets, if snippets enabled
                                    if (StackExchange.settings.snippets.snippetsEnabled) {
                                    StackExchange.using("snippets", function() {
                                    createEditor();
                                    });
                                    }
                                    else {
                                    createEditor();
                                    }
                                    });

                                    function createEditor() {
                                    StackExchange.prepareEditor({
                                    heartbeatType: 'answer',
                                    autoActivateHeartbeat: false,
                                    convertImagesToLinks: false,
                                    noModals: true,
                                    showLowRepImageUploadWarning: true,
                                    reputationToPostImages: null,
                                    bindNavPrevention: true,
                                    postfix: "",
                                    imageUploader: {
                                    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
                                    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
                                    allowUrls: true
                                    },
                                    onDemand: true,
                                    discardSelector: ".discard-answer"
                                    ,immediatelyShowMarkdownHelp:true
                                    });


                                    }
                                    });














                                    draft saved

                                    draft discarded


















                                    StackExchange.ready(
                                    function () {
                                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodegolf.stackexchange.com%2fquestions%2f185783%2fsplit-into-three%23new-answer', 'question_page');
                                    }
                                    );

                                    Post as a guest















                                    Required, but never shown

























                                    37 Answers
                                    37






                                    active

                                    oldest

                                    votes








                                    37 Answers
                                    37






                                    active

                                    oldest

                                    votes









                                    active

                                    oldest

                                    votes






                                    active

                                    oldest

                                    votes








                                    1 2
                                    next










                                    9












                                    $begingroup$


                                    05AB1E, 9 8 bytes



                                    …___«3ô¨


                                    Try it online!
                                    or as a Test Suite



                                    Explanation



                                    …___«      # append "___" to input
                                    3ô # split into groups of 3
                                    ¨ # discard the last group





                                    share|improve this answer











                                    $endgroup$


















                                      9












                                      $begingroup$


                                      05AB1E, 9 8 bytes



                                      …___«3ô¨


                                      Try it online!
                                      or as a Test Suite



                                      Explanation



                                      …___«      # append "___" to input
                                      3ô # split into groups of 3
                                      ¨ # discard the last group





                                      share|improve this answer











                                      $endgroup$
















                                        9












                                        9








                                        9





                                        $begingroup$


                                        05AB1E, 9 8 bytes



                                        …___«3ô¨


                                        Try it online!
                                        or as a Test Suite



                                        Explanation



                                        …___«      # append "___" to input
                                        3ô # split into groups of 3
                                        ¨ # discard the last group





                                        share|improve this answer











                                        $endgroup$




                                        05AB1E, 9 8 bytes



                                        …___«3ô¨


                                        Try it online!
                                        or as a Test Suite



                                        Explanation



                                        …___«      # append "___" to input
                                        3ô # split into groups of 3
                                        ¨ # discard the last group






                                        share|improve this answer














                                        share|improve this answer



                                        share|improve this answer








                                        edited May 19 at 16:38

























                                        answered May 19 at 13:01









                                        EmignaEmigna

                                        50.3k5 gold badges37 silver badges153 bronze badges




                                        50.3k5 gold badges37 silver badges153 bronze badges

























                                            8












                                            $begingroup$

                                            Python 3, 58 47 34 bytes



                                            I'm sure someone else can do better Someone else did better. Thanks Jo King for -11 -24 bytes!



                                            Output is unrestricted, welcome to tuple hell. Returns empty list (falsy) on empty input



                                            lambda x:[*zip(*[iter(x+"__")]*3)]


                                            TIO






                                            share|improve this answer











                                            $endgroup$


















                                              8












                                              $begingroup$

                                              Python 3, 58 47 34 bytes



                                              I'm sure someone else can do better Someone else did better. Thanks Jo King for -11 -24 bytes!



                                              Output is unrestricted, welcome to tuple hell. Returns empty list (falsy) on empty input



                                              lambda x:[*zip(*[iter(x+"__")]*3)]


                                              TIO






                                              share|improve this answer











                                              $endgroup$
















                                                8












                                                8








                                                8





                                                $begingroup$

                                                Python 3, 58 47 34 bytes



                                                I'm sure someone else can do better Someone else did better. Thanks Jo King for -11 -24 bytes!



                                                Output is unrestricted, welcome to tuple hell. Returns empty list (falsy) on empty input



                                                lambda x:[*zip(*[iter(x+"__")]*3)]


                                                TIO






                                                share|improve this answer











                                                $endgroup$



                                                Python 3, 58 47 34 bytes



                                                I'm sure someone else can do better Someone else did better. Thanks Jo King for -11 -24 bytes!



                                                Output is unrestricted, welcome to tuple hell. Returns empty list (falsy) on empty input



                                                lambda x:[*zip(*[iter(x+"__")]*3)]


                                                TIO







                                                share|improve this answer














                                                share|improve this answer



                                                share|improve this answer








                                                edited May 19 at 15:51

























                                                answered May 19 at 12:24









                                                Benjamin UrquhartBenjamin Urquhart

                                                1,1521 silver badge22 bronze badges




                                                1,1521 silver badge22 bronze badges























                                                    6












                                                    $begingroup$

                                                    JavaScript, 25 bytes



                                                    s=>`${s}__`.match(/.../g)


                                                    Try it






                                                    share|improve this answer









                                                    $endgroup$


















                                                      6












                                                      $begingroup$

                                                      JavaScript, 25 bytes



                                                      s=>`${s}__`.match(/.../g)


                                                      Try it






                                                      share|improve this answer









                                                      $endgroup$
















                                                        6












                                                        6








                                                        6





                                                        $begingroup$

                                                        JavaScript, 25 bytes



                                                        s=>`${s}__`.match(/.../g)


                                                        Try it






                                                        share|improve this answer









                                                        $endgroup$



                                                        JavaScript, 25 bytes



                                                        s=>`${s}__`.match(/.../g)


                                                        Try it







                                                        share|improve this answer












                                                        share|improve this answer



                                                        share|improve this answer










                                                        answered May 19 at 20:53









                                                        ShaggyShaggy

                                                        20.4k3 gold badges20 silver badges69 bronze badges




                                                        20.4k3 gold badges20 silver badges69 bronze badges























                                                            5












                                                            $begingroup$


                                                            Perl 5, 16 15 bytes





                                                            "@___"=~/.../g


                                                            Try it online!






                                                            share|improve this answer











                                                            $endgroup$









                                                            • 1




                                                              $begingroup$
                                                              15 with "@___"=~/.../g. There were other 16s: (pop.__)=~/.../g or map/.../g,pop.__.
                                                              $endgroup$
                                                              – Grimy
                                                              May 20 at 11:50






                                                            • 1




                                                              $begingroup$
                                                              Thx to @Grimy for the tip on . It shaved off 1 byte and I learned something new.
                                                              $endgroup$
                                                              – Kjetil S.
                                                              May 20 at 13:30


















                                                            5












                                                            $begingroup$


                                                            Perl 5, 16 15 bytes





                                                            "@___"=~/.../g


                                                            Try it online!






                                                            share|improve this answer











                                                            $endgroup$









                                                            • 1




                                                              $begingroup$
                                                              15 with "@___"=~/.../g. There were other 16s: (pop.__)=~/.../g or map/.../g,pop.__.
                                                              $endgroup$
                                                              – Grimy
                                                              May 20 at 11:50






                                                            • 1




                                                              $begingroup$
                                                              Thx to @Grimy for the tip on . It shaved off 1 byte and I learned something new.
                                                              $endgroup$
                                                              – Kjetil S.
                                                              May 20 at 13:30
















                                                            5












                                                            5








                                                            5





                                                            $begingroup$


                                                            Perl 5, 16 15 bytes





                                                            "@___"=~/.../g


                                                            Try it online!






                                                            share|improve this answer











                                                            $endgroup$




                                                            Perl 5, 16 15 bytes





                                                            "@___"=~/.../g


                                                            Try it online!







                                                            share|improve this answer














                                                            share|improve this answer



                                                            share|improve this answer








                                                            edited May 20 at 13:29

























                                                            answered May 19 at 15:04









                                                            Kjetil S.Kjetil S.

                                                            6692 silver badges5 bronze badges




                                                            6692 silver badges5 bronze badges








                                                            • 1




                                                              $begingroup$
                                                              15 with "@___"=~/.../g. There were other 16s: (pop.__)=~/.../g or map/.../g,pop.__.
                                                              $endgroup$
                                                              – Grimy
                                                              May 20 at 11:50






                                                            • 1




                                                              $begingroup$
                                                              Thx to @Grimy for the tip on . It shaved off 1 byte and I learned something new.
                                                              $endgroup$
                                                              – Kjetil S.
                                                              May 20 at 13:30
















                                                            • 1




                                                              $begingroup$
                                                              15 with "@___"=~/.../g. There were other 16s: (pop.__)=~/.../g or map/.../g,pop.__.
                                                              $endgroup$
                                                              – Grimy
                                                              May 20 at 11:50






                                                            • 1




                                                              $begingroup$
                                                              Thx to @Grimy for the tip on . It shaved off 1 byte and I learned something new.
                                                              $endgroup$
                                                              – Kjetil S.
                                                              May 20 at 13:30










                                                            1




                                                            1




                                                            $begingroup$
                                                            15 with "@___"=~/.../g. There were other 16s: (pop.__)=~/.../g or map/.../g,pop.__.
                                                            $endgroup$
                                                            – Grimy
                                                            May 20 at 11:50




                                                            $begingroup$
                                                            15 with "@___"=~/.../g. There were other 16s: (pop.__)=~/.../g or map/.../g,pop.__.
                                                            $endgroup$
                                                            – Grimy
                                                            May 20 at 11:50




                                                            1




                                                            1




                                                            $begingroup$
                                                            Thx to @Grimy for the tip on . It shaved off 1 byte and I learned something new.
                                                            $endgroup$
                                                            – Kjetil S.
                                                            May 20 at 13:30






                                                            $begingroup$
                                                            Thx to @Grimy for the tip on . It shaved off 1 byte and I learned something new.
                                                            $endgroup$
                                                            – Kjetil S.
                                                            May 20 at 13:30













                                                            4












                                                            $begingroup$

                                                            APL+WIN 36 24 22 bytes



                                                            12 bytes saved as a result of output now being de-restricted and using the code in @Adám's first comment modified to work in APL+WIN and a further 2 with his second comment. Thanks.



                                                            (⌈(↑⍴s)÷3)3⍴(s←⎕),'__'


                                                            Prompts for input of the string and outputs the result as a nx3 array



                                                            Try it online! Courtesy of Dyalog Classic






                                                            share|improve this answer











                                                            $endgroup$













                                                            • $begingroup$
                                                              @Adám. Throws a domain error in APL+WIN at the right most ⍴
                                                              $endgroup$
                                                              – Graham
                                                              May 19 at 13:45










                                                            • $begingroup$
                                                              Fails on '', no? I think OP (for some strange reason) requires the result to be 0 (with any rank).
                                                              $endgroup$
                                                              – Adám
                                                              May 19 at 15:47








                                                            • 1




                                                              $begingroup$
                                                              @Adám It produces a 0 x 3 array. The OP now appears to want "falsey" for a null input. With the spec keeping on changing I am going to bow out at this point and leave my answer as its stands! Thanks for your improvements.
                                                              $endgroup$
                                                              – Graham
                                                              May 19 at 16:12
















                                                            4












                                                            $begingroup$

                                                            APL+WIN 36 24 22 bytes



                                                            12 bytes saved as a result of output now being de-restricted and using the code in @Adám's first comment modified to work in APL+WIN and a further 2 with his second comment. Thanks.



                                                            (⌈(↑⍴s)÷3)3⍴(s←⎕),'__'


                                                            Prompts for input of the string and outputs the result as a nx3 array



                                                            Try it online! Courtesy of Dyalog Classic






                                                            share|improve this answer











                                                            $endgroup$













                                                            • $begingroup$
                                                              @Adám. Throws a domain error in APL+WIN at the right most ⍴
                                                              $endgroup$
                                                              – Graham
                                                              May 19 at 13:45










                                                            • $begingroup$
                                                              Fails on '', no? I think OP (for some strange reason) requires the result to be 0 (with any rank).
                                                              $endgroup$
                                                              – Adám
                                                              May 19 at 15:47








                                                            • 1




                                                              $begingroup$
                                                              @Adám It produces a 0 x 3 array. The OP now appears to want "falsey" for a null input. With the spec keeping on changing I am going to bow out at this point and leave my answer as its stands! Thanks for your improvements.
                                                              $endgroup$
                                                              – Graham
                                                              May 19 at 16:12














                                                            4












                                                            4








                                                            4





                                                            $begingroup$

                                                            APL+WIN 36 24 22 bytes



                                                            12 bytes saved as a result of output now being de-restricted and using the code in @Adám's first comment modified to work in APL+WIN and a further 2 with his second comment. Thanks.



                                                            (⌈(↑⍴s)÷3)3⍴(s←⎕),'__'


                                                            Prompts for input of the string and outputs the result as a nx3 array



                                                            Try it online! Courtesy of Dyalog Classic






                                                            share|improve this answer











                                                            $endgroup$



                                                            APL+WIN 36 24 22 bytes



                                                            12 bytes saved as a result of output now being de-restricted and using the code in @Adám's first comment modified to work in APL+WIN and a further 2 with his second comment. Thanks.



                                                            (⌈(↑⍴s)÷3)3⍴(s←⎕),'__'


                                                            Prompts for input of the string and outputs the result as a nx3 array



                                                            Try it online! Courtesy of Dyalog Classic







                                                            share|improve this answer














                                                            share|improve this answer



                                                            share|improve this answer








                                                            edited May 19 at 15:04

























                                                            answered May 19 at 12:46









                                                            GrahamGraham

                                                            2,8167 silver badges8 bronze badges




                                                            2,8167 silver badges8 bronze badges












                                                            • $begingroup$
                                                              @Adám. Throws a domain error in APL+WIN at the right most ⍴
                                                              $endgroup$
                                                              – Graham
                                                              May 19 at 13:45










                                                            • $begingroup$
                                                              Fails on '', no? I think OP (for some strange reason) requires the result to be 0 (with any rank).
                                                              $endgroup$
                                                              – Adám
                                                              May 19 at 15:47








                                                            • 1




                                                              $begingroup$
                                                              @Adám It produces a 0 x 3 array. The OP now appears to want "falsey" for a null input. With the spec keeping on changing I am going to bow out at this point and leave my answer as its stands! Thanks for your improvements.
                                                              $endgroup$
                                                              – Graham
                                                              May 19 at 16:12


















                                                            • $begingroup$
                                                              @Adám. Throws a domain error in APL+WIN at the right most ⍴
                                                              $endgroup$
                                                              – Graham
                                                              May 19 at 13:45










                                                            • $begingroup$
                                                              Fails on '', no? I think OP (for some strange reason) requires the result to be 0 (with any rank).
                                                              $endgroup$
                                                              – Adám
                                                              May 19 at 15:47








                                                            • 1




                                                              $begingroup$
                                                              @Adám It produces a 0 x 3 array. The OP now appears to want "falsey" for a null input. With the spec keeping on changing I am going to bow out at this point and leave my answer as its stands! Thanks for your improvements.
                                                              $endgroup$
                                                              – Graham
                                                              May 19 at 16:12
















                                                            $begingroup$
                                                            @Adám. Throws a domain error in APL+WIN at the right most ⍴
                                                            $endgroup$
                                                            – Graham
                                                            May 19 at 13:45




                                                            $begingroup$
                                                            @Adám. Throws a domain error in APL+WIN at the right most ⍴
                                                            $endgroup$
                                                            – Graham
                                                            May 19 at 13:45












                                                            $begingroup$
                                                            Fails on '', no? I think OP (for some strange reason) requires the result to be 0 (with any rank).
                                                            $endgroup$
                                                            – Adám
                                                            May 19 at 15:47






                                                            $begingroup$
                                                            Fails on '', no? I think OP (for some strange reason) requires the result to be 0 (with any rank).
                                                            $endgroup$
                                                            – Adám
                                                            May 19 at 15:47






                                                            1




                                                            1




                                                            $begingroup$
                                                            @Adám It produces a 0 x 3 array. The OP now appears to want "falsey" for a null input. With the spec keeping on changing I am going to bow out at this point and leave my answer as its stands! Thanks for your improvements.
                                                            $endgroup$
                                                            – Graham
                                                            May 19 at 16:12




                                                            $begingroup$
                                                            @Adám It produces a 0 x 3 array. The OP now appears to want "falsey" for a null input. With the spec keeping on changing I am going to bow out at this point and leave my answer as its stands! Thanks for your improvements.
                                                            $endgroup$
                                                            – Graham
                                                            May 19 at 16:12











                                                            4












                                                            $begingroup$

                                                            JavaScript, 51 50 48 27 25



                                                            b=>(b+"__").match(/.../g)


                                                            Try it online!






                                                            share|improve this answer











                                                            $endgroup$













                                                            • $begingroup$
                                                              Welcome to PPCG! :) But ... codegolf.stackexchange.com/a/185808/58974
                                                              $endgroup$
                                                              – Shaggy
                                                              May 24 at 16:51










                                                            • $begingroup$
                                                              @Shaggy I didn't even see that ¯_(ツ)_/¯
                                                              $endgroup$
                                                              – VFDan
                                                              May 24 at 17:21












                                                            • $begingroup$
                                                              No worries, it happens.
                                                              $endgroup$
                                                              – Shaggy
                                                              May 24 at 17:24
















                                                            4












                                                            $begingroup$

                                                            JavaScript, 51 50 48 27 25



                                                            b=>(b+"__").match(/.../g)


                                                            Try it online!






                                                            share|improve this answer











                                                            $endgroup$













                                                            • $begingroup$
                                                              Welcome to PPCG! :) But ... codegolf.stackexchange.com/a/185808/58974
                                                              $endgroup$
                                                              – Shaggy
                                                              May 24 at 16:51










                                                            • $begingroup$
                                                              @Shaggy I didn't even see that ¯_(ツ)_/¯
                                                              $endgroup$
                                                              – VFDan
                                                              May 24 at 17:21












                                                            • $begingroup$
                                                              No worries, it happens.
                                                              $endgroup$
                                                              – Shaggy
                                                              May 24 at 17:24














                                                            4












                                                            4








                                                            4





                                                            $begingroup$

                                                            JavaScript, 51 50 48 27 25



                                                            b=>(b+"__").match(/.../g)


                                                            Try it online!






                                                            share|improve this answer











                                                            $endgroup$



                                                            JavaScript, 51 50 48 27 25



                                                            b=>(b+"__").match(/.../g)


                                                            Try it online!







                                                            share|improve this answer














                                                            share|improve this answer



                                                            share|improve this answer








                                                            edited May 24 at 16:46

























                                                            answered May 22 at 22:14









                                                            VFDanVFDan

                                                            1517 bronze badges




                                                            1517 bronze badges












                                                            • $begingroup$
                                                              Welcome to PPCG! :) But ... codegolf.stackexchange.com/a/185808/58974
                                                              $endgroup$
                                                              – Shaggy
                                                              May 24 at 16:51










                                                            • $begingroup$
                                                              @Shaggy I didn't even see that ¯_(ツ)_/¯
                                                              $endgroup$
                                                              – VFDan
                                                              May 24 at 17:21












                                                            • $begingroup$
                                                              No worries, it happens.
                                                              $endgroup$
                                                              – Shaggy
                                                              May 24 at 17:24


















                                                            • $begingroup$
                                                              Welcome to PPCG! :) But ... codegolf.stackexchange.com/a/185808/58974
                                                              $endgroup$
                                                              – Shaggy
                                                              May 24 at 16:51










                                                            • $begingroup$
                                                              @Shaggy I didn't even see that ¯_(ツ)_/¯
                                                              $endgroup$
                                                              – VFDan
                                                              May 24 at 17:21












                                                            • $begingroup$
                                                              No worries, it happens.
                                                              $endgroup$
                                                              – Shaggy
                                                              May 24 at 17:24
















                                                            $begingroup$
                                                            Welcome to PPCG! :) But ... codegolf.stackexchange.com/a/185808/58974
                                                            $endgroup$
                                                            – Shaggy
                                                            May 24 at 16:51




                                                            $begingroup$
                                                            Welcome to PPCG! :) But ... codegolf.stackexchange.com/a/185808/58974
                                                            $endgroup$
                                                            – Shaggy
                                                            May 24 at 16:51












                                                            $begingroup$
                                                            @Shaggy I didn't even see that ¯_(ツ)_/¯
                                                            $endgroup$
                                                            – VFDan
                                                            May 24 at 17:21






                                                            $begingroup$
                                                            @Shaggy I didn't even see that ¯_(ツ)_/¯
                                                            $endgroup$
                                                            – VFDan
                                                            May 24 at 17:21














                                                            $begingroup$
                                                            No worries, it happens.
                                                            $endgroup$
                                                            – Shaggy
                                                            May 24 at 17:24




                                                            $begingroup$
                                                            No worries, it happens.
                                                            $endgroup$
                                                            – Shaggy
                                                            May 24 at 17:24











                                                            3












                                                            $begingroup$


                                                            Perl 6, 19 bytes





                                                            {$_~"__"~~m:g/.../}


                                                            Try it online!



                                                            Pads the string by two underscores then splits the string into chunks of three characters. Returns as an array of Match objects.






                                                            share|improve this answer









                                                            $endgroup$


















                                                              3












                                                              $begingroup$


                                                              Perl 6, 19 bytes





                                                              {$_~"__"~~m:g/.../}


                                                              Try it online!



                                                              Pads the string by two underscores then splits the string into chunks of three characters. Returns as an array of Match objects.






                                                              share|improve this answer









                                                              $endgroup$
















                                                                3












                                                                3








                                                                3





                                                                $begingroup$


                                                                Perl 6, 19 bytes





                                                                {$_~"__"~~m:g/.../}


                                                                Try it online!



                                                                Pads the string by two underscores then splits the string into chunks of three characters. Returns as an array of Match objects.






                                                                share|improve this answer









                                                                $endgroup$




                                                                Perl 6, 19 bytes





                                                                {$_~"__"~~m:g/.../}


                                                                Try it online!



                                                                Pads the string by two underscores then splits the string into chunks of three characters. Returns as an array of Match objects.







                                                                share|improve this answer












                                                                share|improve this answer



                                                                share|improve this answer










                                                                answered May 19 at 12:29









                                                                Jo KingJo King

                                                                29.6k3 gold badges70 silver badges136 bronze badges




                                                                29.6k3 gold badges70 silver badges136 bronze badges























                                                                    3












                                                                    $begingroup$


                                                                    Japt, 8 bytes



                                                                    +1 byte to special case the empty string. Can save 2 if we can choose our padding character.



                                                                    ©ò3 ú'_3


                                                                    Try it



                                                                    ©ò3 ú'_3     :Implicit input of string
                                                                    © :Logical AND with
                                                                    ò3 :Split into chunks of 3
                                                                    ú'_3 :Right pad each with "_" to length 3





                                                                    share|improve this answer











                                                                    $endgroup$


















                                                                      3












                                                                      $begingroup$


                                                                      Japt, 8 bytes



                                                                      +1 byte to special case the empty string. Can save 2 if we can choose our padding character.



                                                                      ©ò3 ú'_3


                                                                      Try it



                                                                      ©ò3 ú'_3     :Implicit input of string
                                                                      © :Logical AND with
                                                                      ò3 :Split into chunks of 3
                                                                      ú'_3 :Right pad each with "_" to length 3





                                                                      share|improve this answer











                                                                      $endgroup$
















                                                                        3












                                                                        3








                                                                        3





                                                                        $begingroup$


                                                                        Japt, 8 bytes



                                                                        +1 byte to special case the empty string. Can save 2 if we can choose our padding character.



                                                                        ©ò3 ú'_3


                                                                        Try it



                                                                        ©ò3 ú'_3     :Implicit input of string
                                                                        © :Logical AND with
                                                                        ò3 :Split into chunks of 3
                                                                        ú'_3 :Right pad each with "_" to length 3





                                                                        share|improve this answer











                                                                        $endgroup$




                                                                        Japt, 8 bytes



                                                                        +1 byte to special case the empty string. Can save 2 if we can choose our padding character.



                                                                        ©ò3 ú'_3


                                                                        Try it



                                                                        ©ò3 ú'_3     :Implicit input of string
                                                                        © :Logical AND with
                                                                        ò3 :Split into chunks of 3
                                                                        ú'_3 :Right pad each with "_" to length 3






                                                                        share|improve this answer














                                                                        share|improve this answer



                                                                        share|improve this answer








                                                                        edited May 19 at 14:55

























                                                                        answered May 19 at 14:47









                                                                        ShaggyShaggy

                                                                        20.4k3 gold badges20 silver badges69 bronze badges




                                                                        20.4k3 gold badges20 silver badges69 bronze badges























                                                                            2












                                                                            $begingroup$


                                                                            Stax, 7 bytes



                                                                            é☻εgP▀╪


                                                                            Run and debug it



                                                                            For an empty string input, the result is an empty array, which is a falsey value in stax.






                                                                            share|improve this answer









                                                                            $endgroup$


















                                                                              2












                                                                              $begingroup$


                                                                              Stax, 7 bytes



                                                                              é☻εgP▀╪


                                                                              Run and debug it



                                                                              For an empty string input, the result is an empty array, which is a falsey value in stax.






                                                                              share|improve this answer









                                                                              $endgroup$
















                                                                                2












                                                                                2








                                                                                2





                                                                                $begingroup$


                                                                                Stax, 7 bytes



                                                                                é☻εgP▀╪


                                                                                Run and debug it



                                                                                For an empty string input, the result is an empty array, which is a falsey value in stax.






                                                                                share|improve this answer









                                                                                $endgroup$




                                                                                Stax, 7 bytes



                                                                                é☻εgP▀╪


                                                                                Run and debug it



                                                                                For an empty string input, the result is an empty array, which is a falsey value in stax.







                                                                                share|improve this answer












                                                                                share|improve this answer



                                                                                share|improve this answer










                                                                                answered May 19 at 15:02









                                                                                recursiverecursive

                                                                                7,21814 silver badges30 bronze badges




                                                                                7,21814 silver badges30 bronze badges























                                                                                    2












                                                                                    $begingroup$


                                                                                    CJam, 11 bytes



                                                                                    q'_3*+3/);p


                                                                                    Try it online!



                                                                                    For empty input this gives an empty string, which is falsy.



                                                                                    How it works



                                                                                    q     e# Read input as a string
                                                                                    '_ e# Push char '_'
                                                                                    3* e# String formed by that char repeated 3 times
                                                                                    + e# Concatenate to input string
                                                                                    3/ e# Split in groups of 3, the last of which may be shorter. Gives array of strings
                                                                                    ); e# Detach last string from the array and delete it
                                                                                    p e# Print string representation of the array





                                                                                    share|improve this answer











                                                                                    $endgroup$


















                                                                                      2












                                                                                      $begingroup$


                                                                                      CJam, 11 bytes



                                                                                      q'_3*+3/);p


                                                                                      Try it online!



                                                                                      For empty input this gives an empty string, which is falsy.



                                                                                      How it works



                                                                                      q     e# Read input as a string
                                                                                      '_ e# Push char '_'
                                                                                      3* e# String formed by that char repeated 3 times
                                                                                      + e# Concatenate to input string
                                                                                      3/ e# Split in groups of 3, the last of which may be shorter. Gives array of strings
                                                                                      ); e# Detach last string from the array and delete it
                                                                                      p e# Print string representation of the array





                                                                                      share|improve this answer











                                                                                      $endgroup$
















                                                                                        2












                                                                                        2








                                                                                        2





                                                                                        $begingroup$


                                                                                        CJam, 11 bytes



                                                                                        q'_3*+3/);p


                                                                                        Try it online!



                                                                                        For empty input this gives an empty string, which is falsy.



                                                                                        How it works



                                                                                        q     e# Read input as a string
                                                                                        '_ e# Push char '_'
                                                                                        3* e# String formed by that char repeated 3 times
                                                                                        + e# Concatenate to input string
                                                                                        3/ e# Split in groups of 3, the last of which may be shorter. Gives array of strings
                                                                                        ); e# Detach last string from the array and delete it
                                                                                        p e# Print string representation of the array





                                                                                        share|improve this answer











                                                                                        $endgroup$




                                                                                        CJam, 11 bytes



                                                                                        q'_3*+3/);p


                                                                                        Try it online!



                                                                                        For empty input this gives an empty string, which is falsy.



                                                                                        How it works



                                                                                        q     e# Read input as a string
                                                                                        '_ e# Push char '_'
                                                                                        3* e# String formed by that char repeated 3 times
                                                                                        + e# Concatenate to input string
                                                                                        3/ e# Split in groups of 3, the last of which may be shorter. Gives array of strings
                                                                                        ); e# Detach last string from the array and delete it
                                                                                        p e# Print string representation of the array






                                                                                        share|improve this answer














                                                                                        share|improve this answer



                                                                                        share|improve this answer








                                                                                        edited May 19 at 15:45

























                                                                                        answered May 19 at 15:19









                                                                                        Luis MendoLuis Mendo

                                                                                        77.2k8 gold badges95 silver badges302 bronze badges




                                                                                        77.2k8 gold badges95 silver badges302 bronze badges























                                                                                            2












                                                                                            $begingroup$


                                                                                            Retina 0.8.2, 10 bytes



                                                                                            $
                                                                                            __
                                                                                            !`...


                                                                                            Try it online! Link includes test cases. Explanation:



                                                                                            $
                                                                                            __


                                                                                            Append two _s, in case the last group needs to be padded.



                                                                                            !`...


                                                                                            Match as many groups of three as possible, outputting the matches themselves rather than the count. (In Retina 1 this would be L instead of !.)






                                                                                            share|improve this answer









                                                                                            $endgroup$


















                                                                                              2












                                                                                              $begingroup$


                                                                                              Retina 0.8.2, 10 bytes



                                                                                              $
                                                                                              __
                                                                                              !`...


                                                                                              Try it online! Link includes test cases. Explanation:



                                                                                              $
                                                                                              __


                                                                                              Append two _s, in case the last group needs to be padded.



                                                                                              !`...


                                                                                              Match as many groups of three as possible, outputting the matches themselves rather than the count. (In Retina 1 this would be L instead of !.)






                                                                                              share|improve this answer









                                                                                              $endgroup$
















                                                                                                2












                                                                                                2








                                                                                                2





                                                                                                $begingroup$


                                                                                                Retina 0.8.2, 10 bytes



                                                                                                $
                                                                                                __
                                                                                                !`...


                                                                                                Try it online! Link includes test cases. Explanation:



                                                                                                $
                                                                                                __


                                                                                                Append two _s, in case the last group needs to be padded.



                                                                                                !`...


                                                                                                Match as many groups of three as possible, outputting the matches themselves rather than the count. (In Retina 1 this would be L instead of !.)






                                                                                                share|improve this answer









                                                                                                $endgroup$




                                                                                                Retina 0.8.2, 10 bytes



                                                                                                $
                                                                                                __
                                                                                                !`...


                                                                                                Try it online! Link includes test cases. Explanation:



                                                                                                $
                                                                                                __


                                                                                                Append two _s, in case the last group needs to be padded.



                                                                                                !`...


                                                                                                Match as many groups of three as possible, outputting the matches themselves rather than the count. (In Retina 1 this would be L instead of !.)







                                                                                                share|improve this answer












                                                                                                share|improve this answer



                                                                                                share|improve this answer










                                                                                                answered May 19 at 22:23









                                                                                                NeilNeil

                                                                                                86.3k8 gold badges46 silver badges183 bronze badges




                                                                                                86.3k8 gold badges46 silver badges183 bronze badges























                                                                                                    2












                                                                                                    $begingroup$


                                                                                                    C (gcc), 67 bytes





                                                                                                    i;f(char*_){for(;*_;puts(""))for(i=3;i--;)putchar(*_?*_++:95);_=0;}


                                                                                                    Try it online!



                                                                                                    Always returns a falsey value (0).






                                                                                                    share|improve this answer









                                                                                                    $endgroup$









                                                                                                    • 1




                                                                                                      $begingroup$
                                                                                                      Do you even need to return anything?
                                                                                                      $endgroup$
                                                                                                      – ceilingcat
                                                                                                      May 20 at 14:11










                                                                                                    • $begingroup$
                                                                                                      63 bytes
                                                                                                      $endgroup$
                                                                                                      – Johan du Toit
                                                                                                      May 21 at 10:28
















                                                                                                    2












                                                                                                    $begingroup$


                                                                                                    C (gcc), 67 bytes





                                                                                                    i;f(char*_){for(;*_;puts(""))for(i=3;i--;)putchar(*_?*_++:95);_=0;}


                                                                                                    Try it online!



                                                                                                    Always returns a falsey value (0).






                                                                                                    share|improve this answer









                                                                                                    $endgroup$









                                                                                                    • 1




                                                                                                      $begingroup$
                                                                                                      Do you even need to return anything?
                                                                                                      $endgroup$
                                                                                                      – ceilingcat
                                                                                                      May 20 at 14:11










                                                                                                    • $begingroup$
                                                                                                      63 bytes
                                                                                                      $endgroup$
                                                                                                      – Johan du Toit
                                                                                                      May 21 at 10:28














                                                                                                    2












                                                                                                    2








                                                                                                    2





                                                                                                    $begingroup$


                                                                                                    C (gcc), 67 bytes





                                                                                                    i;f(char*_){for(;*_;puts(""))for(i=3;i--;)putchar(*_?*_++:95);_=0;}


                                                                                                    Try it online!



                                                                                                    Always returns a falsey value (0).






                                                                                                    share|improve this answer









                                                                                                    $endgroup$




                                                                                                    C (gcc), 67 bytes





                                                                                                    i;f(char*_){for(;*_;puts(""))for(i=3;i--;)putchar(*_?*_++:95);_=0;}


                                                                                                    Try it online!



                                                                                                    Always returns a falsey value (0).







                                                                                                    share|improve this answer












                                                                                                    share|improve this answer



                                                                                                    share|improve this answer










                                                                                                    answered May 19 at 23:07









                                                                                                    attinatattinat

                                                                                                    1,6072 silver badges9 bronze badges




                                                                                                    1,6072 silver badges9 bronze badges








                                                                                                    • 1




                                                                                                      $begingroup$
                                                                                                      Do you even need to return anything?
                                                                                                      $endgroup$
                                                                                                      – ceilingcat
                                                                                                      May 20 at 14:11










                                                                                                    • $begingroup$
                                                                                                      63 bytes
                                                                                                      $endgroup$
                                                                                                      – Johan du Toit
                                                                                                      May 21 at 10:28














                                                                                                    • 1




                                                                                                      $begingroup$
                                                                                                      Do you even need to return anything?
                                                                                                      $endgroup$
                                                                                                      – ceilingcat
                                                                                                      May 20 at 14:11










                                                                                                    • $begingroup$
                                                                                                      63 bytes
                                                                                                      $endgroup$
                                                                                                      – Johan du Toit
                                                                                                      May 21 at 10:28








                                                                                                    1




                                                                                                    1




                                                                                                    $begingroup$
                                                                                                    Do you even need to return anything?
                                                                                                    $endgroup$
                                                                                                    – ceilingcat
                                                                                                    May 20 at 14:11




                                                                                                    $begingroup$
                                                                                                    Do you even need to return anything?
                                                                                                    $endgroup$
                                                                                                    – ceilingcat
                                                                                                    May 20 at 14:11












                                                                                                    $begingroup$
                                                                                                    63 bytes
                                                                                                    $endgroup$
                                                                                                    – Johan du Toit
                                                                                                    May 21 at 10:28




                                                                                                    $begingroup$
                                                                                                    63 bytes
                                                                                                    $endgroup$
                                                                                                    – Johan du Toit
                                                                                                    May 21 at 10:28











                                                                                                    2












                                                                                                    $begingroup$


                                                                                                    Wolfram Language (Mathematica), 28 21 bytes



                                                                                                    -7: No longer requires falsy (False) value on empty input



                                                                                                    Partition[#,3,1,1,_]&


                                                                                                    Try it online!



                                                                                                    Takes a list of characters as input. Returns a list of 3-tuples of characters padded with Blanks (_).






                                                                                                    34 27 bytes



                                                                                                    StringPartition[#<>"__",3]&


                                                                                                    Try it online!



                                                                                                    String input, list of strings output






                                                                                                    share|improve this answer











                                                                                                    $endgroup$


















                                                                                                      2












                                                                                                      $begingroup$


                                                                                                      Wolfram Language (Mathematica), 28 21 bytes



                                                                                                      -7: No longer requires falsy (False) value on empty input



                                                                                                      Partition[#,3,1,1,_]&


                                                                                                      Try it online!



                                                                                                      Takes a list of characters as input. Returns a list of 3-tuples of characters padded with Blanks (_).






                                                                                                      34 27 bytes



                                                                                                      StringPartition[#<>"__",3]&


                                                                                                      Try it online!



                                                                                                      String input, list of strings output






                                                                                                      share|improve this answer











                                                                                                      $endgroup$
















                                                                                                        2












                                                                                                        2








                                                                                                        2





                                                                                                        $begingroup$


                                                                                                        Wolfram Language (Mathematica), 28 21 bytes



                                                                                                        -7: No longer requires falsy (False) value on empty input



                                                                                                        Partition[#,3,1,1,_]&


                                                                                                        Try it online!



                                                                                                        Takes a list of characters as input. Returns a list of 3-tuples of characters padded with Blanks (_).






                                                                                                        34 27 bytes



                                                                                                        StringPartition[#<>"__",3]&


                                                                                                        Try it online!



                                                                                                        String input, list of strings output






                                                                                                        share|improve this answer











                                                                                                        $endgroup$




                                                                                                        Wolfram Language (Mathematica), 28 21 bytes



                                                                                                        -7: No longer requires falsy (False) value on empty input



                                                                                                        Partition[#,3,1,1,_]&


                                                                                                        Try it online!



                                                                                                        Takes a list of characters as input. Returns a list of 3-tuples of characters padded with Blanks (_).






                                                                                                        34 27 bytes



                                                                                                        StringPartition[#<>"__",3]&


                                                                                                        Try it online!



                                                                                                        String input, list of strings output







                                                                                                        share|improve this answer














                                                                                                        share|improve this answer



                                                                                                        share|improve this answer








                                                                                                        edited May 26 at 6:40

























                                                                                                        answered May 19 at 22:56









                                                                                                        attinatattinat

                                                                                                        1,6072 silver badges9 bronze badges




                                                                                                        1,6072 silver badges9 bronze badges























                                                                                                            1












                                                                                                            $begingroup$


                                                                                                            Jelly, 9 bytes



                                                                                                            s3o€“___”


                                                                                                            A monadic Link accepting a list of characters which yields a list of lists of characters (an empty input yields empty output).



                                                                                                            Try it online!



                                                                                                            How?



                                                                                                            s3o€“___” - Link: list of characters
                                                                                                            s3 - split into chunks of three
                                                                                                            € - for each chunk:
                                                                                                            o - OR (vectorises):
                                                                                                            “___” - list of characters = ['_', '_', '_']


                                                                                                            Notes:

                                                                                                            The is only necessary to handle the edge case of an empty input.

                                                                                                            A full program can drop a trailing , but here we can't do that as the printing behaviour of a full program smashes everything together.





                                                                                                            Equivalent 9:



                                                                                                            o3ÐƤ“___”


                                                                                                            Try it





                                                                                                            Alternative 9:



                                                                                                            ;“___”s3Ṗ


                                                                                                            Try it






                                                                                                            share|improve this answer











                                                                                                            $endgroup$


















                                                                                                              1












                                                                                                              $begingroup$


                                                                                                              Jelly, 9 bytes



                                                                                                              s3o€“___”


                                                                                                              A monadic Link accepting a list of characters which yields a list of lists of characters (an empty input yields empty output).



                                                                                                              Try it online!



                                                                                                              How?



                                                                                                              s3o€“___” - Link: list of characters
                                                                                                              s3 - split into chunks of three
                                                                                                              € - for each chunk:
                                                                                                              o - OR (vectorises):
                                                                                                              “___” - list of characters = ['_', '_', '_']


                                                                                                              Notes:

                                                                                                              The is only necessary to handle the edge case of an empty input.

                                                                                                              A full program can drop a trailing , but here we can't do that as the printing behaviour of a full program smashes everything together.





                                                                                                              Equivalent 9:



                                                                                                              o3ÐƤ“___”


                                                                                                              Try it





                                                                                                              Alternative 9:



                                                                                                              ;“___”s3Ṗ


                                                                                                              Try it






                                                                                                              share|improve this answer











                                                                                                              $endgroup$
















                                                                                                                1












                                                                                                                1








                                                                                                                1





                                                                                                                $begingroup$


                                                                                                                Jelly, 9 bytes



                                                                                                                s3o€“___”


                                                                                                                A monadic Link accepting a list of characters which yields a list of lists of characters (an empty input yields empty output).



                                                                                                                Try it online!



                                                                                                                How?



                                                                                                                s3o€“___” - Link: list of characters
                                                                                                                s3 - split into chunks of three
                                                                                                                € - for each chunk:
                                                                                                                o - OR (vectorises):
                                                                                                                “___” - list of characters = ['_', '_', '_']


                                                                                                                Notes:

                                                                                                                The is only necessary to handle the edge case of an empty input.

                                                                                                                A full program can drop a trailing , but here we can't do that as the printing behaviour of a full program smashes everything together.





                                                                                                                Equivalent 9:



                                                                                                                o3ÐƤ“___”


                                                                                                                Try it





                                                                                                                Alternative 9:



                                                                                                                ;“___”s3Ṗ


                                                                                                                Try it






                                                                                                                share|improve this answer











                                                                                                                $endgroup$




                                                                                                                Jelly, 9 bytes



                                                                                                                s3o€“___”


                                                                                                                A monadic Link accepting a list of characters which yields a list of lists of characters (an empty input yields empty output).



                                                                                                                Try it online!



                                                                                                                How?



                                                                                                                s3o€“___” - Link: list of characters
                                                                                                                s3 - split into chunks of three
                                                                                                                € - for each chunk:
                                                                                                                o - OR (vectorises):
                                                                                                                “___” - list of characters = ['_', '_', '_']


                                                                                                                Notes:

                                                                                                                The is only necessary to handle the edge case of an empty input.

                                                                                                                A full program can drop a trailing , but here we can't do that as the printing behaviour of a full program smashes everything together.





                                                                                                                Equivalent 9:



                                                                                                                o3ÐƤ“___”


                                                                                                                Try it





                                                                                                                Alternative 9:



                                                                                                                ;“___”s3Ṗ


                                                                                                                Try it







                                                                                                                share|improve this answer














                                                                                                                share|improve this answer



                                                                                                                share|improve this answer








                                                                                                                edited May 19 at 19:46

























                                                                                                                answered May 19 at 19:28









                                                                                                                Jonathan AllanJonathan Allan

                                                                                                                57.6k5 gold badges43 silver badges181 bronze badges




                                                                                                                57.6k5 gold badges43 silver badges181 bronze badges























                                                                                                                    1












                                                                                                                    $begingroup$


                                                                                                                    J, 16 bytes



                                                                                                                    [:}:_3]'___',~]


                                                                                                                    Try it online!




                                                                                                                    K (oK), 19 17 bytes



                                                                                                                    -2 bytes thanks to ngn!



                                                                                                                    {-1_0N 3#x,"___"}


                                                                                                                    Try it online!






                                                                                                                    share|improve this answer











                                                                                                                    $endgroup$









                                                                                                                    • 1




                                                                                                                      $begingroup$
                                                                                                                      k: (0N;3) -> 0N 3
                                                                                                                      $endgroup$
                                                                                                                      – ngn
                                                                                                                      May 20 at 7:21












                                                                                                                    • $begingroup$
                                                                                                                      @ngn Thank you!
                                                                                                                      $endgroup$
                                                                                                                      – Galen Ivanov
                                                                                                                      May 20 at 7:28
















                                                                                                                    1












                                                                                                                    $begingroup$


                                                                                                                    J, 16 bytes



                                                                                                                    [:}:_3]'___',~]


                                                                                                                    Try it online!




                                                                                                                    K (oK), 19 17 bytes



                                                                                                                    -2 bytes thanks to ngn!



                                                                                                                    {-1_0N 3#x,"___"}


                                                                                                                    Try it online!






                                                                                                                    share|improve this answer











                                                                                                                    $endgroup$









                                                                                                                    • 1




                                                                                                                      $begingroup$
                                                                                                                      k: (0N;3) -> 0N 3
                                                                                                                      $endgroup$
                                                                                                                      – ngn
                                                                                                                      May 20 at 7:21












                                                                                                                    • $begingroup$
                                                                                                                      @ngn Thank you!
                                                                                                                      $endgroup$
                                                                                                                      – Galen Ivanov
                                                                                                                      May 20 at 7:28














                                                                                                                    1












                                                                                                                    1








                                                                                                                    1





                                                                                                                    $begingroup$


                                                                                                                    J, 16 bytes



                                                                                                                    [:}:_3]'___',~]


                                                                                                                    Try it online!




                                                                                                                    K (oK), 19 17 bytes



                                                                                                                    -2 bytes thanks to ngn!



                                                                                                                    {-1_0N 3#x,"___"}


                                                                                                                    Try it online!






                                                                                                                    share|improve this answer











                                                                                                                    $endgroup$




                                                                                                                    J, 16 bytes



                                                                                                                    [:}:_3]'___',~]


                                                                                                                    Try it online!




                                                                                                                    K (oK), 19 17 bytes



                                                                                                                    -2 bytes thanks to ngn!



                                                                                                                    {-1_0N 3#x,"___"}


                                                                                                                    Try it online!







                                                                                                                    share|improve this answer














                                                                                                                    share|improve this answer



                                                                                                                    share|improve this answer








                                                                                                                    edited May 20 at 7:22

























                                                                                                                    answered May 20 at 6:41









                                                                                                                    Galen IvanovGalen Ivanov

                                                                                                                    8,8771 gold badge12 silver badges37 bronze badges




                                                                                                                    8,8771 gold badge12 silver badges37 bronze badges








                                                                                                                    • 1




                                                                                                                      $begingroup$
                                                                                                                      k: (0N;3) -> 0N 3
                                                                                                                      $endgroup$
                                                                                                                      – ngn
                                                                                                                      May 20 at 7:21












                                                                                                                    • $begingroup$
                                                                                                                      @ngn Thank you!
                                                                                                                      $endgroup$
                                                                                                                      – Galen Ivanov
                                                                                                                      May 20 at 7:28














                                                                                                                    • 1




                                                                                                                      $begingroup$
                                                                                                                      k: (0N;3) -> 0N 3
                                                                                                                      $endgroup$
                                                                                                                      – ngn
                                                                                                                      May 20 at 7:21












                                                                                                                    • $begingroup$
                                                                                                                      @ngn Thank you!
                                                                                                                      $endgroup$
                                                                                                                      – Galen Ivanov
                                                                                                                      May 20 at 7:28








                                                                                                                    1




                                                                                                                    1




                                                                                                                    $begingroup$
                                                                                                                    k: (0N;3) -> 0N 3
                                                                                                                    $endgroup$
                                                                                                                    – ngn
                                                                                                                    May 20 at 7:21






                                                                                                                    $begingroup$
                                                                                                                    k: (0N;3) -> 0N 3
                                                                                                                    $endgroup$
                                                                                                                    – ngn
                                                                                                                    May 20 at 7:21














                                                                                                                    $begingroup$
                                                                                                                    @ngn Thank you!
                                                                                                                    $endgroup$
                                                                                                                    – Galen Ivanov
                                                                                                                    May 20 at 7:28




                                                                                                                    $begingroup$
                                                                                                                    @ngn Thank you!
                                                                                                                    $endgroup$
                                                                                                                    – Galen Ivanov
                                                                                                                    May 20 at 7:28











                                                                                                                    1












                                                                                                                    $begingroup$

                                                                                                                    Java 10, 116 113 bytes





                                                                                                                    s->{s+="__";int l=s.length()/3,i=l;var r=new String[l];for(;i-->0;)r[i]=s.substring(i*3,i*3+3);return l<1?0>1:r;}


                                                                                                                    Try it online.



                                                                                                                    Or 104 101 bytes if an empty array instead of false is allowed as output..



                                                                                                                    s->{s+="__";int l=s.length()/3;var r=new String[l];for(;l-->0;)r[l]=s.substring(l*3,l*3+3);return r;}


                                                                                                                    Try it online.



                                                                                                                    Explanation:



                                                                                                                    s->{                             // Method with String as both parameter and return-type
                                                                                                                    s+="__"; // Append two "_" to the input-String
                                                                                                                    int l=s.length()/3; // Get the length, integer-divided by 3
                                                                                                                    var r=new String[l]; // Create a string-array with that many parts
                                                                                                                    for(;l-->0;) // Loop `l` in the range (l, 0]:
                                                                                                                    r[l]= // Set the `l`'th value of the array to:
                                                                                                                    s.substring(l*3,l*3+3); // Get the substring of size 3 from index `l*3` from `s`
                                                                                                                    return r;} // Return the array





                                                                                                                    share|improve this answer









                                                                                                                    $endgroup$













                                                                                                                    • $begingroup$
                                                                                                                      An empty array is now allowed
                                                                                                                      $endgroup$
                                                                                                                      – Benjamin Urquhart
                                                                                                                      May 26 at 3:57
















                                                                                                                    1












                                                                                                                    $begingroup$

                                                                                                                    Java 10, 116 113 bytes





                                                                                                                    s->{s+="__";int l=s.length()/3,i=l;var r=new String[l];for(;i-->0;)r[i]=s.substring(i*3,i*3+3);return l<1?0>1:r;}


                                                                                                                    Try it online.



                                                                                                                    Or 104 101 bytes if an empty array instead of false is allowed as output..



                                                                                                                    s->{s+="__";int l=s.length()/3;var r=new String[l];for(;l-->0;)r[l]=s.substring(l*3,l*3+3);return r;}


                                                                                                                    Try it online.



                                                                                                                    Explanation:



                                                                                                                    s->{                             // Method with String as both parameter and return-type
                                                                                                                    s+="__"; // Append two "_" to the input-String
                                                                                                                    int l=s.length()/3; // Get the length, integer-divided by 3
                                                                                                                    var r=new String[l]; // Create a string-array with that many parts
                                                                                                                    for(;l-->0;) // Loop `l` in the range (l, 0]:
                                                                                                                    r[l]= // Set the `l`'th value of the array to:
                                                                                                                    s.substring(l*3,l*3+3); // Get the substring of size 3 from index `l*3` from `s`
                                                                                                                    return r;} // Return the array





                                                                                                                    share|improve this answer









                                                                                                                    $endgroup$













                                                                                                                    • $begingroup$
                                                                                                                      An empty array is now allowed
                                                                                                                      $endgroup$
                                                                                                                      – Benjamin Urquhart
                                                                                                                      May 26 at 3:57














                                                                                                                    1












                                                                                                                    1








                                                                                                                    1





                                                                                                                    $begingroup$

                                                                                                                    Java 10, 116 113 bytes





                                                                                                                    s->{s+="__";int l=s.length()/3,i=l;var r=new String[l];for(;i-->0;)r[i]=s.substring(i*3,i*3+3);return l<1?0>1:r;}


                                                                                                                    Try it online.



                                                                                                                    Or 104 101 bytes if an empty array instead of false is allowed as output..



                                                                                                                    s->{s+="__";int l=s.length()/3;var r=new String[l];for(;l-->0;)r[l]=s.substring(l*3,l*3+3);return r;}


                                                                                                                    Try it online.



                                                                                                                    Explanation:



                                                                                                                    s->{                             // Method with String as both parameter and return-type
                                                                                                                    s+="__"; // Append two "_" to the input-String
                                                                                                                    int l=s.length()/3; // Get the length, integer-divided by 3
                                                                                                                    var r=new String[l]; // Create a string-array with that many parts
                                                                                                                    for(;l-->0;) // Loop `l` in the range (l, 0]:
                                                                                                                    r[l]= // Set the `l`'th value of the array to:
                                                                                                                    s.substring(l*3,l*3+3); // Get the substring of size 3 from index `l*3` from `s`
                                                                                                                    return r;} // Return the array





                                                                                                                    share|improve this answer









                                                                                                                    $endgroup$



                                                                                                                    Java 10, 116 113 bytes





                                                                                                                    s->{s+="__";int l=s.length()/3,i=l;var r=new String[l];for(;i-->0;)r[i]=s.substring(i*3,i*3+3);return l<1?0>1:r;}


                                                                                                                    Try it online.



                                                                                                                    Or 104 101 bytes if an empty array instead of false is allowed as output..



                                                                                                                    s->{s+="__";int l=s.length()/3;var r=new String[l];for(;l-->0;)r[l]=s.substring(l*3,l*3+3);return r;}


                                                                                                                    Try it online.



                                                                                                                    Explanation:



                                                                                                                    s->{                             // Method with String as both parameter and return-type
                                                                                                                    s+="__"; // Append two "_" to the input-String
                                                                                                                    int l=s.length()/3; // Get the length, integer-divided by 3
                                                                                                                    var r=new String[l]; // Create a string-array with that many parts
                                                                                                                    for(;l-->0;) // Loop `l` in the range (l, 0]:
                                                                                                                    r[l]= // Set the `l`'th value of the array to:
                                                                                                                    s.substring(l*3,l*3+3); // Get the substring of size 3 from index `l*3` from `s`
                                                                                                                    return r;} // Return the array






                                                                                                                    share|improve this answer












                                                                                                                    share|improve this answer



                                                                                                                    share|improve this answer










                                                                                                                    answered May 20 at 8:41









                                                                                                                    Kevin CruijssenKevin Cruijssen

                                                                                                                    47.9k7 gold badges83 silver badges241 bronze badges




                                                                                                                    47.9k7 gold badges83 silver badges241 bronze badges












                                                                                                                    • $begingroup$
                                                                                                                      An empty array is now allowed
                                                                                                                      $endgroup$
                                                                                                                      – Benjamin Urquhart
                                                                                                                      May 26 at 3:57


















                                                                                                                    • $begingroup$
                                                                                                                      An empty array is now allowed
                                                                                                                      $endgroup$
                                                                                                                      – Benjamin Urquhart
                                                                                                                      May 26 at 3:57
















                                                                                                                    $begingroup$
                                                                                                                    An empty array is now allowed
                                                                                                                    $endgroup$
                                                                                                                    – Benjamin Urquhart
                                                                                                                    May 26 at 3:57




                                                                                                                    $begingroup$
                                                                                                                    An empty array is now allowed
                                                                                                                    $endgroup$
                                                                                                                    – Benjamin Urquhart
                                                                                                                    May 26 at 3:57











                                                                                                                    1












                                                                                                                    $begingroup$

                                                                                                                    Ruby, 73 42 bytes



                                                                                                                    a=gets
                                                                                                                    a.length!=0?a.scan(/.{1,3}/).map{|s|(s+'_'*3)[0,3]}:'falsey value'


                                                                                                                    Edit: As falsey value looks like it's not required:



                                                                                                                    gets.scan(/.{1,3}/).map{|s|(s+'_'*3)[0,3]}





                                                                                                                    share|improve this answer











                                                                                                                    $endgroup$









                                                                                                                    • 1




                                                                                                                      $begingroup$
                                                                                                                      The maximum padding is of 2 characters, so '_'*2 would be enough, for which a literal '__' is shorter. But if you add the padding in advance then simply not match the pieces shorter than 3 characters, is shorter: puts"#{gets}__".scan /.../. (Note that without the explicit printing that is considered irb not ruby.)
                                                                                                                      $endgroup$
                                                                                                                      – manatwork
                                                                                                                      May 20 at 15:06


















                                                                                                                    1












                                                                                                                    $begingroup$

                                                                                                                    Ruby, 73 42 bytes



                                                                                                                    a=gets
                                                                                                                    a.length!=0?a.scan(/.{1,3}/).map{|s|(s+'_'*3)[0,3]}:'falsey value'


                                                                                                                    Edit: As falsey value looks like it's not required:



                                                                                                                    gets.scan(/.{1,3}/).map{|s|(s+'_'*3)[0,3]}





                                                                                                                    share|improve this answer











                                                                                                                    $endgroup$









                                                                                                                    • 1




                                                                                                                      $begingroup$
                                                                                                                      The maximum padding is of 2 characters, so '_'*2 would be enough, for which a literal '__' is shorter. But if you add the padding in advance then simply not match the pieces shorter than 3 characters, is shorter: puts"#{gets}__".scan /.../. (Note that without the explicit printing that is considered irb not ruby.)
                                                                                                                      $endgroup$
                                                                                                                      – manatwork
                                                                                                                      May 20 at 15:06
















                                                                                                                    1












                                                                                                                    1








                                                                                                                    1





                                                                                                                    $begingroup$

                                                                                                                    Ruby, 73 42 bytes



                                                                                                                    a=gets
                                                                                                                    a.length!=0?a.scan(/.{1,3}/).map{|s|(s+'_'*3)[0,3]}:'falsey value'


                                                                                                                    Edit: As falsey value looks like it's not required:



                                                                                                                    gets.scan(/.{1,3}/).map{|s|(s+'_'*3)[0,3]}





                                                                                                                    share|improve this answer











                                                                                                                    $endgroup$



                                                                                                                    Ruby, 73 42 bytes



                                                                                                                    a=gets
                                                                                                                    a.length!=0?a.scan(/.{1,3}/).map{|s|(s+'_'*3)[0,3]}:'falsey value'


                                                                                                                    Edit: As falsey value looks like it's not required:



                                                                                                                    gets.scan(/.{1,3}/).map{|s|(s+'_'*3)[0,3]}






                                                                                                                    share|improve this answer














                                                                                                                    share|improve this answer



                                                                                                                    share|improve this answer








                                                                                                                    edited May 20 at 9:59

























                                                                                                                    answered May 20 at 9:53









                                                                                                                    Max LangerakMax Langerak

                                                                                                                    1113 bronze badges




                                                                                                                    1113 bronze badges








                                                                                                                    • 1




                                                                                                                      $begingroup$
                                                                                                                      The maximum padding is of 2 characters, so '_'*2 would be enough, for which a literal '__' is shorter. But if you add the padding in advance then simply not match the pieces shorter than 3 characters, is shorter: puts"#{gets}__".scan /.../. (Note that without the explicit printing that is considered irb not ruby.)
                                                                                                                      $endgroup$
                                                                                                                      – manatwork
                                                                                                                      May 20 at 15:06
















                                                                                                                    • 1




                                                                                                                      $begingroup$
                                                                                                                      The maximum padding is of 2 characters, so '_'*2 would be enough, for which a literal '__' is shorter. But if you add the padding in advance then simply not match the pieces shorter than 3 characters, is shorter: puts"#{gets}__".scan /.../. (Note that without the explicit printing that is considered irb not ruby.)
                                                                                                                      $endgroup$
                                                                                                                      – manatwork
                                                                                                                      May 20 at 15:06










                                                                                                                    1




                                                                                                                    1




                                                                                                                    $begingroup$
                                                                                                                    The maximum padding is of 2 characters, so '_'*2 would be enough, for which a literal '__' is shorter. But if you add the padding in advance then simply not match the pieces shorter than 3 characters, is shorter: puts"#{gets}__".scan /.../. (Note that without the explicit printing that is considered irb not ruby.)
                                                                                                                    $endgroup$
                                                                                                                    – manatwork
                                                                                                                    May 20 at 15:06






                                                                                                                    $begingroup$
                                                                                                                    The maximum padding is of 2 characters, so '_'*2 would be enough, for which a literal '__' is shorter. But if you add the padding in advance then simply not match the pieces shorter than 3 characters, is shorter: puts"#{gets}__".scan /.../. (Note that without the explicit printing that is considered irb not ruby.)
                                                                                                                    $endgroup$
                                                                                                                    – manatwork
                                                                                                                    May 20 at 15:06













                                                                                                                    1












                                                                                                                    $begingroup$


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



                                                                                                                    Just append two underscores '_' at the end of the input to make sure they get printed if the length of the input isn't a factor of 3.



                                                                                                                    s=>Enumerable.Range(0,(s.Length+2)/3).Select(i=>(s+"__").Substring(i*3,3))


                                                                                                                    Try it online!






                                                                                                                    share|improve this answer









                                                                                                                    $endgroup$













                                                                                                                    • $begingroup$
                                                                                                                      67
                                                                                                                      $endgroup$
                                                                                                                      – dana
                                                                                                                      May 22 at 5:20










                                                                                                                    • $begingroup$
                                                                                                                      57
                                                                                                                      $endgroup$
                                                                                                                      – someone
                                                                                                                      May 25 at 1:22


















                                                                                                                    1












                                                                                                                    $begingroup$


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



                                                                                                                    Just append two underscores '_' at the end of the input to make sure they get printed if the length of the input isn't a factor of 3.



                                                                                                                    s=>Enumerable.Range(0,(s.Length+2)/3).Select(i=>(s+"__").Substring(i*3,3))


                                                                                                                    Try it online!






                                                                                                                    share|improve this answer









                                                                                                                    $endgroup$













                                                                                                                    • $begingroup$
                                                                                                                      67
                                                                                                                      $endgroup$
                                                                                                                      – dana
                                                                                                                      May 22 at 5:20










                                                                                                                    • $begingroup$
                                                                                                                      57
                                                                                                                      $endgroup$
                                                                                                                      – someone
                                                                                                                      May 25 at 1:22
















                                                                                                                    1












                                                                                                                    1








                                                                                                                    1





                                                                                                                    $begingroup$


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



                                                                                                                    Just append two underscores '_' at the end of the input to make sure they get printed if the length of the input isn't a factor of 3.



                                                                                                                    s=>Enumerable.Range(0,(s.Length+2)/3).Select(i=>(s+"__").Substring(i*3,3))


                                                                                                                    Try it online!






                                                                                                                    share|improve this answer









                                                                                                                    $endgroup$




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



                                                                                                                    Just append two underscores '_' at the end of the input to make sure they get printed if the length of the input isn't a factor of 3.



                                                                                                                    s=>Enumerable.Range(0,(s.Length+2)/3).Select(i=>(s+"__").Substring(i*3,3))


                                                                                                                    Try it online!







                                                                                                                    share|improve this answer












                                                                                                                    share|improve this answer



                                                                                                                    share|improve this answer










                                                                                                                    answered May 20 at 12:01









                                                                                                                    Innat3Innat3

                                                                                                                    5716 bronze badges




                                                                                                                    5716 bronze badges












                                                                                                                    • $begingroup$
                                                                                                                      67
                                                                                                                      $endgroup$
                                                                                                                      – dana
                                                                                                                      May 22 at 5:20










                                                                                                                    • $begingroup$
                                                                                                                      57
                                                                                                                      $endgroup$
                                                                                                                      – someone
                                                                                                                      May 25 at 1:22




















                                                                                                                    • $begingroup$
                                                                                                                      67
                                                                                                                      $endgroup$
                                                                                                                      – dana
                                                                                                                      May 22 at 5:20










                                                                                                                    • $begingroup$
                                                                                                                      57
                                                                                                                      $endgroup$
                                                                                                                      – someone
                                                                                                                      May 25 at 1:22


















                                                                                                                    $begingroup$
                                                                                                                    67
                                                                                                                    $endgroup$
                                                                                                                    – dana
                                                                                                                    May 22 at 5:20




                                                                                                                    $begingroup$
                                                                                                                    67
                                                                                                                    $endgroup$
                                                                                                                    – dana
                                                                                                                    May 22 at 5:20












                                                                                                                    $begingroup$
                                                                                                                    57
                                                                                                                    $endgroup$
                                                                                                                    – someone
                                                                                                                    May 25 at 1:22






                                                                                                                    $begingroup$
                                                                                                                    57
                                                                                                                    $endgroup$
                                                                                                                    – someone
                                                                                                                    May 25 at 1:22













                                                                                                                    1












                                                                                                                    $begingroup$


                                                                                                                    Kotlin, 34 bytes



                                                                                                                    {"${it}__".chunked(3).dropLast(1)}


                                                                                                                    Try it online!






                                                                                                                    share|improve this answer









                                                                                                                    $endgroup$













                                                                                                                    • $begingroup$
                                                                                                                      this does not work, try {"${it}___".chunked(3).dropLast(1)}
                                                                                                                      $endgroup$
                                                                                                                      – pme
                                                                                                                      May 21 at 6:45
















                                                                                                                    1












                                                                                                                    $begingroup$


                                                                                                                    Kotlin, 34 bytes



                                                                                                                    {"${it}__".chunked(3).dropLast(1)}


                                                                                                                    Try it online!






                                                                                                                    share|improve this answer









                                                                                                                    $endgroup$













                                                                                                                    • $begingroup$
                                                                                                                      this does not work, try {"${it}___".chunked(3).dropLast(1)}
                                                                                                                      $endgroup$
                                                                                                                      – pme
                                                                                                                      May 21 at 6:45














                                                                                                                    1












                                                                                                                    1








                                                                                                                    1





                                                                                                                    $begingroup$


                                                                                                                    Kotlin, 34 bytes



                                                                                                                    {"${it}__".chunked(3).dropLast(1)}


                                                                                                                    Try it online!






                                                                                                                    share|improve this answer









                                                                                                                    $endgroup$




                                                                                                                    Kotlin, 34 bytes



                                                                                                                    {"${it}__".chunked(3).dropLast(1)}


                                                                                                                    Try it online!







                                                                                                                    share|improve this answer












                                                                                                                    share|improve this answer



                                                                                                                    share|improve this answer










                                                                                                                    answered May 20 at 15:16









                                                                                                                    snail_snail_

                                                                                                                    1,7525 silver badges15 bronze badges




                                                                                                                    1,7525 silver badges15 bronze badges












                                                                                                                    • $begingroup$
                                                                                                                      this does not work, try {"${it}___".chunked(3).dropLast(1)}
                                                                                                                      $endgroup$
                                                                                                                      – pme
                                                                                                                      May 21 at 6:45


















                                                                                                                    • $begingroup$
                                                                                                                      this does not work, try {"${it}___".chunked(3).dropLast(1)}
                                                                                                                      $endgroup$
                                                                                                                      – pme
                                                                                                                      May 21 at 6:45
















                                                                                                                    $begingroup$
                                                                                                                    this does not work, try {"${it}___".chunked(3).dropLast(1)}
                                                                                                                    $endgroup$
                                                                                                                    – pme
                                                                                                                    May 21 at 6:45




                                                                                                                    $begingroup$
                                                                                                                    this does not work, try {"${it}___".chunked(3).dropLast(1)}
                                                                                                                    $endgroup$
                                                                                                                    – pme
                                                                                                                    May 21 at 6:45











                                                                                                                    1












                                                                                                                    $begingroup$


                                                                                                                    C (gcc), 55 bytes





                                                                                                                    i;f(char*s){for(;i%4|*s;)putchar(++i%4?*s?*s++:95:10);}


                                                                                                                    Try it online!






                                                                                                                    share|improve this answer











                                                                                                                    $endgroup$













                                                                                                                    • $begingroup$
                                                                                                                      Using 9(t) instead of 10(n) should be fine, but that's not main point
                                                                                                                      $endgroup$
                                                                                                                      – l4m2
                                                                                                                      May 20 at 15:23
















                                                                                                                    1












                                                                                                                    $begingroup$


                                                                                                                    C (gcc), 55 bytes





                                                                                                                    i;f(char*s){for(;i%4|*s;)putchar(++i%4?*s?*s++:95:10);}


                                                                                                                    Try it online!






                                                                                                                    share|improve this answer











                                                                                                                    $endgroup$













                                                                                                                    • $begingroup$
                                                                                                                      Using 9(t) instead of 10(n) should be fine, but that's not main point
                                                                                                                      $endgroup$
                                                                                                                      – l4m2
                                                                                                                      May 20 at 15:23














                                                                                                                    1












                                                                                                                    1








                                                                                                                    1





                                                                                                                    $begingroup$


                                                                                                                    C (gcc), 55 bytes





                                                                                                                    i;f(char*s){for(;i%4|*s;)putchar(++i%4?*s?*s++:95:10);}


                                                                                                                    Try it online!






                                                                                                                    share|improve this answer











                                                                                                                    $endgroup$




                                                                                                                    C (gcc), 55 bytes





                                                                                                                    i;f(char*s){for(;i%4|*s;)putchar(++i%4?*s?*s++:95:10);}


                                                                                                                    Try it online!







                                                                                                                    share|improve this answer














                                                                                                                    share|improve this answer



                                                                                                                    share|improve this answer








                                                                                                                    edited May 20 at 15:41

























                                                                                                                    answered May 20 at 15:22









                                                                                                                    l4m2l4m2

                                                                                                                    4,8771 gold badge8 silver badges35 bronze badges




                                                                                                                    4,8771 gold badge8 silver badges35 bronze badges












                                                                                                                    • $begingroup$
                                                                                                                      Using 9(t) instead of 10(n) should be fine, but that's not main point
                                                                                                                      $endgroup$
                                                                                                                      – l4m2
                                                                                                                      May 20 at 15:23


















                                                                                                                    • $begingroup$
                                                                                                                      Using 9(t) instead of 10(n) should be fine, but that's not main point
                                                                                                                      $endgroup$
                                                                                                                      – l4m2
                                                                                                                      May 20 at 15:23
















                                                                                                                    $begingroup$
                                                                                                                    Using 9(t) instead of 10(n) should be fine, but that's not main point
                                                                                                                    $endgroup$
                                                                                                                    – l4m2
                                                                                                                    May 20 at 15:23




                                                                                                                    $begingroup$
                                                                                                                    Using 9(t) instead of 10(n) should be fine, but that's not main point
                                                                                                                    $endgroup$
                                                                                                                    – l4m2
                                                                                                                    May 20 at 15:23











                                                                                                                    1












                                                                                                                    $begingroup$


                                                                                                                    C (clang), 128 126 94 67 bytes



                                                                                                                    67 bytes thanks to @ceilingcat





                                                                                                                    f(char*k){for(;*k;k++)printf("%c%c%cn",*k,*++k?*k:95,*++k?*k:95);}


                                                                                                                    Try it online!






                                                                                                                    share|improve this answer











                                                                                                                    $endgroup$


















                                                                                                                      1












                                                                                                                      $begingroup$


                                                                                                                      C (clang), 128 126 94 67 bytes



                                                                                                                      67 bytes thanks to @ceilingcat





                                                                                                                      f(char*k){for(;*k;k++)printf("%c%c%cn",*k,*++k?*k:95,*++k?*k:95);}


                                                                                                                      Try it online!






                                                                                                                      share|improve this answer











                                                                                                                      $endgroup$
















                                                                                                                        1












                                                                                                                        1








                                                                                                                        1





                                                                                                                        $begingroup$


                                                                                                                        C (clang), 128 126 94 67 bytes



                                                                                                                        67 bytes thanks to @ceilingcat





                                                                                                                        f(char*k){for(;*k;k++)printf("%c%c%cn",*k,*++k?*k:95,*++k?*k:95);}


                                                                                                                        Try it online!






                                                                                                                        share|improve this answer











                                                                                                                        $endgroup$




                                                                                                                        C (clang), 128 126 94 67 bytes



                                                                                                                        67 bytes thanks to @ceilingcat





                                                                                                                        f(char*k){for(;*k;k++)printf("%c%c%cn",*k,*++k?*k:95,*++k?*k:95);}


                                                                                                                        Try it online!







                                                                                                                        share|improve this answer














                                                                                                                        share|improve this answer



                                                                                                                        share|improve this answer








                                                                                                                        edited May 21 at 0:04

























                                                                                                                        answered May 19 at 16:31









                                                                                                                        a stone arachnida stone arachnid

                                                                                                                        9932 silver badges13 bronze badges




                                                                                                                        9932 silver badges13 bronze badges























                                                                                                                            1












                                                                                                                            $begingroup$


                                                                                                                            Bash, 90 bytes



                                                                                                                            This uses Bash features rather than a combination of more traditional Bourne shell plus *nix commands (which one version I created ended up at 205 bytes). I cheated by using the dodge of adding two _ characters to the string.



                                                                                                                            c=;read a;a=${a}__;while (($(echo ${#a})>2));do b=${a:0:3};c=$c $b;a=${a#$b};done;echo $c


                                                                                                                            Try it online!






                                                                                                                            share|improve this answer









                                                                                                                            $endgroup$


















                                                                                                                              1












                                                                                                                              $begingroup$


                                                                                                                              Bash, 90 bytes



                                                                                                                              This uses Bash features rather than a combination of more traditional Bourne shell plus *nix commands (which one version I created ended up at 205 bytes). I cheated by using the dodge of adding two _ characters to the string.



                                                                                                                              c=;read a;a=${a}__;while (($(echo ${#a})>2));do b=${a:0:3};c=$c $b;a=${a#$b};done;echo $c


                                                                                                                              Try it online!






                                                                                                                              share|improve this answer









                                                                                                                              $endgroup$
















                                                                                                                                1












                                                                                                                                1








                                                                                                                                1





                                                                                                                                $begingroup$


                                                                                                                                Bash, 90 bytes



                                                                                                                                This uses Bash features rather than a combination of more traditional Bourne shell plus *nix commands (which one version I created ended up at 205 bytes). I cheated by using the dodge of adding two _ characters to the string.



                                                                                                                                c=;read a;a=${a}__;while (($(echo ${#a})>2));do b=${a:0:3};c=$c $b;a=${a#$b};done;echo $c


                                                                                                                                Try it online!






                                                                                                                                share|improve this answer









                                                                                                                                $endgroup$




                                                                                                                                Bash, 90 bytes



                                                                                                                                This uses Bash features rather than a combination of more traditional Bourne shell plus *nix commands (which one version I created ended up at 205 bytes). I cheated by using the dodge of adding two _ characters to the string.



                                                                                                                                c=;read a;a=${a}__;while (($(echo ${#a})>2));do b=${a:0:3};c=$c $b;a=${a#$b};done;echo $c


                                                                                                                                Try it online!







                                                                                                                                share|improve this answer












                                                                                                                                share|improve this answer



                                                                                                                                share|improve this answer










                                                                                                                                answered May 21 at 14:52









                                                                                                                                PJFPJF

                                                                                                                                713 bronze badges




                                                                                                                                713 bronze badges























                                                                                                                                    1












                                                                                                                                    $begingroup$


                                                                                                                                    PowerShell, 58 35 bytes



                                                                                                                                    $args-split'(...)'-ne''|% *ht 3 '_'


                                                                                                                                    -23 bytes thanks to mazzy.



                                                                                                                                    Try it online!






                                                                                                                                    share|improve this answer











                                                                                                                                    $endgroup$













                                                                                                                                    • $begingroup$
                                                                                                                                      Nice. 1) You can count a code that can be extracted into a ps1-file and executed. 2) See shortcuts. 3) Try to golf more
                                                                                                                                      $endgroup$
                                                                                                                                      – mazzy
                                                                                                                                      May 25 at 5:18
















                                                                                                                                    1












                                                                                                                                    $begingroup$


                                                                                                                                    PowerShell, 58 35 bytes



                                                                                                                                    $args-split'(...)'-ne''|% *ht 3 '_'


                                                                                                                                    -23 bytes thanks to mazzy.



                                                                                                                                    Try it online!






                                                                                                                                    share|improve this answer











                                                                                                                                    $endgroup$













                                                                                                                                    • $begingroup$
                                                                                                                                      Nice. 1) You can count a code that can be extracted into a ps1-file and executed. 2) See shortcuts. 3) Try to golf more
                                                                                                                                      $endgroup$
                                                                                                                                      – mazzy
                                                                                                                                      May 25 at 5:18














                                                                                                                                    1












                                                                                                                                    1








                                                                                                                                    1





                                                                                                                                    $begingroup$


                                                                                                                                    PowerShell, 58 35 bytes



                                                                                                                                    $args-split'(...)'-ne''|% *ht 3 '_'


                                                                                                                                    -23 bytes thanks to mazzy.



                                                                                                                                    Try it online!






                                                                                                                                    share|improve this answer











                                                                                                                                    $endgroup$




                                                                                                                                    PowerShell, 58 35 bytes



                                                                                                                                    $args-split'(...)'-ne''|% *ht 3 '_'


                                                                                                                                    -23 bytes thanks to mazzy.



                                                                                                                                    Try it online!







                                                                                                                                    share|improve this answer














                                                                                                                                    share|improve this answer



                                                                                                                                    share|improve this answer








                                                                                                                                    edited May 25 at 5:15

























                                                                                                                                    answered May 24 at 21:22









                                                                                                                                    Andrei OdegovAndrei Odegov

                                                                                                                                    7193 silver badges6 bronze badges




                                                                                                                                    7193 silver badges6 bronze badges












                                                                                                                                    • $begingroup$
                                                                                                                                      Nice. 1) You can count a code that can be extracted into a ps1-file and executed. 2) See shortcuts. 3) Try to golf more
                                                                                                                                      $endgroup$
                                                                                                                                      – mazzy
                                                                                                                                      May 25 at 5:18


















                                                                                                                                    • $begingroup$
                                                                                                                                      Nice. 1) You can count a code that can be extracted into a ps1-file and executed. 2) See shortcuts. 3) Try to golf more
                                                                                                                                      $endgroup$
                                                                                                                                      – mazzy
                                                                                                                                      May 25 at 5:18
















                                                                                                                                    $begingroup$
                                                                                                                                    Nice. 1) You can count a code that can be extracted into a ps1-file and executed. 2) See shortcuts. 3) Try to golf more
                                                                                                                                    $endgroup$
                                                                                                                                    – mazzy
                                                                                                                                    May 25 at 5:18




                                                                                                                                    $begingroup$
                                                                                                                                    Nice. 1) You can count a code that can be extracted into a ps1-file and executed. 2) See shortcuts. 3) Try to golf more
                                                                                                                                    $endgroup$
                                                                                                                                    – mazzy
                                                                                                                                    May 25 at 5:18











                                                                                                                                    1












                                                                                                                                    $begingroup$


                                                                                                                                    GNU sed, 27 bytes



                                                                                                                                    s:$:__:
                                                                                                                                    s:...:& :g
                                                                                                                                    s: _*$::


                                                                                                                                    Try it online!



                                                                                                                                    It gets a bit tricky regarding the empty string input, since sed has no meaning of a falsy value. So to deal with this, I provide you with two possible interpretations of the rules to validate my submission:





                                                                                                                                    A. You essentially provide nothing as input, not even a trailing newline (as it is the case with all the examples, including that 6 Mb file).



                                                                                                                                    Usage:



                                                                                                                                    echo -n ""|sed -f script


                                                                                                                                    Output: nothing is printed, because sed doesn't even run the script without input.





                                                                                                                                    B. One could consider as falsy value for sed to be an unique string, i.e., returned only when the input is an empty string.



                                                                                                                                    Usage:



                                                                                                                                    echo ""|sed -f script


                                                                                                                                    Output:



                                                                                                                                    __




                                                                                                                                    I prefer the first interpretation so much more, as I believe it to be the closest to the intended rule, but the last one helps if you run the script using that TIO link.






                                                                                                                                    share|improve this answer









                                                                                                                                    $endgroup$


















                                                                                                                                      1












                                                                                                                                      $begingroup$


                                                                                                                                      GNU sed, 27 bytes



                                                                                                                                      s:$:__:
                                                                                                                                      s:...:& :g
                                                                                                                                      s: _*$::


                                                                                                                                      Try it online!



                                                                                                                                      It gets a bit tricky regarding the empty string input, since sed has no meaning of a falsy value. So to deal with this, I provide you with two possible interpretations of the rules to validate my submission:





                                                                                                                                      A. You essentially provide nothing as input, not even a trailing newline (as it is the case with all the examples, including that 6 Mb file).



                                                                                                                                      Usage:



                                                                                                                                      echo -n ""|sed -f script


                                                                                                                                      Output: nothing is printed, because sed doesn't even run the script without input.





                                                                                                                                      B. One could consider as falsy value for sed to be an unique string, i.e., returned only when the input is an empty string.



                                                                                                                                      Usage:



                                                                                                                                      echo ""|sed -f script


                                                                                                                                      Output:



                                                                                                                                      __




                                                                                                                                      I prefer the first interpretation so much more, as I believe it to be the closest to the intended rule, but the last one helps if you run the script using that TIO link.






                                                                                                                                      share|improve this answer









                                                                                                                                      $endgroup$
















                                                                                                                                        1












                                                                                                                                        1








                                                                                                                                        1





                                                                                                                                        $begingroup$


                                                                                                                                        GNU sed, 27 bytes



                                                                                                                                        s:$:__:
                                                                                                                                        s:...:& :g
                                                                                                                                        s: _*$::


                                                                                                                                        Try it online!



                                                                                                                                        It gets a bit tricky regarding the empty string input, since sed has no meaning of a falsy value. So to deal with this, I provide you with two possible interpretations of the rules to validate my submission:





                                                                                                                                        A. You essentially provide nothing as input, not even a trailing newline (as it is the case with all the examples, including that 6 Mb file).



                                                                                                                                        Usage:



                                                                                                                                        echo -n ""|sed -f script


                                                                                                                                        Output: nothing is printed, because sed doesn't even run the script without input.





                                                                                                                                        B. One could consider as falsy value for sed to be an unique string, i.e., returned only when the input is an empty string.



                                                                                                                                        Usage:



                                                                                                                                        echo ""|sed -f script


                                                                                                                                        Output:



                                                                                                                                        __




                                                                                                                                        I prefer the first interpretation so much more, as I believe it to be the closest to the intended rule, but the last one helps if you run the script using that TIO link.






                                                                                                                                        share|improve this answer









                                                                                                                                        $endgroup$




                                                                                                                                        GNU sed, 27 bytes



                                                                                                                                        s:$:__:
                                                                                                                                        s:...:& :g
                                                                                                                                        s: _*$::


                                                                                                                                        Try it online!



                                                                                                                                        It gets a bit tricky regarding the empty string input, since sed has no meaning of a falsy value. So to deal with this, I provide you with two possible interpretations of the rules to validate my submission:





                                                                                                                                        A. You essentially provide nothing as input, not even a trailing newline (as it is the case with all the examples, including that 6 Mb file).



                                                                                                                                        Usage:



                                                                                                                                        echo -n ""|sed -f script


                                                                                                                                        Output: nothing is printed, because sed doesn't even run the script without input.





                                                                                                                                        B. One could consider as falsy value for sed to be an unique string, i.e., returned only when the input is an empty string.



                                                                                                                                        Usage:



                                                                                                                                        echo ""|sed -f script


                                                                                                                                        Output:



                                                                                                                                        __




                                                                                                                                        I prefer the first interpretation so much more, as I believe it to be the closest to the intended rule, but the last one helps if you run the script using that TIO link.







                                                                                                                                        share|improve this answer












                                                                                                                                        share|improve this answer



                                                                                                                                        share|improve this answer










                                                                                                                                        answered Jun 8 at 17:16









                                                                                                                                        seshoumaraseshoumara

                                                                                                                                        2,8271 gold badge4 silver badges23 bronze badges




                                                                                                                                        2,8271 gold badge4 silver badges23 bronze badges























                                                                                                                                            0












                                                                                                                                            $begingroup$


                                                                                                                                            JavaScript (Babel Node), 45 bytes





                                                                                                                                            _=>_.match(/.{1,3}/g).map(a=>a.padEnd(3,`_`))


                                                                                                                                            Try it online!






                                                                                                                                            share|improve this answer









                                                                                                                                            $endgroup$













                                                                                                                                            • $begingroup$
                                                                                                                                              44
                                                                                                                                              $endgroup$
                                                                                                                                              – Shaggy
                                                                                                                                              May 19 at 15:13










                                                                                                                                            • $begingroup$
                                                                                                                                              Doesn't work for me
                                                                                                                                              $endgroup$
                                                                                                                                              – VFDan
                                                                                                                                              May 22 at 21:55
















                                                                                                                                            0












                                                                                                                                            $begingroup$


                                                                                                                                            JavaScript (Babel Node), 45 bytes





                                                                                                                                            _=>_.match(/.{1,3}/g).map(a=>a.padEnd(3,`_`))


                                                                                                                                            Try it online!






                                                                                                                                            share|improve this answer









                                                                                                                                            $endgroup$













                                                                                                                                            • $begingroup$
                                                                                                                                              44
                                                                                                                                              $endgroup$
                                                                                                                                              – Shaggy
                                                                                                                                              May 19 at 15:13










                                                                                                                                            • $begingroup$
                                                                                                                                              Doesn't work for me
                                                                                                                                              $endgroup$
                                                                                                                                              – VFDan
                                                                                                                                              May 22 at 21:55














                                                                                                                                            0












                                                                                                                                            0








                                                                                                                                            0





                                                                                                                                            $begingroup$


                                                                                                                                            JavaScript (Babel Node), 45 bytes





                                                                                                                                            _=>_.match(/.{1,3}/g).map(a=>a.padEnd(3,`_`))


                                                                                                                                            Try it online!






                                                                                                                                            share|improve this answer









                                                                                                                                            $endgroup$




                                                                                                                                            JavaScript (Babel Node), 45 bytes





                                                                                                                                            _=>_.match(/.{1,3}/g).map(a=>a.padEnd(3,`_`))


                                                                                                                                            Try it online!







                                                                                                                                            share|improve this answer












                                                                                                                                            share|improve this answer



                                                                                                                                            share|improve this answer










                                                                                                                                            answered May 19 at 15:02









                                                                                                                                            Luis felipe De jesus MunozLuis felipe De jesus Munoz

                                                                                                                                            6,5262 gold badges18 silver badges74 bronze badges




                                                                                                                                            6,5262 gold badges18 silver badges74 bronze badges












                                                                                                                                            • $begingroup$
                                                                                                                                              44
                                                                                                                                              $endgroup$
                                                                                                                                              – Shaggy
                                                                                                                                              May 19 at 15:13










                                                                                                                                            • $begingroup$
                                                                                                                                              Doesn't work for me
                                                                                                                                              $endgroup$
                                                                                                                                              – VFDan
                                                                                                                                              May 22 at 21:55


















                                                                                                                                            • $begingroup$
                                                                                                                                              44
                                                                                                                                              $endgroup$
                                                                                                                                              – Shaggy
                                                                                                                                              May 19 at 15:13










                                                                                                                                            • $begingroup$
                                                                                                                                              Doesn't work for me
                                                                                                                                              $endgroup$
                                                                                                                                              – VFDan
                                                                                                                                              May 22 at 21:55
















                                                                                                                                            $begingroup$
                                                                                                                                            44
                                                                                                                                            $endgroup$
                                                                                                                                            – Shaggy
                                                                                                                                            May 19 at 15:13




                                                                                                                                            $begingroup$
                                                                                                                                            44
                                                                                                                                            $endgroup$
                                                                                                                                            – Shaggy
                                                                                                                                            May 19 at 15:13












                                                                                                                                            $begingroup$
                                                                                                                                            Doesn't work for me
                                                                                                                                            $endgroup$
                                                                                                                                            – VFDan
                                                                                                                                            May 22 at 21:55




                                                                                                                                            $begingroup$
                                                                                                                                            Doesn't work for me
                                                                                                                                            $endgroup$
                                                                                                                                            – VFDan
                                                                                                                                            May 22 at 21:55











                                                                                                                                            0












                                                                                                                                            $begingroup$


                                                                                                                                            Jelly, 10 bytes



                                                                                                                                            s3;€⁾__ḣ€3


                                                                                                                                            Try it online!



                                                                                                                                            It feels like an 8 or 9 should be possible, but haven’t found one yet.






                                                                                                                                            share|improve this answer









                                                                                                                                            $endgroup$


















                                                                                                                                              0












                                                                                                                                              $begingroup$


                                                                                                                                              Jelly, 10 bytes



                                                                                                                                              s3;€⁾__ḣ€3


                                                                                                                                              Try it online!



                                                                                                                                              It feels like an 8 or 9 should be possible, but haven’t found one yet.






                                                                                                                                              share|improve this answer









                                                                                                                                              $endgroup$
















                                                                                                                                                0












                                                                                                                                                0








                                                                                                                                                0





                                                                                                                                                $begingroup$


                                                                                                                                                Jelly, 10 bytes



                                                                                                                                                s3;€⁾__ḣ€3


                                                                                                                                                Try it online!



                                                                                                                                                It feels like an 8 or 9 should be possible, but haven’t found one yet.






                                                                                                                                                share|improve this answer









                                                                                                                                                $endgroup$




                                                                                                                                                Jelly, 10 bytes



                                                                                                                                                s3;€⁾__ḣ€3


                                                                                                                                                Try it online!



                                                                                                                                                It feels like an 8 or 9 should be possible, but haven’t found one yet.







                                                                                                                                                share|improve this answer












                                                                                                                                                share|improve this answer



                                                                                                                                                share|improve this answer










                                                                                                                                                answered May 19 at 16:36









                                                                                                                                                Nick KennedyNick Kennedy

                                                                                                                                                4,9149 silver badges14 bronze badges




                                                                                                                                                4,9149 silver badges14 bronze badges























                                                                                                                                                    0












                                                                                                                                                    $begingroup$


                                                                                                                                                    Attache, 34 23 bytes



                                                                                                                                                    PadRight&"_"&3=>@Chop&3


                                                                                                                                                    Try it online!



                                                                                                                                                    Explanation (outdated)



                                                                                                                                                    {On[#_-1,PadRight&"_"&3,_]}@Chop&3
                                                                                                                                                    @Chop&3 chop the input string into groups of 3s
                                                                                                                                                    {On[#_-1 ,_]} on the last group
                                                                                                                                                    ,PadRight pad it
                                                                                                                                                    &3 to length three
                                                                                                                                                    &"_" with underscores





                                                                                                                                                    share|improve this answer











                                                                                                                                                    $endgroup$













                                                                                                                                                    • $begingroup$
                                                                                                                                                      Would you save anything by padding all the elements instead of just the last one?
                                                                                                                                                      $endgroup$
                                                                                                                                                      – Shaggy
                                                                                                                                                      May 19 at 20:18










                                                                                                                                                    • $begingroup$
                                                                                                                                                      @Shaggy Good point! I’ll look into it
                                                                                                                                                      $endgroup$
                                                                                                                                                      – Conor O'Brien
                                                                                                                                                      May 19 at 20:19
















                                                                                                                                                    0












                                                                                                                                                    $begingroup$


                                                                                                                                                    Attache, 34 23 bytes



                                                                                                                                                    PadRight&"_"&3=>@Chop&3


                                                                                                                                                    Try it online!



                                                                                                                                                    Explanation (outdated)



                                                                                                                                                    {On[#_-1,PadRight&"_"&3,_]}@Chop&3
                                                                                                                                                    @Chop&3 chop the input string into groups of 3s
                                                                                                                                                    {On[#_-1 ,_]} on the last group
                                                                                                                                                    ,PadRight pad it
                                                                                                                                                    &3 to length three
                                                                                                                                                    &"_" with underscores





                                                                                                                                                    share|improve this answer











                                                                                                                                                    $endgroup$













                                                                                                                                                    • $begingroup$
                                                                                                                                                      Would you save anything by padding all the elements instead of just the last one?
                                                                                                                                                      $endgroup$
                                                                                                                                                      – Shaggy
                                                                                                                                                      May 19 at 20:18










                                                                                                                                                    • $begingroup$
                                                                                                                                                      @Shaggy Good point! I’ll look into it
                                                                                                                                                      $endgroup$
                                                                                                                                                      – Conor O'Brien
                                                                                                                                                      May 19 at 20:19














                                                                                                                                                    0












                                                                                                                                                    0








                                                                                                                                                    0





                                                                                                                                                    $begingroup$


                                                                                                                                                    Attache, 34 23 bytes



                                                                                                                                                    PadRight&"_"&3=>@Chop&3


                                                                                                                                                    Try it online!



                                                                                                                                                    Explanation (outdated)



                                                                                                                                                    {On[#_-1,PadRight&"_"&3,_]}@Chop&3
                                                                                                                                                    @Chop&3 chop the input string into groups of 3s
                                                                                                                                                    {On[#_-1 ,_]} on the last group
                                                                                                                                                    ,PadRight pad it
                                                                                                                                                    &3 to length three
                                                                                                                                                    &"_" with underscores





                                                                                                                                                    share|improve this answer











                                                                                                                                                    $endgroup$




                                                                                                                                                    Attache, 34 23 bytes



                                                                                                                                                    PadRight&"_"&3=>@Chop&3


                                                                                                                                                    Try it online!



                                                                                                                                                    Explanation (outdated)



                                                                                                                                                    {On[#_-1,PadRight&"_"&3,_]}@Chop&3
                                                                                                                                                    @Chop&3 chop the input string into groups of 3s
                                                                                                                                                    {On[#_-1 ,_]} on the last group
                                                                                                                                                    ,PadRight pad it
                                                                                                                                                    &3 to length three
                                                                                                                                                    &"_" with underscores






                                                                                                                                                    share|improve this answer














                                                                                                                                                    share|improve this answer



                                                                                                                                                    share|improve this answer








                                                                                                                                                    edited May 19 at 22:18

























                                                                                                                                                    answered May 19 at 19:47









                                                                                                                                                    Conor O'BrienConor O'Brien

                                                                                                                                                    31.1k2 gold badges66 silver badges162 bronze badges




                                                                                                                                                    31.1k2 gold badges66 silver badges162 bronze badges












                                                                                                                                                    • $begingroup$
                                                                                                                                                      Would you save anything by padding all the elements instead of just the last one?
                                                                                                                                                      $endgroup$
                                                                                                                                                      – Shaggy
                                                                                                                                                      May 19 at 20:18










                                                                                                                                                    • $begingroup$
                                                                                                                                                      @Shaggy Good point! I’ll look into it
                                                                                                                                                      $endgroup$
                                                                                                                                                      – Conor O'Brien
                                                                                                                                                      May 19 at 20:19


















                                                                                                                                                    • $begingroup$
                                                                                                                                                      Would you save anything by padding all the elements instead of just the last one?
                                                                                                                                                      $endgroup$
                                                                                                                                                      – Shaggy
                                                                                                                                                      May 19 at 20:18










                                                                                                                                                    • $begingroup$
                                                                                                                                                      @Shaggy Good point! I’ll look into it
                                                                                                                                                      $endgroup$
                                                                                                                                                      – Conor O'Brien
                                                                                                                                                      May 19 at 20:19
















                                                                                                                                                    $begingroup$
                                                                                                                                                    Would you save anything by padding all the elements instead of just the last one?
                                                                                                                                                    $endgroup$
                                                                                                                                                    – Shaggy
                                                                                                                                                    May 19 at 20:18




                                                                                                                                                    $begingroup$
                                                                                                                                                    Would you save anything by padding all the elements instead of just the last one?
                                                                                                                                                    $endgroup$
                                                                                                                                                    – Shaggy
                                                                                                                                                    May 19 at 20:18












                                                                                                                                                    $begingroup$
                                                                                                                                                    @Shaggy Good point! I’ll look into it
                                                                                                                                                    $endgroup$
                                                                                                                                                    – Conor O'Brien
                                                                                                                                                    May 19 at 20:19




                                                                                                                                                    $begingroup$
                                                                                                                                                    @Shaggy Good point! I’ll look into it
                                                                                                                                                    $endgroup$
                                                                                                                                                    – Conor O'Brien
                                                                                                                                                    May 19 at 20:19











                                                                                                                                                    0












                                                                                                                                                    $begingroup$


                                                                                                                                                    Charcoal, 10 bytes



                                                                                                                                                    E⪪S³…⁺ι__³


                                                                                                                                                    Try it online! Link is to verbose version of code. Explanation:



                                                                                                                                                      S         Input string
                                                                                                                                                    ⪪ ³ Split into groups of up to 3 characters
                                                                                                                                                    E Map over each group
                                                                                                                                                    ι Current group
                                                                                                                                                    ⁺ Concatenated with
                                                                                                                                                    __ Literal `__`
                                                                                                                                                    … ³ Moulded to length 3
                                                                                                                                                    Each group implicitly printed on its own line





                                                                                                                                                    share|improve this answer









                                                                                                                                                    $endgroup$


















                                                                                                                                                      0












                                                                                                                                                      $begingroup$


                                                                                                                                                      Charcoal, 10 bytes



                                                                                                                                                      E⪪S³…⁺ι__³


                                                                                                                                                      Try it online! Link is to verbose version of code. Explanation:



                                                                                                                                                        S         Input string
                                                                                                                                                      ⪪ ³ Split into groups of up to 3 characters
                                                                                                                                                      E Map over each group
                                                                                                                                                      ι Current group
                                                                                                                                                      ⁺ Concatenated with
                                                                                                                                                      __ Literal `__`
                                                                                                                                                      … ³ Moulded to length 3
                                                                                                                                                      Each group implicitly printed on its own line





                                                                                                                                                      share|improve this answer









                                                                                                                                                      $endgroup$
















                                                                                                                                                        0












                                                                                                                                                        0








                                                                                                                                                        0





                                                                                                                                                        $begingroup$


                                                                                                                                                        Charcoal, 10 bytes



                                                                                                                                                        E⪪S³…⁺ι__³


                                                                                                                                                        Try it online! Link is to verbose version of code. Explanation:



                                                                                                                                                          S         Input string
                                                                                                                                                        ⪪ ³ Split into groups of up to 3 characters
                                                                                                                                                        E Map over each group
                                                                                                                                                        ι Current group
                                                                                                                                                        ⁺ Concatenated with
                                                                                                                                                        __ Literal `__`
                                                                                                                                                        … ³ Moulded to length 3
                                                                                                                                                        Each group implicitly printed on its own line





                                                                                                                                                        share|improve this answer









                                                                                                                                                        $endgroup$




                                                                                                                                                        Charcoal, 10 bytes



                                                                                                                                                        E⪪S³…⁺ι__³


                                                                                                                                                        Try it online! Link is to verbose version of code. Explanation:



                                                                                                                                                          S         Input string
                                                                                                                                                        ⪪ ³ Split into groups of up to 3 characters
                                                                                                                                                        E Map over each group
                                                                                                                                                        ι Current group
                                                                                                                                                        ⁺ Concatenated with
                                                                                                                                                        __ Literal `__`
                                                                                                                                                        … ³ Moulded to length 3
                                                                                                                                                        Each group implicitly printed on its own line






                                                                                                                                                        share|improve this answer












                                                                                                                                                        share|improve this answer



                                                                                                                                                        share|improve this answer










                                                                                                                                                        answered May 19 at 22:31









                                                                                                                                                        NeilNeil

                                                                                                                                                        86.3k8 gold badges46 silver badges183 bronze badges




                                                                                                                                                        86.3k8 gold badges46 silver badges183 bronze badges























                                                                                                                                                            0












                                                                                                                                                            $begingroup$


                                                                                                                                                            Scala, 31 bytes





                                                                                                                                                            (s+"___").grouped(3).toSeq.init


                                                                                                                                                            Try it online!



                                                                                                                                                            Explanation



                                                                                                                                                            (s+"___")       // add "___"
                                                                                                                                                            .grouped(3) // make groups of 3
                                                                                                                                                            .toSeq // change to Seq
                                                                                                                                                            .init // take all but last





                                                                                                                                                            share|improve this answer











                                                                                                                                                            $endgroup$


















                                                                                                                                                              0












                                                                                                                                                              $begingroup$


                                                                                                                                                              Scala, 31 bytes





                                                                                                                                                              (s+"___").grouped(3).toSeq.init


                                                                                                                                                              Try it online!



                                                                                                                                                              Explanation



                                                                                                                                                              (s+"___")       // add "___"
                                                                                                                                                              .grouped(3) // make groups of 3
                                                                                                                                                              .toSeq // change to Seq
                                                                                                                                                              .init // take all but last





                                                                                                                                                              share|improve this answer











                                                                                                                                                              $endgroup$
















                                                                                                                                                                0












                                                                                                                                                                0








                                                                                                                                                                0





                                                                                                                                                                $begingroup$


                                                                                                                                                                Scala, 31 bytes





                                                                                                                                                                (s+"___").grouped(3).toSeq.init


                                                                                                                                                                Try it online!



                                                                                                                                                                Explanation



                                                                                                                                                                (s+"___")       // add "___"
                                                                                                                                                                .grouped(3) // make groups of 3
                                                                                                                                                                .toSeq // change to Seq
                                                                                                                                                                .init // take all but last





                                                                                                                                                                share|improve this answer











                                                                                                                                                                $endgroup$




                                                                                                                                                                Scala, 31 bytes





                                                                                                                                                                (s+"___").grouped(3).toSeq.init


                                                                                                                                                                Try it online!



                                                                                                                                                                Explanation



                                                                                                                                                                (s+"___")       // add "___"
                                                                                                                                                                .grouped(3) // make groups of 3
                                                                                                                                                                .toSeq // change to Seq
                                                                                                                                                                .init // take all but last






                                                                                                                                                                share|improve this answer














                                                                                                                                                                share|improve this answer



                                                                                                                                                                share|improve this answer








                                                                                                                                                                edited May 20 at 12:46

























                                                                                                                                                                answered May 20 at 11:04









                                                                                                                                                                pmepme

                                                                                                                                                                1114 bronze badges




                                                                                                                                                                1114 bronze badges























                                                                                                                                                                    0












                                                                                                                                                                    $begingroup$


                                                                                                                                                                    Befunge-93, 30 29 bytes



                                                                                                                                                                    ~:1+%,~:1+!"`"*+,~:1+!"`"*+,,


                                                                                                                                                                    Try it online!



                                                                                                                                                                    Outputs nothing for an empty input, otherwise outputs strings of length 3 separated by NUL characters.



                                                                                                                                                                    Explanation:




                                                                                                                                                                    ~ Push character of input to stack
                                                                                                                                                                    :1+ Duplicate input and add 1
                                                                                                                                                                    % Modulo top 2 values of stack and push result
                                                                                                                                                                    If input was -1 (end of stream), calculate -1%0 -> halt
                                                                                                                                                                    Otherwise calculate input%(input+1) -> input
                                                                                                                                                                    , Pop and output character
                                                                                                                                                                    ~ Push character of input to stack
                                                                                                                                                                    :1+! Duplicate input, add 1 and perform logical NOT
                                                                                                                                                                    "`"* Multiply by 96 (ASCII code for '`')
                                                                                                                                                                    This returns 96 or 0 depending on the result of the NOT
                                                                                                                                                                    + Add the top 2 values from the stack and push the result
                                                                                                                                                                    If the input was -1 (end of stream), pushes -1+96=95, or the ASCII code for '_'
                                                                                                                                                                    Otherwise pushes input+0
                                                                                                                                                                    , Pop and output character
                                                                                                                                                                    ~:1+!"`"*+, Same block again to handle the third character
                                                                                                                                                                    , Output a NUL character (stack is empty, so popping from stack just returns 0)

                                                                                                                                                                    The instruction pointer wraps around at the end, looping the entire line.





                                                                                                                                                                    share|improve this answer











                                                                                                                                                                    $endgroup$


















                                                                                                                                                                      0












                                                                                                                                                                      $begingroup$


                                                                                                                                                                      Befunge-93, 30 29 bytes



                                                                                                                                                                      ~:1+%,~:1+!"`"*+,~:1+!"`"*+,,


                                                                                                                                                                      Try it online!



                                                                                                                                                                      Outputs nothing for an empty input, otherwise outputs strings of length 3 separated by NUL characters.



                                                                                                                                                                      Explanation:




                                                                                                                                                                      ~ Push character of input to stack
                                                                                                                                                                      :1+ Duplicate input and add 1
                                                                                                                                                                      % Modulo top 2 values of stack and push result
                                                                                                                                                                      If input was -1 (end of stream), calculate -1%0 -> halt
                                                                                                                                                                      Otherwise calculate input%(input+1) -> input
                                                                                                                                                                      , Pop and output character
                                                                                                                                                                      ~ Push character of input to stack
                                                                                                                                                                      :1+! Duplicate input, add 1 and perform logical NOT
                                                                                                                                                                      "`"* Multiply by 96 (ASCII code for '`')
                                                                                                                                                                      This returns 96 or 0 depending on the result of the NOT
                                                                                                                                                                      + Add the top 2 values from the stack and push the result
                                                                                                                                                                      If the input was -1 (end of stream), pushes -1+96=95, or the ASCII code for '_'
                                                                                                                                                                      Otherwise pushes input+0
                                                                                                                                                                      , Pop and output character
                                                                                                                                                                      ~:1+!"`"*+, Same block again to handle the third character
                                                                                                                                                                      , Output a NUL character (stack is empty, so popping from stack just returns 0)

                                                                                                                                                                      The instruction pointer wraps around at the end, looping the entire line.





                                                                                                                                                                      share|improve this answer











                                                                                                                                                                      $endgroup$
















                                                                                                                                                                        0












                                                                                                                                                                        0








                                                                                                                                                                        0





                                                                                                                                                                        $begingroup$


                                                                                                                                                                        Befunge-93, 30 29 bytes



                                                                                                                                                                        ~:1+%,~:1+!"`"*+,~:1+!"`"*+,,


                                                                                                                                                                        Try it online!



                                                                                                                                                                        Outputs nothing for an empty input, otherwise outputs strings of length 3 separated by NUL characters.



                                                                                                                                                                        Explanation:




                                                                                                                                                                        ~ Push character of input to stack
                                                                                                                                                                        :1+ Duplicate input and add 1
                                                                                                                                                                        % Modulo top 2 values of stack and push result
                                                                                                                                                                        If input was -1 (end of stream), calculate -1%0 -> halt
                                                                                                                                                                        Otherwise calculate input%(input+1) -> input
                                                                                                                                                                        , Pop and output character
                                                                                                                                                                        ~ Push character of input to stack
                                                                                                                                                                        :1+! Duplicate input, add 1 and perform logical NOT
                                                                                                                                                                        "`"* Multiply by 96 (ASCII code for '`')
                                                                                                                                                                        This returns 96 or 0 depending on the result of the NOT
                                                                                                                                                                        + Add the top 2 values from the stack and push the result
                                                                                                                                                                        If the input was -1 (end of stream), pushes -1+96=95, or the ASCII code for '_'
                                                                                                                                                                        Otherwise pushes input+0
                                                                                                                                                                        , Pop and output character
                                                                                                                                                                        ~:1+!"`"*+, Same block again to handle the third character
                                                                                                                                                                        , Output a NUL character (stack is empty, so popping from stack just returns 0)

                                                                                                                                                                        The instruction pointer wraps around at the end, looping the entire line.





                                                                                                                                                                        share|improve this answer











                                                                                                                                                                        $endgroup$




                                                                                                                                                                        Befunge-93, 30 29 bytes



                                                                                                                                                                        ~:1+%,~:1+!"`"*+,~:1+!"`"*+,,


                                                                                                                                                                        Try it online!



                                                                                                                                                                        Outputs nothing for an empty input, otherwise outputs strings of length 3 separated by NUL characters.



                                                                                                                                                                        Explanation:




                                                                                                                                                                        ~ Push character of input to stack
                                                                                                                                                                        :1+ Duplicate input and add 1
                                                                                                                                                                        % Modulo top 2 values of stack and push result
                                                                                                                                                                        If input was -1 (end of stream), calculate -1%0 -> halt
                                                                                                                                                                        Otherwise calculate input%(input+1) -> input
                                                                                                                                                                        , Pop and output character
                                                                                                                                                                        ~ Push character of input to stack
                                                                                                                                                                        :1+! Duplicate input, add 1 and perform logical NOT
                                                                                                                                                                        "`"* Multiply by 96 (ASCII code for '`')
                                                                                                                                                                        This returns 96 or 0 depending on the result of the NOT
                                                                                                                                                                        + Add the top 2 values from the stack and push the result
                                                                                                                                                                        If the input was -1 (end of stream), pushes -1+96=95, or the ASCII code for '_'
                                                                                                                                                                        Otherwise pushes input+0
                                                                                                                                                                        , Pop and output character
                                                                                                                                                                        ~:1+!"`"*+, Same block again to handle the third character
                                                                                                                                                                        , Output a NUL character (stack is empty, so popping from stack just returns 0)

                                                                                                                                                                        The instruction pointer wraps around at the end, looping the entire line.






                                                                                                                                                                        share|improve this answer














                                                                                                                                                                        share|improve this answer



                                                                                                                                                                        share|improve this answer








                                                                                                                                                                        edited May 22 at 21:18

























                                                                                                                                                                        answered May 22 at 16:44









                                                                                                                                                                        negative sevennegative seven

                                                                                                                                                                        1,0353 silver badges11 bronze badges




                                                                                                                                                                        1,0353 silver badges11 bronze badges






















                                                                                                                                                                            1 2
                                                                                                                                                                            next

















                                                                                                                                                                            draft saved

                                                                                                                                                                            draft discarded




















































                                                                                                                                                                            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%2f185783%2fsplit-into-three%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

                                                                                                                                                                            Færeyskur hestur Heimild | Tengill | Tilvísanir | LeiðsagnarvalRossið - síða um færeyska hrossið á færeyskuGott ár hjá færeyska hestinum

                                                                                                                                                                            He _____ here since 1970 . Answer needed [closed]What does “since he was so high” mean?Meaning of “catch birds for”?How do I ensure “since” takes the meaning I want?“Who cares here” meaningWhat does “right round toward” mean?the time tense (had now been detected)What does the phrase “ring around the roses” mean here?Correct usage of “visited upon”Meaning of “foiled rail sabotage bid”It was the third time I had gone to Rome or It is the third time I had been to Rome

                                                                                                                                                                            Slayer Innehåll Historia | Stil, komposition och lyrik | Bandets betydelse och framgångar | Sidoprojekt och samarbeten | Kontroverser | Medlemmar | Utmärkelser och nomineringar | Turnéer och festivaler | Diskografi | Referenser | Externa länkar | Navigeringsmenywww.slayer.net”Metal Massacre vol. 1””Metal Massacre vol. 3””Metal Massacre Volume III””Show No Mercy””Haunting the Chapel””Live Undead””Hell Awaits””Reign in Blood””Reign in Blood””Gold & Platinum – Reign in Blood””Golden Gods Awards Winners”originalet”Kerrang! Hall Of Fame””Slayer Looks Back On 37-Year Career In New Video Series: Part Two””South of Heaven””Gold & Platinum – South of Heaven””Seasons in the Abyss””Gold & Platinum - Seasons in the Abyss””Divine Intervention””Divine Intervention - Release group by Slayer””Gold & Platinum - Divine Intervention””Live Intrusion””Undisputed Attitude””Abolish Government/Superficial Love””Release “Slatanic Slaughter: A Tribute to Slayer” by Various Artists””Diabolus in Musica””Soundtrack to the Apocalypse””God Hates Us All””Systematic - Relationships””War at the Warfield””Gold & Platinum - War at the Warfield””Soundtrack to the Apocalypse””Gold & Platinum - Still Reigning””Metallica, Slayer, Iron Mauden Among Winners At Metal Hammer Awards””Eternal Pyre””Eternal Pyre - Slayer release group””Eternal Pyre””Metal Storm Awards 2006””Kerrang! Hall Of Fame””Slayer Wins 'Best Metal' Grammy Award””Slayer Guitarist Jeff Hanneman Dies””Bullet-For My Valentine booed at Metal Hammer Golden Gods Awards””Unholy Aliance””The End Of Slayer?””Slayer: We Could Thrash Out Two More Albums If We're Fast Enough...””'The Unholy Alliance: Chapter III' UK Dates Added”originalet”Megadeth And Slayer To Co-Headline 'Canadian Carnage' Trek”originalet”World Painted Blood””Release “World Painted Blood” by Slayer””Metallica Heading To Cinemas””Slayer, Megadeth To Join Forces For 'European Carnage' Tour - Dec. 18, 2010”originalet”Slayer's Hanneman Contracts Acute Infection; Band To Bring In Guest Guitarist””Cannibal Corpse's Pat O'Brien Will Step In As Slayer's Guest Guitarist”originalet”Slayer’s Jeff Hanneman Dead at 49””Dave Lombardo Says He Made Only $67,000 In 2011 While Touring With Slayer””Slayer: We Do Not Agree With Dave Lombardo's Substance Or Timeline Of Events””Slayer Welcomes Drummer Paul Bostaph Back To The Fold””Slayer Hope to Unveil Never-Before-Heard Jeff Hanneman Material on Next Album””Slayer Debut New Song 'Implode' During Surprise Golden Gods Appearance””Release group Repentless by Slayer””Repentless - Slayer - Credits””Slayer””Metal Storm Awards 2015””Slayer - to release comic book "Repentless #1"””Slayer To Release 'Repentless' 6.66" Vinyl Box Set””BREAKING NEWS: Slayer Announce Farewell Tour””Slayer Recruit Lamb of God, Anthrax, Behemoth + Testament for Final Tour””Slayer lägger ner efter 37 år””Slayer Announces Second North American Leg Of 'Final' Tour””Final World Tour””Slayer Announces Final European Tour With Lamb of God, Anthrax And Obituary””Slayer To Tour Europe With Lamb of God, Anthrax And Obituary””Slayer To Play 'Last French Show Ever' At Next Year's Hellfst””Slayer's Final World Tour Will Extend Into 2019””Death Angel's Rob Cavestany On Slayer's 'Farewell' Tour: 'Some Of Us Could See This Coming'””Testament Has No Plans To Retire Anytime Soon, Says Chuck Billy””Anthrax's Scott Ian On Slayer's 'Farewell' Tour Plans: 'I Was Surprised And I Wasn't Surprised'””Slayer””Slayer's Morbid Schlock””Review/Rock; For Slayer, the Mania Is the Message””Slayer - Biography””Slayer - Reign In Blood”originalet”Dave Lombardo””An exclusive oral history of Slayer”originalet”Exclusive! Interview With Slayer Guitarist Jeff Hanneman”originalet”Thinking Out Loud: Slayer's Kerry King on hair metal, Satan and being polite””Slayer Lyrics””Slayer - Biography””Most influential artists for extreme metal music””Slayer - Reign in Blood””Slayer guitarist Jeff Hanneman dies aged 49””Slatanic Slaughter: A Tribute to Slayer””Gateway to Hell: A Tribute to Slayer””Covered In Blood””Slayer: The Origins of Thrash in San Francisco, CA.””Why They Rule - #6 Slayer”originalet”Guitar World's 100 Greatest Heavy Metal Guitarists Of All Time”originalet”The fans have spoken: Slayer comes out on top in readers' polls”originalet”Tribute to Jeff Hanneman (1964-2013)””Lamb Of God Frontman: We Sound Like A Slayer Rip-Off””BEHEMOTH Frontman Pays Tribute To SLAYER's JEFF HANNEMAN””Slayer, Hatebreed Doing Double Duty On This Year's Ozzfest””System of a Down””Lacuna Coil’s Andrea Ferro Talks Influences, Skateboarding, Band Origins + More””Slayer - Reign in Blood””Into The Lungs of Hell””Slayer rules - en utställning om fans””Slayer and Their Fans Slashed Through a No-Holds-Barred Night at Gas Monkey””Home””Slayer””Gold & Platinum - The Big 4 Live from Sofia, Bulgaria””Exclusive! Interview With Slayer Guitarist Kerry King””2008-02-23: Wiltern, Los Angeles, CA, USA””Slayer's Kerry King To Perform With Megadeth Tonight! - Oct. 21, 2010”originalet”Dave Lombardo - Biography”Slayer Case DismissedArkiveradUltimate Classic Rock: Slayer guitarist Jeff Hanneman dead at 49.”Slayer: "We could never do any thing like Some Kind Of Monster..."””Cannibal Corpse'S Pat O'Brien Will Step In As Slayer'S Guest Guitarist | The Official Slayer Site”originalet”Slayer Wins 'Best Metal' Grammy Award””Slayer Guitarist Jeff Hanneman Dies””Kerrang! Awards 2006 Blog: Kerrang! Hall Of Fame””Kerrang! Awards 2013: Kerrang! Legend”originalet”Metallica, Slayer, Iron Maien Among Winners At Metal Hammer Awards””Metal Hammer Golden Gods Awards””Bullet For My Valentine Booed At Metal Hammer Golden Gods Awards””Metal Storm Awards 2006””Metal Storm Awards 2015””Slayer's Concert History””Slayer - Relationships””Slayer - Releases”Slayers officiella webbplatsSlayer på MusicBrainzOfficiell webbplatsSlayerSlayerr1373445760000 0001 1540 47353068615-5086262726cb13906545x(data)6033143kn20030215029