<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">% 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 &gt; 0 \land n &gt; 0}
\[\glocon m, n; \virvar gcd
  ; \privar i, j
  ; i \vir int, j \vir int \:= m, n
  ; \do i \not= j \-&gt;\IF i &gt; j \-&gt; i \:= i - j
                     \| j &gt; i \-&gt; 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 &lt; q}
; \privar u, v
; d \vir int \array, u \vir int, v \vir int \:= (1), 10, n*10
; \do u \div 2 &lt; v  \mand  u \le q \-&gt;\&amp;%
                                  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 &lt; v \-&gt; d:hiext.\bigl((v + q \div 2) \div q\bigr)%
  \| v \le u \div 2 \-&gt; 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 &gt; j \-&gt; i \:= i - j
     \| i &lt; j \-&gt; 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) \-&gt; i \:= i - 1\od
  ; j\vir int \:= c.hib;\;\do c.j \le c.i \-&gt; j \:= j-1 \od
  ; c:swap.(i,j)
  ; i \:= i+1; j \:= c.hib;
  ; \do i &lt; j \-&gt; 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 \-&gt; \[ \glovar buck, r, w, b; \pricon col
                ; col \vir colour \:= buck.w 
                ; \IF col = red \-&gt; buck:swap.(r,w); r := r+1
		   \| col = white \-&gt; w \:= w-1
		   \| col = blue \-&gt; buck:swap.(w,b); w,b \:= w-1, b-1
		  \FI 
	       \]
   \od
\]
\eblock
\bye
</pre></body></html>