PowerShellの、154、152、99, 86 bytes
なんと47バイト節約してくれてありがとう@TimmyD(さらに6バイトも節約した)
@TessellatingHecklerにさらに13バイトを保存していただきありがとうございます。
最新:
param($a)-join($a[$a.length..0]|%{("$_".ToLower(),"$_".ToUpper())[$a[$i++]-in65..90]})
元の:
param($a);$x=0;(($a[-1..-$a.length])|%{$_=$_.tostring().tolower();if([regex]::matches($a,"[A-Z]").index-contains$x){$_.toupper()}else{$_};$x++})-join''
通常のフォーマット:
最新(私の意見では2行として最適に見えます):
param($a)
-join($a[$a.length..0] | %{("$_".ToLower(), "$_".ToUpper())[$a[$i++] -in 65..90]})
説明:
param($a)-join($a[$a.length..0]|%{("$_".ToLower(),"$_".ToUpper())[$a[$i++]-in65..90]})
param($a)
# Sets the first passed parameter to variable $a
-join( )
# Converts a char array to a string
$a[$a.length..0]
# Reverses $a as a char array
|%{ }
# Shorthand pipe to foreach loop
("$_".ToLower(),"$_".ToUpper())
# Creates an array of the looped char in lower and upper cases
[$a[$i++]-in65..90]
# Resolves to 1 if the current index of $a is upper, which would output "$_".ToUpper() which is index 1 of the previous array
元の:
param($a)
$x = 0
(($a[-1..-$a.length]) | %{
$_ = $_.tostring().tolower()
if([regex]::matches($a,"[A-Z]").index -contains $x){
$_.toupper()
}else{
$_
}
$x++
}
) -join ''
First time poster here, was motivated because I rarely see PowerShell, but at 154 152 bytes on this one... I can see why! Any suggestions appreciated.
I have learned that I must completely change my way of thinking to golf in code and its fun!