Powershell、69バイト
($args|% t*y|?{$r+="$_ ";++$p-gt$l}|%{$r;rv r,p;$l++})|%{' '*--$l+$_}
ゴルフの少ないテストスクリプト:
$f = {
(
$args|% t*y|?{ # test predicate for each char in a argument string
$r+="$_ " # add current char to the result string
++$p-gt$l # return predicate value: current char posision is greater then line num
}|%{ # if predicate is True
$r # push the result string to a pipe
rv r,p # Remove-Variable r,p. This variables will be undefined after it.
$l++ # increment line number
}
)|%{ # new loop after processing all characters and calculating $l
' '*--$l+$_ # add spaces to the start of lines
} # and push a result to a pipe
}
@(
,("R",
"R ")
,("cat",
" c ",
"a t ")
,("monk3y",
" m ",
" o n ",
"k 3 y ")
,("meanIngfu1",
" m ",
" e a ",
" n I n ",
"g f u 1 ")
,("^/\/|\/[]\",
" ^ ",
" / \ ",
" / | \ ",
"/ [ ] \ ")
,("Thisrunofcharactersismeanttohavealengththatcanbeexpressedasatriangularnumber.Diditwork?Youtellme,Ican'tcountverywell,ok?",
" T ",
" h i ",
" s r u ",
" n o f c ",
" h a r a c ",
" t e r s i s ",
" m e a n t t o ",
" h a v e a l e n ",
" g t h t h a t c a ",
" n b e e x p r e s s ",
" e d a s a t r i a n g ",
" u l a r n u m b e r . D ",
" i d i t w o r k ? Y o u t ",
" e l l m e , I c a n ' t c o ",
"u n t v e r y w e l l , o k ? ")
,("*/\/|\/|o\/|o|\/o|o|\/||o|o\/o|||o|\/o||o|||\/||o|||o|\/|o|||o||o\",
" * ",
" / \ ",
" / | \ ",
" / | o \ ",
" / | o | \ ",
" / o | o | \ ",
" / | | o | o \ ",
" / o | | | o | \ ",
" / o | | o | | | \ ",
" / | | o | | | o | \ ",
"/ | o | | | o | | o \ ")
) | % {
$s,$expected = $_
$result = &$f $s
"$result"-eq"$expected"
$result
}
出力:
True
R
True
c
a t
True
m
o n
k 3 y
True
m
e a
n I n
g f u 1
True
^
/ \
/ | \
/ [ ] \
True
T
h i
s r u
n o f c
h a r a c
t e r s i s
m e a n t t o
h a v e a l e n
g t h t h a t c a
n b e e x p r e s s
e d a s a t r i a n g
u l a r n u m b e r . D
i d i t w o r k ? Y o u t
e l l m e , I c a n ' t c o
u n t v e r y w e l l , o k ?
True
*
/ \
/ | \
/ | o \
/ | o | \
/ o | o | \
/ | | o | o \
/ o | | | o | \
/ o | | o | | | \
/ | | o | | | o | \
/ | o | | | o | | o \