WinDbg, 449 388 바이트
as, }@$t1
as. }0;?@$t0
asThink n10;ed8<<22;r$t0=dwo(8<<22);r$t1=0;.do{
aSa " "
asQ .printf";r$t1=1;.do{r$t1=@$t1-1;r$t0=@$t0
as/c add Q +"
aSby " "
as/c divide Q /"
asfrom 0;r$t0=-@$t0+
as/c multiply Q *"
aSnumber " "
aSof " "
asrepeat +1
as/c subtract Q -"
.for(r$t9=1;by(@$t0);r$t0=@$t0+1){j44!=by(@$t0) .printf"%c",by(@$t0);.if116!=by(@$t0-1){.printf" , "}};.printf"\b ."
반복 코드의 별명을 정의하여 -61 바이트
LambdaBeta의 사용에서 영감을 얻었습니다#define
. 이러한 접근 방식의 수정합니다 WordMath 구문이 약간 ( ,
및 .
공백으로 구분 된 다른 단어처럼해야하며, ,
따르지 않는 repeat
), 그리고 수정 된 WordMath 구문이 유효 WinDbg는 코드가되도록 별칭을 만듭니다. 마지막 줄은 입력을 수정 된 구문으로 변환하여 질문에서 요구하는 내용을 수행합니다.
메모리 주소에서 문자열을 설정하고 의사 레지스터 $t0
를 해당 주소 로 설정하면 입력이 이루어집니다 . 참고 :이 int
at 을 덮어 쓰므로 0x2000000
문자열을 시작하면 부분적으로 덮어 씁니다. $t0
덮어 씁니다.
이 코드는 문자열 설정 전후에 실행되었는지에 따라 별칭을 생성하므로 출력 코드가 달라집니다 (별칭 또는 불일치). 불행히도 공백을 구분하지 않고 별칭을 올바르게 확장하는 방법을 찾지 못했습니다 (즉, WordMath 스크립트를 먼저 변환하지 않고 직접 실행할 수 없음을 의미합니다).
작동 방식 :
* $t1 is used for repeating and $t0 is used to read the input and hold the accumulator
* Alias , to }@$t1 -- closing do-while loop and allowing repeat
as , }@$t1
* Alias . to }0;?@$t0 -- close do-while loop and evaluate $t0 (accumulator)
as . }0;?@$t0
* Alias Think to (note this is one line)
as Think n10; * Set base 10
ed 8<<22; * Read ints to address 0x2000000. Enter nothing to exit input mode
r$t0 = dwo(8<<22); * Set $t0 = first int
r$t1=0;.do{ * Open do-while
* Alias a to nothing
aS a " "
* Alias add to (note one line):
as add ; * Close previous statement
r$t1=1;.do{r$t1=@$t1-1; * Open do-while (once) loop
r$t0=@$t0+ * Add number to $t0
* Alias by to nothing
aS by " "
* Alias divide to (note one line):
as divide ; * Close previous statement
r$t1=1;.do{r$t1=@$t1-1; * Open do-while (once) loop
r$t0=@$t0/ * Divide next number from $t0
* Alias from to (note one line):
as from 0; * Preceding subtract statement subtracts 0
r$t0=-@$t0+ * Subtract $t0 from next number
* Alias multiply to (note one line):
as multiply ; * Close previous statement
r$t1=1;.do{r$t1=@$t1-1; * Open do-while (once) loop
r$t0=@$t0* * Multiply next number with $t0
* Alias number to nothing
aS number " "
* Alias of to nothing
aS of " "
* Alias repeat to +1 making do-while (once) loops into do-while (once)+1
as repeat +1
* Alias subtract to (note one line):
as subtract ; * Close previous statement
r$t1=1;.do{r$t1=@$t1-1; * Open do-while (once) loop
r$t0=@$t0- * Subtract next number from $t0
.for (r$t9=1; by(@$t0); r$t0=@$t0+1) * Enumerate the string
{
j 44!=by(@$t0) * If not comma
.printf "%c",by(@$t0); * Print the char
* implicit else
.if 116!=by(@$t0-1) * Else if the previous char is not t
{
.printf " , " * Print the comma with spaces around it
}
};
.printf "\b ." * Replacing ending "." with " ."
이 코드를 한 번 실행하기 전에 문자열을 입력하는 샘플 출력 (결과 프로그램은 WordMath와 유사) :
0:000> r$t0=8<<22
0:000> eza8<<22"Think of a number, add 5, add 10, multiply by 2, subtract 15, repeat, divide by 2."
0:000> as, }@$t1
0:000> as. }0;?@$t0
0:000> asThink n10;ed8<<22;r$t0=dwo(8<<22);r$t1=0;.do{
0:000> aSa " "
0:000> asadd ;r$t1=1;.do{r$t1=@$t1-1;r$t0=@$t0+
0:000> aSby " "
0:000> asdivide ;r$t1=1;.do{r$t1=@$t1-1;r$t0=@$t0/
0:000> asfrom 0;r$t0=-@$t0+
0:000> asmultiply ;r$t1=1;.do{r$t1=@$t1-1;r$t0=@$t0*
0:000> aSnumber " "
0:000> aSof " "
0:000> asrepeat +1
0:000> assubtract ;r$t1=1;.do{r$t1=@$t1-1;r$t0=@$t0-
0:000> .for(r$t9=1;by(@$t0);r$t0=@$t0+1){j44!=by(@$t0) .printf"%c",by(@$t0);.if116!=by(@$t0-1){.printf" , "}};.printf"\b ."
Think of a number , add 5 , add 10 , multiply by 2 , subtract 15 , repeat divide by 2 }0;?@$t0
0:000> Think of a number , add 5 , add 10 , multiply by 2 , subtract 15 , repeat divide by 2 }0;?@$t0
base is 10
02000000 6e696854 18
18
02000004 666f206b
Evaluate expression: 18 = 00000012
이 코드가 한 번 실행 된 후 문자열을 입력 한 샘플 출력 (문자열을 입력 할 때 별칭이 확장되어 결과 프로그램이 예쁘지 않음) :
0:000> r$t0=8<<22
0:000> eza8<<22"Think of a number, add 5, add 10, multiply by 2, subtract 15, repeat, divide by 2."
0:000> as, }@$t1
0:000> as. }0;?@$t0
0:000> asThink n10;ed8<<22;r$t0=dwo(8<<22);r$t1=0;.do{
0:000> aSa " "
0:000> asadd ;r$t1=1;.do{r$t1=@$t1-1;r$t0=@$t0+
0:000> aSby " "
0:000> asdivide ;r$t1=1;.do{r$t1=@$t1-1;r$t0=@$t0/
0:000> asfrom 0;r$t0=-@$t0+
0:000> asmultiply ;r$t1=1;.do{r$t1=@$t1-1;r$t0=@$t0*
0:000> aSnumber " "
0:000> aSof " "
0:000> asrepeat +1
0:000> assubtract ;r$t1=1;.do{r$t1=@$t1-1;r$t0=@$t0-
0:000> .for(r$t9=1;by(@$t0);r$t0=@$t0+1){j44!=by(@$t0) .printf"%c",by(@$t0);.if116!=by(@$t0-1){.printf" , "}};.printf"\b ."
n10;ed8<<22;r$t0=dwo(8<<22);r$t1=0;.do{ number , ;r$t1=1;.do{r$t1=@$t1-1;r$t0=@$t0+ 5 , ;r$t1=1;.do{r$t1=@$t1-1;r$t0=@$t0+ 10 , ;r$t1=1;.do{r$t1=@$t1-1;r$t0=@$t0* 2 , ;r$t1=1;.do{r$t1=@$t1-1;r$t0=@$t0- 15 , repeat ;r$t1=1;.do{r$t1=@$t1-1;r$t0=@$t0/ 2 }0;?@$t0
0:000> n10;ed8<<22;r$t0=dwo(8<<22);r$t1=0;.do{ number , ;r$t1=1;.do{r$t1=@$t1-1;r$t0=@$t0+ 5 , ;r$t1=1;.do{r$t1=@$t1-1;r$t0=@$t0+ 10 , ;r$t1=1;.do{r$t1=@$t1-1;r$t0=@$t0* 2 , ;r$t1=1;.do{r$t1=@$t1-1;r$t0=@$t0- 15 , repeat ;r$t1=1;.do{r$t1=@$t1-1;r$t0=@$t0/ 2 }0;?@$t0
base is 10
02000000 3b30316e 26
26
02000004 3c386465
Evaluate expression: 26 = 0000001a
약간 수정 된 WordMath 구문을 사용하는 샘플 출력 :
0:000> Think of a number , add 1 , repeat repeat repeat divide by 3 .
base is 10
02000000 0000001a 3
3
02000004 3c386465
Evaluate expression: 2 = 00000002
0:000> Think of a number , divide by 5 , subtract from 9 .
base is 10
02000000 00000003 29
29
02000004 3c386465
Evaluate expression: 4 = 00000004