はじめに
2×nブール行列は、4文字の文字列として表すことができます. ':
。文字列には「上行」と「下行」があり、1を表すドットと0を表す空のスペースがあります。たとえば、2×6行列
1 0 1 0 0 1
0 0 0 1 0 1
として表すことができます' '. :
。あなたの仕事は、この「圧縮された形式」のマトリックスを取り、そのエントリーをコンベヤーベルトのように時計回りに1ステップ回転させることです。
入力
あなたの入力は文字の上の単一の文字列. ':
です。その長さは少なくとも2であることが保証されています。
出力
出力は入力文字列になりますが、すべてのドットは時計回りに1ステップ回転します。より明確に言えば、一番上の行のドットは、右に1つずつ配置されていますが、一番右のドットは下に移動します。下の行のドットは左に1ステップ移動しますが、左端のドットは上に移動します。特に、出力文字列は元の文字列と同じ長さでなければならず、空白は重要です。
例
:..:'.
2×6行列に対応する入力文字列を考えます
1 0 0 1 1 0
1 1 1 1 0 1
この行列の回転バージョンは
1 1 0 0 1 1
1 1 1 0 1 0
これは文字列に対応します::. :'
。
ルールとスコアリング
完全なプログラムまたは関数を作成できます。最小のバイトカウントが優先され、標準の抜け穴は許可されません。入力と出力を引用符で囲むかどうかを決定できます。また、1つの末尾の改行も両方で受け入れられます。
テストケース
これらのテストケースは二重引用符で囲みます。
" " -> " "
" ." -> ". "
". " -> "' "
"' " -> " '"
" '" -> " ."
": " -> "''"
"''" -> " :"
":." -> ":'"
":.'" -> ":'."
"..." -> ":. "
": :" -> "':."
"':." -> ".:'"
".:'" -> ": :"
" " -> " "
"::::" -> "::::"
":..:'." -> "::. :'"
" : .:'" -> ". '.. :"
": ''. :" -> "'' :'.."
"........" -> ":...... "
":::: " -> ":::'' "
" ::::" -> " ..:::"
" : : : : " -> ". : : : '"
".'.'.'.'.'" -> "'.'.'.'.'."
".. :: '.' :." -> ": ..'' .' :.'"
".' '.:: :.'. . ::.' '. . .::' :.'." -> "' ' .:.''..'.'. ..:' ' .'. ...'''..'.'"
s=>s.replace(/./g,(c,i)=>" '.:"[(i?q>' '&q!=".":c>"'")+(q=c,s[++i]?s[i]>"'":c>' '&c!=".")*2])
(2つの部分を反転させて、iを増やし、正規表現を減らし、テストを簡単にします。前のcをqに保存します)