Initial commit
authorBernhard Urban <lewurm@gmail.com>
Tue, 18 Oct 2011 13:57:11 +0000 (15:57 +0200)
committerBernhard Urban <lewurm@gmail.com>
Tue, 18 Oct 2011 13:57:11 +0000 (15:57 +0200)
1hw.fs [new file with mode: 0644]

diff --git a/1hw.fs b/1hw.fs
new file mode 100644 (file)
index 0000000..e6275d5
--- /dev/null
+++ b/1hw.fs
@@ -0,0 +1,36 @@
+\ ============================== 3.6 =========================================
+
+\          Given:          How do you get:
+\          1 2 3           3 2 1
+: ass36.1.1 1 2 3 rot rot swap .s 2drop drop ;
+
+\          1 2 3           1 2 3 2
+: ass36.1.2 1 2 3 over .s 2drop 2drop ;
+
+\          1 2 3           1 2 3 3
+: ass36.1.3 1 2 3 dup .s 2drop 2drop ;
+
+\          1 2 3           1 3 3
+: ass36.1.4 1 2 3 swap drop dup .s 2drop drop ;
+
+\          1 2 3           2 1 3
+: ass36.1.5 1 2 3 rot swap .s 2drop drop ;
+
+\          1 2 3 4         4 3 2 1
+: ass36.1.6 1 2 3 4 swap 2swap swap ;
+
+\          1 2 3           1 2 3 1 2 3
+\          1 2 3 4         1 2 3 4 1 2
+\          1 2 3
+\          1 2 3           1 2 3 4
+\          1 2 3           1 3
+
+
+\ Assignment: Write 17^3 and 17^4 in Forth, without writing 17 more than once.
+\ Write a piece of Forth code that expects two numbers on the stack (a and b,
+\ with b on top) and computes (a-b)(a+1). 
+
+: ass36.2 17 dup dup * * ;
+: ass36.3 17 dup 2dup * * * ;
+: ass36.4 ( a b -- erg)
+       over swap - swap 1 + * ;