TI-BASIC,79字节
Ans→Str1:" :For(I,1,length(Str1:Ans+sub(":)=((:)=:():=)(=:||:",1+2expr(sub(Str1,I,1)),2:End:sub(Ans,2,length(Ans)-1
输入是中的数字字符串Ans。
输出是Emoji Math编码的数字。
例子:
"134
134
prgmCDGF1C
:)(:)=
"2213894
2213894
prgmCDGF1C
(:(:=()=:||::(
说明:
Ans→Str1                                                 ;store the input in Ans
"                                                        ;leave " " in Ans
For(I,1,length(Str1                                      ;loop over each character in the
                                                         ; input string
Ans+sub(":)=((:)=:():=)(=:||:",1+2expr(sub(Str1,I,1)),2  ;convert the current character
                                                         ; to a number and use it as the
                                                         ; index into the encoding string
                                                         ; then append the encoded digit
End
sub(Ans,2,length(Ans)-1                                  ;remove the prepended space and
                                                         ; store the result in Ans
                                                         ;implicit print of Ans
另外,这是一个94字节的解决方案,它使用数字而不是字符串作为输入:
int(10fPart(Ans₁₀^(seq(⁻X-1,X,0,log(Ans→L₁:" :For(I,dim(L₁),1,-1:Ans+sub(":)=((:)=:():=)(=:||:",1+2L₁(I),2:End:sub(Ans,2,length(Ans)-1
例子:
134
             134
prgmCDGF1C
:)(:)=
2213894
         2213894
prgmCDGF1C
(:(:=()=:||::(
说明:
int(10fPart(Ans₁₀^(seq(⁻X-1,X,0,log(Ans→L₁     ;generate a list of the input's digits
                                             ; reversed and store it in L₁
"                                            ;leave " " in Ans
For(I,dim(L₁),1,-1                            ;loop over L₁ backwards
Ans+sub(":)=((:)=:():=)(=:||:",1+2L₁(I),2     ;use the value of the I-th element in L₁ as
                                              ; the index into the encoding string then
                                              ; append the encoded digit
End
sub(Ans,2,length(Ans)-1                       ;remove the prepended space and store the
                                              ; result in Ans
                                              ;implicit print of Ans
笔记: