PowerShell, 102 Bytes
param($s,$i)$l=$s.Length;$s+' '*($i%$l)-split"(.{$i})"|?{$_}|%{$r=-not$r;@($_,($_[$l..0]-join''))[$r]}
Diminta sebagai berikut (jika disimpan ke file CodeGolf55051.ps1
)
.\CodeGolf55051.ps1 -s '1234567890' -i 4
Usaha Sebelumnya
(lebih panjang atau tidak valid)
PowerShell, 110 Bytes
param($s,$i)$l=$s.Length;$s+' '*(($i-$l%$i)%$i)-split"(.{$i})"|?{$_}|%{$r=-not$r;@($_,($_[$l..0]-join''))[$r]}
PowerShell, 111 Bytes
param($s,$i)$s+' '*(($i-$s.Length%$i)%$i)-split"(.{$i})"|?{$_}|%{$r=-not$r;@($_,($_[$_.length..0]-join''))[$r]}
Penjelasan
param($s,$i) #Take input text (s) and column width (i)
$s #take the user entered string
+ ' ' * (($i - $s.Length % $i) % $i) #add the least number of spaces required to make its length divisible by i
-split"(.{$i})" #break it into chunks of i characters in length
| ?{$_} #skip any blank lines created in the process
| %{ #for each line
$r = -not $r; # toggle a boolean value
@( # define an array
$_ # index 0 = the string going forwards
,($_[$_.length..0] -join '') # index 1 = the string reversed (by taking each character from the last to the first, then joining them)
)[$r] # if our boolean value is false take the forward string (index 0), if true take the backwards one (index 1)
} #next
PowerShell, 180 Bytes
param($s,$i)$x="`${0}|{1}|`${2}";$w=$x;1..$i|%{$w=$w-f$_,$x,($i+$_)};$w=$w-replace'\||\${.*}';$r=$w-replace'\$\d+','(.)?';$s+' '*($i-$s.Length%$i)-replace$r,$w-split"(.{$i})"|?{$_}
PowerShell, 196 Bytes
param($s,$i)$x="{0}|{1}|{2}";$w=$x;1..$i|%{$w=$w-f$_,$x,($i+$_)};$w=$w-replace'(\d+)','$$$1'-replace'\||{.*}';$r=$w-replace'\$\d+','(.)?';$s+' '*($i-$s.Length%$i)-replace$r,$w-split"(.{$i})"|?{$_}
Penjelasan
param ($s, $i) #Take input text (s) and column width (i)
$x = "{0}|{1}|{2}" #Define string format which takes 3 entries and pipe delimits them
$w = $x #initialise our replacement regex with this format
1..$i | %{ #for 1 to the specified column width
$w = $w -f $_, $x, ($i + $_) #update the regex 1|{...}|5, 1|2|{...}|6|5, etc
} #resulting in w = 1|2|3|4|{...}|8|7|6|5
$w = $w -replace '(\d+)', '$$$1' #now prefix the numbers with a dollar (so they're regex replacement variables)
-replace '\||{.*}' #and remove the delimiters and superfluous `{...}` left from our middle insertion routine
$r = $w -replace '\$\d+', '(.)?' #then create the match pattern by replacing the variables with optional single character captures
$s #now take the user entered string
+ ' ' * ($i - $s.Length % $i) #add the least number of spaces required to make its length divisible by i
-replace $r, $w #perform a replacement using the regex match and replace patterns created above
-split "(.{$i})" #then split the string into blocks of length i
| ?{$_} #removing any blank lines created in the process
( {...}
dalam komentar di atas sebenarnya {0}|{1}|{2}
; saya menempatkan {...}
untuk meningkatkan keterbacaan.
Powershell, 120 Bytes
(tidak valid)
param($s,$i)$s + ' ' * ($i-$s.Length%$i) -replace '(.{4})?(.)(.)(.)(.)',"`$1`n`$5`$4`$3`$2`n" -split "`n" | ?{$_ -ne ""}