From 688723b137a91a73cd5372adbc1ef6eecce27a96 Mon Sep 17 00:00:00 2001 From: Bernhard Urban Date: Tue, 18 Oct 2011 15:57:11 +0200 Subject: [PATCH] Initial commit --- 1hw.fs | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 1hw.fs diff --git a/1hw.fs b/1hw.fs new file mode 100644 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 + * ; -- 2.25.1