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是一种标记化语言。字符数不不等于字节数。