TI-BASIC、311 288バイト
TI-BASICの答えは何ですか?それを修正する時間です!
Ans→Str1:" →Str2:" →Str6:"ABCDEFGHIJKLMNOPQRSTUVWXYZ→Str4:For(S,1,length(Str1:sub(Str1,S,1:If inString(Str4+"abcdefghijklmnopqrstuvwxyz",Ans:Str2+Ans→Str2:End:sub(Str2,2,length(Str2)-1→Str2:For(B,1,.1+3⁻¹length(Str2:sub(Str2,3B-2,3→Str3:1+sum({4,2,1}seq(0≠inString(Str4,sub(Str3,X,1)),X,1,3→L₁(B:End:For(C,1,.1+dim(L₁:Str6+sub("><[]-+.,",L₁(C),1→Str6:End:sub(Str6,2,length(Str6)-1→Str6
入力はのoOoコードですAns
。
出力は、変換されたBFコードです。
例:
"AbcDef
AbcDef
prgmCDGF18
--
"PROgRam reVERsES giVeN iNPut sEqUENcE
PROgRam reVERsES giVeN iNPut sEqUENcE
prgmCDGF18
.[>,]<[.<]+
"AbcDe
AbcDe
prgmCDGF18
-
ゴルフ
禁止:(改行とコメントが追加されました)
Ans→Str1 ;store the input in "Str1"
" →Str2 ;set "Str2" and "Str6" to a
" →Str6 ; space character
; (needed b/c TI-BASIC doesn't
; like concatenating empty
; strings)
"ABCDEFGHIJKLMNOPQRSTUVWXYZ→Str4 ;store the uppercase alphabet
; in "Str4"
For(S,1,length(Str1 ;loop over the input string
sub(Str1,S,1 ;get the current character
If inString(Str4+"abcdefghijklmnopqrstuvwxyz",Ans ;if the character is in either
; the uppercase or lowercase
; alphabet
Str2+Ans→Str2 ;add it to "Str2", the code
; string
End
sub(Str2,2,length(Str2)-1→Str2 ;remove the space added earlier
For(B,1,.1+3⁻¹length(Str2 ;loop over each 3-char substring
; and skip any extra chars
; (.1 is added to force one
; loop)
sub(Str2,3B-2,3→Str3 ;store said substring in "Ans"
1+sum({4,2,1}seq(0≠inString(Str4,sub(Str3,X,1)),X,1,3→L₁(B ;convert to the respective
; index in "><[]-+.,"
; (1-indexed)
End
For(C,1,.1+dim(L₁ ;loop over each index
; (.1 is added to force one
; loop)
Str6+sub("><[]-+.,",L₁(C),1→Str6 ;add the char to the translation
; string
End
sub(Str6,2,length(Str6)-1→Str6 ;remove the added space and
; store the result in "Str6"
; and "Ans"
;implicit print of "Ans"
ノート:
- TI-BASICはトークン化された言語です。文字数がバイト数と等しくありません。