11
\$\begingroup\$

Write a program in the minimum number of bytes that prints a string split into chunks of every length from 1 to the string's length (ascending and then descending), separated by spaces.

Example

Input : abcdef
Output: a b c d e f
        ab cd ef
        abc def
        abcd ef
        abcde f
        abcdef
        abcde f
        abcd ef
        abc def
        ab cd ef
        a b c d e f
\$\endgroup\$
1
  • 1
    \$\begingroup\$ Why were the tags fastest-code and functional-programming added? The former conflicts with the winning condition given already (which is shortest code) and the latter doesn't apply terribly much... \$\endgroup\$
    – FireFly
    Feb 12, 2014 at 22:40

23 Answers 23

6
\$\begingroup\$

Ruby, 84 81 characters

i=gets.chop
puts (a=(1..i.size).map{|n|i.scan(/.{0,#{n}}/)*' '})+a.reverse[1..-1]

The magic is in the regex: i.scan(/.{0,#{n}}/). Since Ruby does regex interpolation too, it will become

i.scan(/.{0,1}/)
i.scan(/.{0,2}/)
...

This means it will grab as many characters as it can, limited to n. n progressively gets bigger, and is used to generate the first half of the output.

Then I just call reverse to generate the second half. I had to use [1..-1] in order to avoid repeating the middle line (what that does is basically chop off the first element of the array).

Sample run:

c:\a\ruby>spacesplitgolf.rb
CodeGolfStackExchange         // (this is the input)
C o d e G o l f S t a c k E x c h a n g e
Co de Go lf St ac kE xc ha ng e
Cod eGo lfS tac kEx cha nge
Code Golf Stac kExc hang e
CodeG olfSt ackEx chang e
CodeGo lfStac kExcha nge
CodeGol fStackE xchange
CodeGolf StackExc hange
CodeGolfS tackExcha nge
CodeGolfSt ackExchang e
CodeGolfSta ckExchange
CodeGolfStac kExchange
CodeGolfStack Exchange
CodeGolfStackE xchange
CodeGolfStackEx change
CodeGolfStackExc hange
CodeGolfStackExch ange
CodeGolfStackExcha nge
CodeGolfStackExchan ge
CodeGolfStackExchang e
CodeGolfStackExchange
CodeGolfStackExchang e
CodeGolfStackExchan ge
CodeGolfStackExcha nge
CodeGolfStackExch ange
CodeGolfStackExc hange
CodeGolfStackEx change
CodeGolfStackE xchange
CodeGolfStack Exchange
CodeGolfStac kExchange
CodeGolfSta ckExchange
CodeGolfSt ackExchang e
CodeGolfS tackExcha nge
CodeGolf StackExc hange
CodeGol fStackE xchange
CodeGo lfStac kExcha nge
CodeG olfSt ackEx chang e
Code Golf Stac kExc hang e
Cod eGo lfS tac kEx cha nge
Co de Go lf St ac kE xc ha ng e
C o d e G o l f S t a c k E x c h a n g e
\$\endgroup\$
3
  • \$\begingroup\$ 4th line contain single and double string Co de G ol f St ac k Ex ch an ge-this is not correct...correct is Co de Go lf St ac kE xc ha ng e \$\endgroup\$
    – learner
    Feb 11, 2014 at 13:12
  • \$\begingroup\$ @Boopathi That's because the spaces in the string count as letters too... I've edited the example to use an input with no spaces. \$\endgroup\$
    – Doorknob
    Feb 11, 2014 at 13:15
  • \$\begingroup\$ 70 bytes, or 66 using newer Ruby features. \$\endgroup\$
    – Jordan
    Oct 14, 2022 at 23:31
4
\$\begingroup\$

GolfScript, 22 characters

:I,,{)I/' '*n+}%.-1%1>

Try the example here.

> abcdef
a b c d e f
ab cd ef
abc def
abcd ef
abcde f
abcdef
abcde f
abcd ef
abc def
ab cd ef
a b c d e f

Code explained:

:I          # Save input to variable I
,,          # Create array [0..n)
{
  )         # Increment loop variable by 1
  I/        # Split input into chunks with as many characters
  ' '*      # Join with spaces
  n+        # Append newline
}%
.-1%1>      # Create reverse copy (minus first element)
\$\endgroup\$
1
  • \$\begingroup\$ You can save a byte if you remove the + and use 3> instead of 1>. \$\endgroup\$ Feb 22, 2015 at 19:35
4
\$\begingroup\$

Smalltalk (Smalltalk/X) (137 chars)

s := Stdin nextLine.
(1 to:s size),(s size-1 downTo:1) do:[:n |
 ((s asCollectionOfSubCollectionsOfSize:n) asStringWith:' ') printNL] 

output (first line is input):

abcdef
a b c d e f
ab cd ef
abc def
abcd ef
abcde f
abcdef
abcde f
abcd ef
abc def
ab cd ef
a b c d e f
\$\endgroup\$
2
  • 1
    \$\begingroup\$ That is quite an impressive score when it includes identifiers such as asCollectionOfSubCollectionsOfSize... \$\endgroup\$
    – FireFly
    Feb 12, 2014 at 22:42
  • \$\begingroup\$ that's right, smalltalk was designed to be more readable than writable - bad for this kind of contest... \$\endgroup\$
    – blabla999
    Feb 13, 2014 at 17:44
3
\$\begingroup\$

J - 32 27 char

Thanks to randomra for improvements.

(,&' '\(,@)"{~#-~|@i:@<:@#)

Explained:

  • <:@# - One less than the length of the string.
  • |@i: - Count from that number down to 0, then back up to that number. (J has weird primitives!)
  • #-~ - Subtract from each of those numbers the length. When you do the math, the result is that you count from -1 to the negation of the length and back up.
  • u\(,@)"{~ - For each negative integer, apply the verb u on non-overlapping infixes of the string, with length the negative of the integer, and then run it into a single string. So e.g. for _2 it will split the string up into non-overlapping pairs of letters, apply u, then make a string back of all the new infixes.
  • ,&' ' - Append a space. (This fills in u above.)

Usage:

   (,&' '\(,@)"{~#-~|@i:@<:@#) 'abcdef'
a b c d e f
ab cd ef
abc def
abcd ef
abcde f
abcdef
abcde f
abcd ef
abc def
ab cd ef
a b c d e f
\$\endgroup\$
2
  • \$\begingroup\$ (,&' '\(,@)"{~(-~|@i:@<:)@#) saves a total of 4 bytes. I improved an algorithmshark solution by several bytes! Yay! \$\endgroup\$
    – randomra
    Feb 22, 2015 at 12:40
  • \$\begingroup\$ @randomra (,&' '\(,@)"{~#-~|@i:@<:@#) for one more ;) \$\endgroup\$ Feb 22, 2015 at 16:00
2
\$\begingroup\$

Python 94 (bit verbose, but that;s Python)

s=raw_input();print'\n'.join(' '.join(map(''.join,zip(*[iter(s)]*n)))for n in range(1,len(s)))
\$\endgroup\$
2
\$\begingroup\$

Delphi XE3 - WayToMany characters (WayToMany==321 261 245)

Im sure I can get this shorter so consider this as Work In Progress ^.^

Edits:
Removed use of array making 2 units redundant saving a total of 61 chars
Removed useless begin..end for loop saving 16 chars

{$APPTYPE CONSOLE}uses idglobal;var i,st:int16;s,r:string;p:boolean;begin readln(s);st:=1;p:=true;repeat r:='';for I:=1to Length(s)do r:=r+iif(i mod st=0,s[i]+' ',s[i]);writeln(r);if st=length(s)then p:=false;st:=iif(p,st+1,st-1);until st<1;end.

With indent

{$APPTYPE CONSOLE}
uses idglobal;
var
i,st:int16;
s,r:string;
p:boolean;
begin
readln(s);
st:=1;
p:=true;
repeat
  r:='';
  for I:=1to Length(s)do
    r:=r+iif(i mod st=0,s[i]+' ',s[i]);
  writeln(r);
  if st=length(s)then
    p:=false;
  st:=iif(p,st+1,st-1);
until st<1;
end.

Result: (first line is input) enter image description here

\$\endgroup\$
2
\$\begingroup\$

Rebol (144 chars)

s: input o:[]repeat i(length? s) - 1[t: copy s forskip t i + 1[insert t" "]append o next t]append o reverse append copy o s forall o[print o/1]


Un-golfed:

s: input
o: []

repeat i (length? s) - 1 [
    t: copy s
    forskip t i + 1 [insert t " "]
    append o next t
]

append o reverse append copy o s

forall o [print o/1]


Usage example:

rebol script.reb <<< "abcdef"
a b c d e f
ab cd ef
abc def
abcd ef
abcde f
abcdef
abcde f
abcd ef
abc def
ab cd ef
a b c d e f
\$\endgroup\$
2
\$\begingroup\$

R, 95

x=scan(,"");z=1:nchar(x);for(i in c(z,rev(z)[-1]))cat(gsub(paste0("(.{",i,"})"),"\\1 ",x),"\n")

(based on regular expressions)

Example:

> x=scan(,"");z=1:nchar(x);for(i in c(z,rev(z)[-1]))cat(gsub(paste0("(.{",i,"})"),"\\1 ",x),"\n")
1: abcdef
2: 
Read 1 item
a b c d e f  
ab cd ef  
abc def  
abcd ef 
abcde f 
abcdef  
abcde f 
abcd ef 
abc def  
ab cd ef  
a b c d e f  
\$\endgroup\$
2
\$\begingroup\$

JavaScript - 242

I'm new to CodeGolf (and JS as well) and this is my first try. Any suggestions are welcome :)

function f(s){var i,j,a=s.split(''),t;for(i=1;i<=a.length;i++){t='';for(j=1;j<=a.length;j++){t+=a[j-1];if(j%i==0)t+=' ';}
console.log(t);}
for(i=a.length;i>0;i--){t='';for(j=1;j<=a.length;j++){t+=a[j-1];if(j%i==0)t+=' ';}
console.log(t);}}

Example:

>>> f('CodeGolfIsAwesome');

C o d e G o l f I s A w e s o m e
Co de Go lf Is Aw es om e
Cod eGo lfI sAw eso me
Code Golf IsAw esom e
CodeG olfIs Aweso me
CodeGo lfIsAw esome
CodeGol fIsAwes ome
CodeGolf IsAwesom e
CodeGolfI sAwesome
CodeGolfIs Awesome
CodeGolfIsA wesome
CodeGolfIsAw esome
CodeGolfIsAwe some
CodeGolfIsAwes ome
CodeGolfIsAweso me
CodeGolfIsAwesom e
CodeGolfIsAwesome
CodeGolfIsAwesom e
CodeGolfIsAweso me
CodeGolfIsAwes ome
CodeGolfIsAwe some
CodeGolfIsAw esome
CodeGolfIsA wesome
CodeGolfIs Awesome
CodeGolfI sAwesome
CodeGolf IsAwesom e
CodeGol fIsAwes ome
CodeGo lfIsAw esome
CodeG olfIs Aweso me
Code Golf IsAw esom e
Cod eGo lfI sAw eso me
Co de Go lf Is Aw es om e
C o d e G o l f I s A w e s o m e 
\$\endgroup\$
2
\$\begingroup\$

Perl, 77 71

Better late, than never (and since so far no Perl solution):

chomp($s=<>);say$s=~s/.{$_}/$& /gr for@a=1..length$s,reverse@a[[email protected]]

Requires 5.014 because of r modifier. Uses 'say' feature. And

echo CodeGolfStackExchange| perl -M5.010 spaces.pl
C o d e G o l f S t a c k E x c h a n g e
Co de Go lf St ac kE xc ha ng e
Cod eGo lfS tac kEx cha nge
Code Golf Stac kExc hang e
CodeG olfSt ackEx chang e
CodeGo lfStac kExcha nge
CodeGol fStackE xchange
CodeGolf StackExc hange
CodeGolfS tackExcha nge
CodeGolfSt ackExchang e
CodeGolfSta ckExchange
CodeGolfStac kExchange
CodeGolfStack Exchange
CodeGolfStackE xchange
CodeGolfStackEx change
CodeGolfStackExc hange
CodeGolfStackExch ange
CodeGolfStackExcha nge
CodeGolfStackExchan ge
CodeGolfStackExchang e
CodeGolfStackExchange
CodeGolfStackExchang e
CodeGolfStackExchan ge
CodeGolfStackExcha nge
CodeGolfStackExch ange
CodeGolfStackExc hange
CodeGolfStackEx change
CodeGolfStackE xchange
CodeGolfStack Exchange
CodeGolfStac kExchange
CodeGolfSta ckExchange
CodeGolfSt ackExchang e
CodeGolfS tackExcha nge
CodeGolf StackExc hange
CodeGol fStackE xchange
CodeGo lfStac kExcha nge
CodeG olfSt ackEx chang e
Code Golf Stac kExc hang e
Cod eGo lfS tac kEx cha nge
Co de Go lf St ac kE xc ha ng e
C o d e G o l f S t a c k E x c h a n g e
\$\endgroup\$
2
\$\begingroup\$

CJam, 20 19 18 bytes

Not a valid entry as CJam was created sometime after this question and moreover, this code is using some of the even newer features of the language.

q:Q,{)Q/S*N}%_W%3>

1 byte saved thanks to Martin.

Explanation:

q:Q,                   "Read the input, store it in Q and take its length";
    {      }%          "Map over 0 to length - 1";
     )Q/               "Increment iterator and split Q into pieces of length iterator";
        S*N            "Join by space and add new line";
              _W%      "Copy the mapped string array and reverse it";
                 3>    "Remove the first 3 elements, which comprise of 2 new lines and";
                       "the original string which should appear once only";

Example input:

CodeGolfStackExchange

Output:

C o d e G o l f S t a c k E x c h a n g e
Co de Go lf St ac kE xc ha ng e
Cod eGo lfS tac kEx cha nge
Code Golf Stac kExc hang e
CodeG olfSt ackEx chang e
CodeGo lfStac kExcha nge
CodeGol fStackE xchange
CodeGolf StackExc hange
CodeGolfS tackExcha nge
CodeGolfSt ackExchang e
CodeGolfSta ckExchange
CodeGolfStac kExchange
CodeGolfStack Exchange
CodeGolfStackE xchange
CodeGolfStackEx change
CodeGolfStackExc hange
CodeGolfStackExch ange
CodeGolfStackExcha nge
CodeGolfStackExchan ge
CodeGolfStackExchang e
CodeGolfStackExchange
CodeGolfStackExchang e
CodeGolfStackExchan ge
CodeGolfStackExcha nge
CodeGolfStackExch ange
CodeGolfStackExc hange
CodeGolfStackEx change
CodeGolfStackE xchange
CodeGolfStack Exchange
CodeGolfStac kExchange
CodeGolfSta ckExchange
CodeGolfSt ackExchang e
CodeGolfS tackExcha nge
CodeGolf StackExc hange
CodeGol fStackE xchange
CodeGo lfStac kExcha nge
CodeG olfSt ackEx chang e
Code Golf Stac kExc hang e
Cod eGo lfS tac kEx cha nge
Co de Go lf St ac kE xc ha ng e
C o d e G o l f S t a c k E x c h a n g e

Try it online here

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

D - 178 176

Golfed:

import std.stdio,std.range;void main(string[]a){int l=a[1].length;for(int i=1;i<=l;++i)a[1].chunks(i).join(" ").writeln;for(int i=l-1;i>0;--i)a[1].chunks(i).join(" ").writeln;}

Un-golfed:

import std.stdio, std.range;

void main( string[] a )
{   
    int l = a[1].length;

    for( int i = 1; i <= l; ++i )
        a[1].chunks( i ).join( " " ).writeln;

    for( int i = l - 1; i > 0; --i )
        a[1].chunks( i ).join( " " ).writeln;
}

Example 1:

F:\Code\D\Other>rdmd spaces.d abcdef
a b c d e f
ab cd ef
abc def
abcd ef
abcde f
abcdef
abcde f
abcd ef
abc def
ab cd ef
a b c d e f

Example 2:

F:\Code\D\Other>rdmd spaces.d CodeGolfStackExchange
C o d e G o l f S t a c k E x c h a n g e
Co de Go lf St ac kE xc ha ng e
Cod eGo lfS tac kEx cha nge
Code Golf Stac kExc hang e
CodeG olfSt ackEx chang e
CodeGo lfStac kExcha nge
CodeGol fStackE xchange
CodeGolf StackExc hange
CodeGolfS tackExcha nge
CodeGolfSt ackExchang e
CodeGolfSta ckExchange
CodeGolfStac kExchange
CodeGolfStack Exchange
CodeGolfStackE xchange
CodeGolfStackEx change
CodeGolfStackExc hange
CodeGolfStackExch ange
CodeGolfStackExcha nge
CodeGolfStackExchan ge
CodeGolfStackExchang e
CodeGolfStackExchange
CodeGolfStackExchang e
CodeGolfStackExchan ge
CodeGolfStackExcha nge
CodeGolfStackExch ange
CodeGolfStackExc hange
CodeGolfStackEx change
CodeGolfStackE xchange
CodeGolfStack Exchange
CodeGolfStac kExchange
CodeGolfSta ckExchange
CodeGolfSt ackExchang e
CodeGolfS tackExcha nge
CodeGolf StackExc hange
CodeGol fStackE xchange
CodeGo lfStac kExcha nge
CodeG olfSt ackEx chang e
Code Golf Stac kExc hang e
Cod eGo lfS tac kEx cha nge
Co de Go lf St ac kE xc ha ng e
C o d e G o l f S t a c k E x c h a n g e
\$\endgroup\$
1
\$\begingroup\$

k [50 chars]

{x c,1_|c:{1_,/-1,/:(y*!-_-(#x)%y)_x}[!c]'1+!c:#x}

Example

{x c,1_|c:{1_,/-1,/:(y*!-_-(#x)%y)_x}[!c]'1+!c:#x}"abcdef"

"a b c d e f"
"ab cd ef"
"abc def"
"abcd ef"
"abcde f"
"abcdef"
"abcde f"
"abcd ef"
"abc def"
"ab cd ef"
"a b c d e f"

Example 2

{x c,1_|c:{1_,/-1,/:(y*!-_-(#x)%y)_x}[!c]'1+!c:#x}"CodeGolfStackExchange"

"C o d e G o l f S t a c k E x c h a n g e"
"Co de Go lf St ac kE xc ha ng e"
"Cod eGo lfS tac kEx cha nge"
"Code Golf Stac kExc hang e"
"CodeG olfSt ackEx chang e"
"CodeGo lfStac kExcha nge"
"CodeGol fStackE xchange"
"CodeGolf StackExc hange"
"CodeGolfS tackExcha nge"
"CodeGolfSt ackExchang e"
"CodeGolfSta ckExchange"
"CodeGolfStac kExchange"
"CodeGolfStack Exchange"
"CodeGolfStackE xchange"
"CodeGolfStackEx change"
"CodeGolfStackExc hange"
"CodeGolfStackExch ange"
"CodeGolfStackExcha nge"
"CodeGolfStackExchan ge"
"CodeGolfStackExchang e"
"CodeGolfStackExchange"
"CodeGolfStackExchang e"
"CodeGolfStackExchan ge"
"CodeGolfStackExcha nge"
"CodeGolfStackExch ange"
"CodeGolfStackExc hange"
"CodeGolfStackEx change"
"CodeGolfStackE xchange"
"CodeGolfStack Exchange"
"CodeGolfStac kExchange"
"CodeGolfSta ckExchange"
"CodeGolfSt ackExchang e"
"CodeGolfS tackExcha nge"
"CodeGolf StackExc hange"
"CodeGol fStackE xchange"
"CodeGo lfStac kExcha nge"
"CodeG olfSt ackEx chang e"
"Code Golf Stac kExc hang e"
"Cod eGo lfS tac kEx cha nge"
"Co de Go lf St ac kE xc ha ng e"
"C o d e G o l f S t a c k E x c h a n g e"
\$\endgroup\$
1
\$\begingroup\$

C# - 182 176

using C=System.Console;class P{static void Main(string[]p){int l=p[0].Length,i=-l,j;for(;++i<l;){for(j=0;++j<=l;)C.Write(p[0][j-1]+(j%(i>0?l-i:l+i)>0?"":" "));C.WriteLine();}}}

Ungolfed:

using C=System.Console;

class P
{
    static void Main(string[] p)
    {
        int l=p[0].Length,i=-l,j;
        for (; ++i < l;)
        {
            for(j=0;++j<=l;)C.Write(p[0][j-1]+(j%(i>0?l-i:l+i)>0?"":" "));
            C.WriteLine();
        }
    }
}

Output:

D:\>program CodeGolfStackExchange
C o d e G o l f S t a c k E x c h a n g e
Co de Go lf St ac kE xc ha ng e
Cod eGo lfS tac kEx cha nge
Code Golf Stac kExc hang e
CodeG olfSt ackEx chang e
CodeGo lfStac kExcha nge
CodeGol fStackE xchange
CodeGolf StackExc hange
CodeGolfS tackExcha nge
CodeGolfSt ackExchang e
CodeGolfSta ckExchange
CodeGolfStac kExchange
CodeGolfStack Exchange
CodeGolfStackE xchange
CodeGolfStackEx change
CodeGolfStackExc hange
CodeGolfStackExch ange
CodeGolfStackExcha nge
CodeGolfStackExchan ge
CodeGolfStackExchang e
CodeGolfStackExchange
CodeGolfStackExchang e
CodeGolfStackExchan ge
CodeGolfStackExcha nge
CodeGolfStackExch ange
CodeGolfStackExc hange
CodeGolfStackEx change
CodeGolfStackE xchange
CodeGolfStack Exchange
CodeGolfStac kExchange
CodeGolfSta ckExchange
CodeGolfSt ackExchang e
CodeGolfS tackExcha nge
CodeGolf StackExc hange
CodeGol fStackE xchange
CodeGo lfStac kExcha nge
CodeG olfSt ackEx chang e
Code Golf Stac kExc hang e
Cod eGo lfS tac kEx cha nge
Co de Go lf St ac kE xc ha ng e
C o d e G o l f S t a c k E x c h a n g e

Edit: now using parameters instead of ReadLine().

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

JavaScript 127

function f(s) {
o=s+'\n'
for(i=s.length;--i;){
l='',j=0
while((p=s.substr(i*j++,i)))l+=p+' '
l+='\n',o=l+o+l
}
console.log(o)
}
\$\endgroup\$
1
\$\begingroup\$

Python - 153

a=raw_input()
k=0
b=len(a)
for i in range(b+1)+range(b-1):
 k+=1
 p=[i,b-2-i][k>b]
 s=a
 if kb+1:
    for j in a[p::p+1]:s=s.replace(j, j+" ",1)
    print s 
\$\endgroup\$
1
\$\begingroup\$

Vyxal, 5 bytes

żvẇ∞⁋

Try it Online!

  ẇ   # Cut into slices of length...
 v    # Each of...
ż     # Range from 1 to length of input
   ∞  # Mirror
    ⁋ # Join by newlines, joining each line with spaces
\$\endgroup\$
1
  • \$\begingroup\$ Gosh dang it, ninja'd because I had to sign into a uni workshop! \$\endgroup\$
    – lyxal
    Oct 14, 2022 at 5:05
0
\$\begingroup\$

Q, 34

{a,1_(|)a:" "sv'(1+(!)(#)x)cut\:x}
\$\endgroup\$
0
\$\begingroup\$

C - 134 132

Maximum 8 characters of input, ignoring buffer overflow

#define L n){for(i=0;b[i];){if(i%n==0)p(32);p(b[i++]);}p(10);}
main(i){char b[9],n=1,(*p)()=putchar;gets(b);for(;b[n];++L for(;n;--L}
\$\endgroup\$
0
\$\begingroup\$

Haskell, 109 bytes

p s=putStr$unlines$f s++(reverse$init$f s)
f s=map(unwords.(s#))[1..length s]
[]#i=[]
s#i=take i s:drop i s#i

Usage example: p "abcdef". Output:

a b c d e f
ab cd ef
abc def
abcd ef
abcde f
abcdef
abcde f
abcd ef
abc def
ab cd ef
a b c d e f
\$\endgroup\$
0
\$\begingroup\$

Factor, 78 bytes

[ dup length [1,b] dup reverse rest append [ group " "join print ] with each ]

Try it online!

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

Japt -R, 9 bytes

Êõ@òX ¸Ãê

Try it

Êõ@òX ¸Ãê 
Ê         # Get the length of the input
 õ@    Ã  # For each X in the range [1...length]:
   òX     #  Split the input into substrings with length X
      ¸   #  Join them with spaces
        ê # Palindromize

-R        # Join with newlines and print
\$\endgroup\$
0
\$\begingroup\$

Raku, 44 bytes

{.put for map {.comb($^n)},(1...+.comb...1)}

Try it online!

Raku conveniently has a comb method on strings that can split one into chunks of a given size, so it's just a matter of mapping that method from 1, up to the number of characters in the string, then back down to 1 again.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.