summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/doc/generic/tex-ewd/t1.tex
blob: 1f69f3680112b59dd4a4b57768054cd8dadd4fc5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
% This software is licensed to you under the terms of a BSD-style license,
% see bsdlic.txt for details.
% This file demonstrates usage of the dotnot macros.
\input dotnot
\headline{\bf \title}
\def\title{\centerline{Usage of dotnot}}
\def\out{\hbox{\it out:\/}}

The greatest common denominator:
\bblock
\cofl{m > 0 \land n > 0}
\[\glocon m, n; \virvar gcd
  ; \privar i, j
  ; i \vir int, j \vir int \:= m, n
  ; \do i \not= j \->\IF i > j \-> i \:= i - j
                     \| j > i \-> j \:= j - i
                     \FI 
    \od
  ; gcd \vir int \:= i
\] \co{gcd = \gcd.(n, m)}
\eblock
This is the outcome of p0:
\bblock
\out\;\[\glocon n, q; \virvar d
\cofl{0 \le n < q}
; \privar u, v
; d \vir int \array, u \vir int, v \vir int \:= (1), 10, n*10
; \do u \div 2 < v  \mand  u \le q \->\&%
                                  d:hiext.\bigl((v + u \div 2 - 1) \div q\bigr)
                                ; u, v \:= 10*u, (v - d.high*q)*10 \decind
   \od
; \IF u \div 2 < v \-> d:hiext.\bigl((v + q \div 2) \div q\bigr)%
  \| v \le u \div 2 \-> skip   % use `%' to combine several input lines
                                  % into one output line
  \FI
\] \co{\hbox{$d$ contains the decimal digits of $n/q$}}
\eblock
An alternative program to compute the greatest common denominator:
\bblock
\[\glocon m, n; \virvar gcd
   ;\privar i, j
   ;i \vir int, j \vir int \:= m, n
   ;\do i > j \-> i \:= i - j
     \| i < j \-> j \:= j - i
    \od
   ;gcd \vir int \:= (i + j) \div 2
\]
\eblock
This program computes the next higher permutation of c.
\bblock
\[ \glovar c; \privar i,j
  ; i\vir int \:= c.hib -1;\;\do c.i \ge c.(i+1) \-> i \:= i - 1\od
  ; j\vir int \:= c.hib;\;\do c.j \le c.i \-> j \:= j-1 \od
  ; c:swap.(i,j)
  ; i \:= i+1; j \:= c.hib;
  ; \do i < j \-> c:swap.(i,j); i,j \:= i+1,j-1 \od
\]
\eblock
And this is the famous Dutch flag program:
\bblock
\[ \glovar buck; \glocon n; \privar r, w, b
 ; r \vir int, w \vir int, b\vir int \:= 1, n,n
 ; \do w \ge r \-> \[ \glovar buck, r, w, b; \pricon col
                ; col \vir colour \:= buck.w 
                ; \IF col = red \-> buck:swap.(r,w); r := r+1
		   \| col = white \-> w \:= w-1
		   \| col = blue \-> buck:swap.(w,b); w,b \:= w-1, b-1
		  \FI 
	       \]
   \od
\]
\eblock
\bye