From 86fc0fe7b2b0508cef1ac17a4a8573175bbd35fc Mon Sep 17 00:00:00 2001 From: Chen Hao Date: Thu, 5 Apr 2018 20:02:51 +0800 Subject: [PATCH 1/9] Add compare --- Language2.md | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 Language2.md diff --git a/Language2.md b/Language2.md new file mode 100644 index 0000000..67ec9fe --- /dev/null +++ b/Language2.md @@ -0,0 +1,44 @@ +# Advance functions + +## compare: compare cell#0 and cell#1 +`cell#2 = 0` if cell#0 equals cell#1; + +`cell#2 = 1` if cell#0 larger than cell#1; + +`cell#2 = -1 = 255` if cell#0 smaller than cell#1; + +``` +[-]>[-]>[-]>[-]>[-]>[-]>[-]<<<<<< // clear cell#0~6 + +// px means the pointer value after executing this line +++++++++ // p0; cell#0 +> ++++++++++ // p1; cell#1 +<[->>+>+<<<]>>>[-<<<+>>>] // p3; cell#2 = #0 +<<[->>+>+>+<<<<]>>>[-<<<+>>>] // p4; cell#5 = cell#3 = cell#1 ++ // p4; cell#4 flag + // p4; cell#5 = cell#3 = cell#1 + // p4; cell#6; buffer +<< // p2 + +// p2 +[ +->- // p3; sub cell#2 and cell#3 +>- // p4; clear the flag +<[>+<[-]] // p3; cell#3 not 0; then set the flag and clear cell#3 to break the loop; else continue +[-]>>-[->+<<<+>>]>[-<+>] // p6; copy cell#5 sub 1 to cell#3 +<<<< // p2 +] + +// if flag is set; then cell#0 smaller than cell#1; else cell#0 lager equals cell#1 +// and if cell#3 equals 0; then cell#0 equals cell#2 +>> // p4 +-[ // p4; if flag is not set; +<[<+>>[-]]<<+>> // p4; then if cell#3 not 0; then cell#2 = 2; else cell#2 = 1; +] +<<- // p2; cell#2 sub 1 +<< // p0; + +// clear cell#3~6 +>>>[-]>[-]>[-]>[-]<<<<<< +``` From 64df2ae6146e82389c2ace5090091aa0d721effc Mon Sep 17 00:00:00 2001 From: Chen Hao Date: Thu, 5 Apr 2018 20:03:40 +0800 Subject: [PATCH 2/9] update format --- Language2.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Language2.md b/Language2.md index 67ec9fe..92075be 100644 --- a/Language2.md +++ b/Language2.md @@ -19,7 +19,7 @@ + // p4; cell#4 flag // p4; cell#5 = cell#3 = cell#1 // p4; cell#6; buffer -<< // p2 +<< // p2 // p2 [ From e5338060f0dd5416c5d4ef72d5a8a9bdbb89e68d Mon Sep 17 00:00:00 2001 From: Chen Hao Date: Thu, 5 Apr 2018 20:05:06 +0800 Subject: [PATCH 3/9] update format --- Language2.md | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/Language2.md b/Language2.md index 92075be..b08f334 100644 --- a/Language2.md +++ b/Language2.md @@ -11,33 +11,33 @@ [-]>[-]>[-]>[-]>[-]>[-]>[-]<<<<<< // clear cell#0~6 // px means the pointer value after executing this line -++++++++ // p0; cell#0 +++++++++ // p0; cell#0 > -+++++++++ // p1; cell#1 ++++++++++ // p1; cell#1 <[->>+>+<<<]>>>[-<<<+>>>] // p3; cell#2 = #0 <<[->>+>+>+<<<<]>>>[-<<<+>>>] // p4; cell#5 = cell#3 = cell#1 -+ // p4; cell#4 flag - // p4; cell#5 = cell#3 = cell#1 - // p4; cell#6; buffer -<< // p2 ++ // p4; cell#4 flag + // p4; cell#5 = cell#3 = cell#1 + // p4; cell#6; buffer +<< // p2 // p2 [ -->- // p3; sub cell#2 and cell#3 ->- // p4; clear the flag -<[>+<[-]] // p3; cell#3 not 0; then set the flag and clear cell#3 to break the loop; else continue -[-]>>-[->+<<<+>>]>[-<+>] // p6; copy cell#5 sub 1 to cell#3 -<<<< // p2 +->- // p3; sub cell#2 and cell#3 +>- // p4; clear the flag +<[>+<[-]] // p3; cell#3 not 0; then set the flag and clear cell#3 to break the loop; else continue +[-]>>-[->+<<<+>>]>[-<+>] // p6; copy cell#5 sub 1 to cell#3 +<<<< // p2 ] // if flag is set; then cell#0 smaller than cell#1; else cell#0 lager equals cell#1 // and if cell#3 equals 0; then cell#0 equals cell#2 ->> // p4 --[ // p4; if flag is not set; -<[<+>>[-]]<<+>> // p4; then if cell#3 not 0; then cell#2 = 2; else cell#2 = 1; +>> // p4 +-[ // p4; if flag is not set; +<[<+>>[-]]<<+>> // p4; then if cell#3 not 0; then cell#2 = 2; else cell#2 = 1; ] -<<- // p2; cell#2 sub 1 -<< // p0; +<<- // p2; cell#2 sub 1 +<< // p0; // clear cell#3~6 >>>[-]>[-]>[-]>[-]<<<<<< From 3081ee6bede03f4497da5c2809a47bbdbca1d32c Mon Sep 17 00:00:00 2001 From: Chen Hao Date: Thu, 5 Apr 2018 23:21:40 +0800 Subject: [PATCH 4/9] Update Language2.md --- Language2.md | 115 +++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 94 insertions(+), 21 deletions(-) diff --git a/Language2.md b/Language2.md index b08f334..370255a 100644 --- a/Language2.md +++ b/Language2.md @@ -1,44 +1,117 @@ # Advance functions + 1. px means the pointer value after executing this line + 1. #x means the order x of the cell -## compare: compare cell#0 and cell#1 -`cell#2 = 0` if cell#0 equals cell#1; +## compare(x, y, ret): compare #0 and #1 -`cell#2 = 1` if cell#0 larger than cell#1; +`#2 = 0` if #0 equals #1; -`cell#2 = -1 = 255` if cell#0 smaller than cell#1; +`#2 = 1` if #0 larger than #1; + +`#2 = -1 = 255` if #0 smaller than #1; ``` -[-]>[-]>[-]>[-]>[-]>[-]>[-]<<<<<< // clear cell#0~6 +[-]>[-]>[-]>[-]>[-]>[-]>[-]<<<<<< // clear #0~#6 -// px means the pointer value after executing this line -++++++++ // p0; cell#0 +++++++++ // p0; #0 > -+++++++++ // p1; cell#1 -<[->>+>+<<<]>>>[-<<<+>>>] // p3; cell#2 = #0 -<<[->>+>+>+<<<<]>>>[-<<<+>>>] // p4; cell#5 = cell#3 = cell#1 -+ // p4; cell#4 flag - // p4; cell#5 = cell#3 = cell#1 - // p4; cell#6; buffer ++++++++++ // p1; #1 +<[->>+>+<<<]>>>[-<<<+>>>] // p3; #2 = #0 +<<[->>+>+>+<<<<]>>>[-<<<+>>>] // p4; #5 = #3 = #1 ++ // p4; #4 flag + // p4; #5 = #3 = #1 + // p4; #6; buffer << // p2 // p2 [ -->- // p3; sub cell#2 and cell#3 +->- // p3; sub #2 and #3 >- // p4; clear the flag -<[>+<[-]] // p3; cell#3 not 0; then set the flag and clear cell#3 to break the loop; else continue -[-]>>-[->+<<<+>>]>[-<+>] // p6; copy cell#5 sub 1 to cell#3 +<[>+<[-]] // p3; #3 not 0; then set the flag and clear #3 to break the loop; else continue +[-]>>-[->+<<<+>>]>[-<+>] // p6; copy #5 sub 1 to #3 <<<< // p2 ] -// if flag is set; then cell#0 smaller than cell#1; else cell#0 lager equals cell#1 -// and if cell#3 equals 0; then cell#0 equals cell#2 +// if flag is set; then #0 smaller than #1; else #0 lager equals #1 +// and if #3 equals 0; then #0 equals #2 >> // p4 -[ // p4; if flag is not set; -<[<+>>[-]]<<+>> // p4; then if cell#3 not 0; then cell#2 = 2; else cell#2 = 1; +<[<+>>[-]]<<+>> // p4; then if #3 not 0; then #2 = 2; else #2 = 1; ] -<<- // p2; cell#2 sub 1 +<<- // p2; #2 sub 1 << // p0; -// clear cell#3~6 +// clear #3~6 +>>>[-]>[-]>[-]>[-]<<<<<< +``` + +## min(x, y. min{x,y}): put the min value from #0 and #1 to #2 + +``` +[-]>[-]>[-]>[-]>[-]>[-]>[-]<<<<<< // clear #0~6 + +// px means the pointer value after executing this line +++++++++ // p0; #0 +> ++++++++++ // p1; #1 +<[->>+>+<<<]>>>[-<<<+>>>] // p3; #2 = #0 +<<[->>+>+>+<<<<]>>>[-<<<+>>>] // p4; #5 = #3 = #1 ++ // p4; #4 flag + // p4; #5 = #3 = #1 + // p4; #6; buffer +<< // p2 + +// p2 +[ +->- // p3; sub #2 and #3 +>- // p4; clear the flag +<[>+<[-]] // p3; #3 not 0; then set the flag and clear #3 to break the loop; else continue +[-]>>-[->+<<<+>>]>[-<+>] // p6; copy #5 sub 1 to #3 +<<<< // p2 +] + +// if flag is set; then #0 smaller than #1; else #0 lager equals #1 +>[-]+> // p4; set #3 = 1 +[<-<<<[->>+>+<<<]>>>[-<<<+>>>]>[-]] // p4; if flag is set; set #3 = 0; copy #0 to #2; +<[-<<[->+>+<<]>>[-<<+>>]] // p3; if #3 = 1; copy #1 to #2 +<<< // p0 + +// clear #3~6 +>>>[-]>[-]>[-]>[-]<<<<<< +``` + + +## max(x, y. max{x,y}): put the max value from #0 and #1 to #2 + +``` +[-]>[-]>[-]>[-]>[-]>[-]>[-]<<<<<< // clear #0~6 + +// px means the pointer value after executing this line +++++++++++++++ // p0; #0 +> ++++++++++ // p1; #1 +<[->>+>+<<<]>>>[-<<<+>>>] // p3; #2 = #0 +<<[->>+>+>+<<<<]>>>[-<<<+>>>] // p4; #5 = #3 = #1 ++ // p4; #4 flag + // p4; #5 = #3 = #1 + // p4; #6; buffer +<< // p2 + +// p2 +[ +->- // p3; sub #2 and #3 +>- // p4; clear the flag +<[>+<[-]] // p3; #3 not 0; then set the flag and clear #3 to break the loop; else continue +[-]>>-[->+<<<+>>]>[-<+>] // p6; copy #5 sub 1 to #3 +<<<< // p2 +] + +// if flag is set; then #0 smaller than #1; else #0 lager equals #1 +>[-]+> // p4; set #3 = 1 +[<-<<[->+>+<<]>>[-<<+>>]>[-]] // p4; if flag is set; set #3 = 0; copy #1 to #2; +<[-<<<[->>+>+<<<]>>>[-<<<+>>>]] // p3; if #3 = 1; copy #0 to #2 +<<< // p0 + +// clear #3~6 >>>[-]>[-]>[-]>[-]<<<<<< ``` From 468f8af78fb2bd84ac67511bc81eb87dc6a30267 Mon Sep 17 00:00:00 2001 From: Chen Hao Date: Thu, 5 Apr 2018 23:25:03 +0800 Subject: [PATCH 5/9] optimize code --- Language2.md | 46 ++++------------------------------------------ 1 file changed, 4 insertions(+), 42 deletions(-) diff --git a/Language2.md b/Language2.md index 370255a..3ca126e 100644 --- a/Language2.md +++ b/Language2.md @@ -11,6 +11,7 @@ `#2 = -1 = 255` if #0 smaller than #1; ``` +########################### perpare compare ########################### [-]>[-]>[-]>[-]>[-]>[-]>[-]<<<<<< // clear #0~#6 ++++++++ // p0; #0 @@ -31,6 +32,7 @@ [-]>>-[->+<<<+>>]>[-<+>] // p6; copy #5 sub 1 to #3 <<<< // p2 ] +########################### perpare compare ########################### // if flag is set; then #0 smaller than #1; else #0 lager equals #1 // and if #3 equals 0; then #0 equals #2 @@ -48,27 +50,7 @@ ## min(x, y. min{x,y}): put the min value from #0 and #1 to #2 ``` -[-]>[-]>[-]>[-]>[-]>[-]>[-]<<<<<< // clear #0~6 - -// px means the pointer value after executing this line -++++++++ // p0; #0 -> -+++++++++ // p1; #1 -<[->>+>+<<<]>>>[-<<<+>>>] // p3; #2 = #0 -<<[->>+>+>+<<<<]>>>[-<<<+>>>] // p4; #5 = #3 = #1 -+ // p4; #4 flag - // p4; #5 = #3 = #1 - // p4; #6; buffer -<< // p2 - -// p2 -[ -->- // p3; sub #2 and #3 ->- // p4; clear the flag -<[>+<[-]] // p3; #3 not 0; then set the flag and clear #3 to break the loop; else continue -[-]>>-[->+<<<+>>]>[-<+>] // p6; copy #5 sub 1 to #3 -<<<< // p2 -] +perpare_compare(x, y, x, y, flag, x, buffer); // if flag is set; then #0 smaller than #1; else #0 lager equals #1 >[-]+> // p4; set #3 = 1 @@ -84,27 +66,7 @@ ## max(x, y. max{x,y}): put the max value from #0 and #1 to #2 ``` -[-]>[-]>[-]>[-]>[-]>[-]>[-]<<<<<< // clear #0~6 - -// px means the pointer value after executing this line -++++++++++++++ // p0; #0 -> -+++++++++ // p1; #1 -<[->>+>+<<<]>>>[-<<<+>>>] // p3; #2 = #0 -<<[->>+>+>+<<<<]>>>[-<<<+>>>] // p4; #5 = #3 = #1 -+ // p4; #4 flag - // p4; #5 = #3 = #1 - // p4; #6; buffer -<< // p2 - -// p2 -[ -->- // p3; sub #2 and #3 ->- // p4; clear the flag -<[>+<[-]] // p3; #3 not 0; then set the flag and clear #3 to break the loop; else continue -[-]>>-[->+<<<+>>]>[-<+>] // p6; copy #5 sub 1 to #3 -<<<< // p2 -] +perpare_compare(x, y, x, y, flag, x, buffer); // if flag is set; then #0 smaller than #1; else #0 lager equals #1 >[-]+> // p4; set #3 = 1 From 2f3e7ea217453e0855eb0a80bc19ea51ba86394d Mon Sep 17 00:00:00 2001 From: Chen Hao Date: Thu, 5 Apr 2018 23:39:33 +0800 Subject: [PATCH 6/9] optimize call --- Language2.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Language2.md b/Language2.md index 3ca126e..460e373 100644 --- a/Language2.md +++ b/Language2.md @@ -50,7 +50,7 @@ ## min(x, y. min{x,y}): put the min value from #0 and #1 to #2 ``` -perpare_compare(x, y, x, y, flag, x, buffer); +perpare_compare(#0, #1, #2, #3, #4, #5, #6); // if flag is set; then #0 smaller than #1; else #0 lager equals #1 >[-]+> // p4; set #3 = 1 @@ -66,7 +66,7 @@ perpare_compare(x, y, x, y, flag, x, buffer); ## max(x, y. max{x,y}): put the max value from #0 and #1 to #2 ``` -perpare_compare(x, y, x, y, flag, x, buffer); +perpare_compare(#0, #1, #2, #3, #4, #5, #6); // if flag is set; then #0 smaller than #1; else #0 lager equals #1 >[-]+> // p4; set #3 = 1 From 7587c3589c46ec3dbe895aa4cb56c6dafa228813 Mon Sep 17 00:00:00 2001 From: Chen Hao Date: Thu, 5 Apr 2018 23:39:50 +0800 Subject: [PATCH 7/9] fix number --- Language2.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Language2.md b/Language2.md index 460e373..d6f8234 100644 --- a/Language2.md +++ b/Language2.md @@ -1,6 +1,6 @@ # Advance functions 1. px means the pointer value after executing this line - 1. #x means the order x of the cell + 2. #x means the order x of the cell ## compare(x, y, ret): compare #0 and #1 From ab29f0b65b1c36372a5b0199af9630bee1e65a70 Mon Sep 17 00:00:00 2001 From: Chen Hao Date: Fri, 6 Apr 2018 00:33:37 +0800 Subject: [PATCH 8/9] update hello world --- README.md | 38 +++++++++++++++++++++++++++----------- 1 file changed, 27 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index 34220d5..0b7566e 100644 --- a/README.md +++ b/README.md @@ -11,17 +11,33 @@ ## "Hello world!" - >+++ [<++++ >-] <- - [>>+++ [<+++ >-] < [>>+ >+ >+ [<]<-] >>- - >>++ >++++ >+++ [<]<<-] - >>>. >--. >. >. >-. > - >+++ [<+++ >-] <- [>>>+++ [<<+++ >>-] <++++ <<-] >+. >. > - >+++ [<+++ >-] < - [>>+++ [<++++ >-]< [>>+ >+ >+ >+ [<]<-] >>>>+ >- [<]<<-] - >>>. >+++. >+. >++. > - >+++ [<+++ >-]< [>+++ <-] >+++++. > - >+++ [<++++ >-] <- - [>>+++ [<++++ >-] <- [>>+ >+ >+ [<] <-] >>>- >>+++ [<] <<-] - >>>. >+. >----. >. + >+++[-<+++>]<+[->+++++<] + >[-<+>>+>+<<]<---> + ++++++[->++++++++<]>- + <++++[->>++++<<] + + ++[->+++<]>+. + <+++[->++++<]>.. + ----.+++. + <+++[-<++++>]<-. + >+++[-<---->]<+.. + >+++[->----<]>.++. + <+++[->++++<]>-. + <+++[->----<]>. + <+++[->++++<]>+. + <++++[->-----<]>+. + <<-.>>+.<+++[->++++<]>. + --.<<+. + >>++++++.<+++[->---<]>-. + ------.<+++[->+++<]>-. + <+++[->++++<]>. + <+++[->---<]>+. + +++.-----.<<. + >>>.<+++++.<++++[->----<]>-. + <+++[->+++<]>-.+++++. + >++++.<+++++++. + <++++[->----<]>--. + <+++[->+++<]>-. ## Run it From dba7730c0284da77bb62073e423e20f0b3fae1c5 Mon Sep 17 00:00:00 2001 From: Chen Hao Date: Tue, 17 Apr 2018 16:28:48 +0800 Subject: [PATCH 9/9] improve structure --- Language2.md | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/Language2.md b/Language2.md index d6f8234..ed53549 100644 --- a/Language2.md +++ b/Language2.md @@ -11,12 +11,12 @@ `#2 = -1 = 255` if #0 smaller than #1; ``` -########################### perpare compare ########################### [-]>[-]>[-]>[-]>[-]>[-]>[-]<<<<<< // clear #0~#6 - ++++++++ // p0; #0 > +++++++++ // p1; #1 + +########################### perpare compare ########################### <[->>+>+<<<]>>>[-<<<+>>>] // p3; #2 = #0 <<[->>+>+>+<<<<]>>>[-<<<+>>>] // p4; #5 = #3 = #1 + // p4; #4 flag @@ -32,11 +32,12 @@ [-]>>-[->+<<<+>>]>[-<+>] // p6; copy #5 sub 1 to #3 <<<< // p2 ] +<< // p0 ########################### perpare compare ########################### // if flag is set; then #0 smaller than #1; else #0 lager equals #1 // and if #3 equals 0; then #0 equals #2 ->> // p4 +>>>> // p4 -[ // p4; if flag is not set; <[<+>>[-]]<<+>> // p4; then if #3 not 0; then #2 = 2; else #2 = 1; ] @@ -50,10 +51,14 @@ ## min(x, y. min{x,y}): put the min value from #0 and #1 to #2 ``` +[-]>[-]>[-]>[-]>[-]>[-]>[-]<<<<<< // clear #0~#6 +++++++++ // p0; #0 +> ++++++++++ // p1; #1 perpare_compare(#0, #1, #2, #3, #4, #5, #6); // if flag is set; then #0 smaller than #1; else #0 lager equals #1 ->[-]+> // p4; set #3 = 1 +>>>[-]+> // p4; set #3 = 1 [<-<<<[->>+>+<<<]>>>[-<<<+>>>]>[-]] // p4; if flag is set; set #3 = 0; copy #0 to #2; <[-<<[->+>+<<]>>[-<<+>>]] // p3; if #3 = 1; copy #1 to #2 <<< // p0 @@ -66,10 +71,14 @@ perpare_compare(#0, #1, #2, #3, #4, #5, #6); ## max(x, y. max{x,y}): put the max value from #0 and #1 to #2 ``` +[-]>[-]>[-]>[-]>[-]>[-]>[-]<<<<<< // clear #0~#6 +++++++++ // p0; #0 +> ++++++++++ // p1; #1 perpare_compare(#0, #1, #2, #3, #4, #5, #6); // if flag is set; then #0 smaller than #1; else #0 lager equals #1 ->[-]+> // p4; set #3 = 1 +>>>[-]+> // p4; set #3 = 1 [<-<<[->+>+<<]>>[-<<+>>]>[-]] // p4; if flag is set; set #3 = 0; copy #1 to #2; <[-<<<[->>+>+<<<]>>>[-<<<+>>>]] // p3; if #3 = 1; copy #0 to #2 <<< // p0