Pyramid of broken strings
Perl, 46 + 1 = 47 bytes
Run with the -n
flag
say s/.{$=}(?=.)/$&|/gr while($==y///c/++$,)-2
Try it online!
Code breakdown
-n #Reads input into the $_ variable
say s/.{$=}(?=.)/$&|/gr while($==y///c/++$,)-2
y///c #Transliteration. Implicitly operates on $_, replacing every character with itself and counting replacements
#y///c effectively returns the length of $_
/++$, #Increments $, (which starts off at 0) and divides the length of $_ by $,
$== #Stores the result of this division into $=
#$= forces its contents to be an integer, so it truncates any decimal
( )-2 #Returns 0 if $= is equal to 2
while #Evaluates its RHS as the condition. If truthy, evaluates its LHS.
s/ / /gr #Substitution. Implicitly operates on $_.
#Searches for its first argument and replaces it with its second argument, repeating until it's done, and returns the new string. $_ is not modified.
.{$=} #Looks for a string of $= characters...
(?=.) #...that is followed by at least one non-newline character, but does not include this character in the match...
$&| #...and replaces it with itself followed by a pipe character.
say #Output the result of the substitution.
Pyth, 16 bytes
Vh/lQ3j\|cQ/lQhN
V # For N in range(1, \/ )
h/lQ3 # 1+lenght(input)/3
j\| # join with '|'
cQ # chop input in
/lQhN # lenght(input)/(N+1) pieces
try here
C, 145 131 128 125 bytes
l,n,i=1,j;f(char*s){l=strlen(s);puts(s);do{n=l/++i;for(j=0;j<l;)j&&(j%n||putchar('|')),putchar(s[j++]);puts("");}while(n>2);}
This is a function that takes a string as its argument and prints the output to STDOUT.
l,n,i=1,j; // declare some variables
f(char*s){ // declare the function
l=strlen(s); // get the length of the string
puts(s); // output the initial version, with trailing newline
do{n=l/++i; // n is the number of characters per "section",
// and we'll do-while n>2 to stop at the right time
for(j=0;j<l;) // loop through the characters of the string
j&&( // if j != 0,
j%n|| // and j % n == 0,
putchar('|')), // insert a | before this character
putchar(s[j++]); // print the character
puts(""); // print a newline after the loop
}while(n>2);}