e6275d51d35eadea8a9fdb897a8ed4f6169f3da4
[sbs.git] / 1hw.fs
1 \ ============================== 3.6 =========================================
2
3 \          Given:          How do you get:
4 \          1 2 3           3 2 1
5 : ass36.1.1 1 2 3 rot rot swap .s 2drop drop ;
6
7 \          1 2 3           1 2 3 2
8 : ass36.1.2 1 2 3 over .s 2drop 2drop ;
9
10 \          1 2 3           1 2 3 3
11 : ass36.1.3 1 2 3 dup .s 2drop 2drop ;
12
13 \          1 2 3           1 3 3
14 : ass36.1.4 1 2 3 swap drop dup .s 2drop drop ;
15
16 \          1 2 3           2 1 3
17 : ass36.1.5 1 2 3 rot swap .s 2drop drop ;
18
19 \          1 2 3 4         4 3 2 1
20 : ass36.1.6 1 2 3 4 swap 2swap swap ;
21
22 \          1 2 3           1 2 3 1 2 3
23 \          1 2 3 4         1 2 3 4 1 2
24 \          1 2 3
25 \          1 2 3           1 2 3 4
26 \          1 2 3           1 3
27
28
29 \ Assignment: Write 17^3 and 17^4 in Forth, without writing 17 more than once.
30 \ Write a piece of Forth code that expects two numbers on the stack (a and b,
31 \ with b on top) and computes (a-b)(a+1). 
32
33 : ass36.2 17 dup dup * * ;
34 : ass36.3 17 dup 2dup * * * ;
35 : ass36.4 ( a b -- erg)
36         over swap - swap 1 + * ;