aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIgor <pashev.igor@gmail.com>2010-01-20 13:15:11 +0300
committerIgor <pashev.igor@gmail.com>2010-01-20 13:15:11 +0300
commitde84782edc12c5abe3277d0f162e28fa0033c7d7 (patch)
tree512351c862e7403640b0f55e219028a96028df37
parent8b2047a458e5a4e200c6130893a568797648b9d3 (diff)
downloadbrainfuck-de84782edc12c5abe3277d0f162e28fa0033c7d7.tar.gz
Maximum of 2 numbers
-rw-r--r--max2.bf36
1 files changed, 36 insertions, 0 deletions
diff --git a/max2.bf b/max2.bf
new file mode 100644
index 0000000..f2665d4
--- /dev/null
+++ b/max2.bf
@@ -0,0 +1,36 @@
+# Show the maximum number
+
+# == Preparations ==
+
+# input the 1st number into the 1st cell
+, # |a|0|0|0|0|0|
+
+# copy 1st cell into the 2nd and the 5th cells
+[->+>>>+<<<<] # |0|a|0|0|a|0|
+
+
+# input the 2nd number into the 1st cell
+, # |b|a|0|0|a|0|
+
+# copy 1st cell into the 3nd and the 6th cells
+[->>+>>>+<<<<<] # |0|a|b|0|a|b|
+
+> # move to the 2nd cell
+
+
+
+# == Main loop ==
+
+# decrement both 2nd and 3rd cells by 1,
+# the final position depends on which number is bigger
+[[->]<<]
+
+
+# == Result ==
+# go to the answer
+>>>>
+
+# show the answer
+.
+
+