MODULE check0s; (*--------------------------------------------------------- File name: check0s.pm Author: AG Date: 6/8/05 Problem: Checks if the chain is full of 0s between LeftLimit and RightLimit. LeftLimit = 3 RightLimit = 19 Example of Execution 1: L1: 0 1 2 2 0 0 1 2 1 1 1 2 1 1 0 Res: FALSE Example of Execution 2: L1: 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 Res: TRUE Cycles: 1 Test + 2 assignments. *) (*---------------------------------------------------------- CONFIGURATION ----------------------------------------------------------*) CONST MAXCELLS=1024; (* MAXCELLS cells in one line *) CONFIGURATION chain[0..(MAXCELLS - 1)]; CONNECTION left: chain [i] -> chain[(i-1) MOD MAXCELLS]; right: chain[i] -> chain[(i+1) MOD MAXCELLS]; (*---------------------------------------------------------- VARIABLES ----------------------------------------------------------*) VAR L1: chain OF INTEGER; LeftLimit, RightLimit: INTEGER; Res: BOOLEAN; (*---------------------------------------------------------- MAIN ----------------------------------------------------------*) BEGIN (* Initialize data *) L1 := RandomInt(chain) MOD 3; (* L1 := 0; *) (*define limits *) RightLimit:= 19; LeftLimit := 3; Res:= TRUE; (* Assume it is true *) IF LeftLimit < ID(chain) < RightLimit THEN (* select cells *) IF L1 # 0 THEN (* If we find anything that is not a '0' *) Res:= FALSE; (* then we change it to false *) END; (* IF *) (*printing *) WriteString("L1: "); WriteInt(L1, 2); WriteLn; WriteString("Res: "); WriteBool(Res,0); WriteLn; END; (* IF *) END check0s.