%externalroutine elect(%string (255) str) %externalroutinespec define(%string (255) s) %integerarray lab,con,lib(0:63) %integerarray snp,ind,tota, hold(0:63) %integerarray maj,indx(0:63) %ownintegerarray look up(1:62) = %c 57, 4, 3, 16, 55, 17, 27, 53, 30, 62, 29, 5, 37, 24, 56, 54, 12,60, 9, 20, 39, 42, 59, 18, 58, 2, 28, 34, 19, 50, 52, 47, 46, 35, 48, 44, 8, 23, 11, 25, 61, 14, 31, 13, 6, 7, 45, 51, 1, 41, 49, 38, 33, 32, 22, 21, 36, 26, 15, 40, 10, 43 %string (25) %array names(0:63) %ownintegerarray res(1:62, 1:10) %ownbyteintegerarray labl(1:10) = 12, 10, 9, 8, 6, 5, 4, 3, 2, 1 %ownbyteintegerarray conl(1:10) = 16, 14, 12, 10, 8, 6, 5, 4, 3, 2 %ownstring (3) %array ps(1:5) = %c "Lab", "Con", "Lib", "Snp", "Ind" %realarray pc(0:63) %ownreal p1,p2 %owninteger this one %string (255) ss %owninteger i,j,k,l,c,b,num,tot,index,s,n,p,x %owninteger pqs %string (25) %fn read line %string (25) s %integer i s = "" %cycle readsymbol(i) %exit %if i=nl s = s.tostring(i) %repeat %result = s %end %integerfn read cand %integer i,j,k, num num = this one readsymbol(i) %if i='*' %then skipsymbol %and %result = 0 read(j) %unless i = 'p' %if i#'m' %and i#'p' %start tot = tot+j index = index+1 %finish %if i='l' %then lab(num)=j %and k = 1 %if i='c' %then con(num)=j %and k = 2 %if i='b' %then lib(num)=j %and k = 3 %if i='s' %then snp(num)=j %and k = 4 %if i='i' %then ind(num)=j %and k = 5 %if index =1 %then indx(num)=k %if i='m' %then maj(num)=j %if i='p' %start read(pc(num)) %finish skipsymbol %result = 1 %end %routine print name(%integer i) ss = names((i*2)-1)."/".names(i*2) printstring(ss); spaces (45-length(ss)) %end ! %routine print info(%integer x, %integer index) printstring(" !") %unless index = 1 %if index = num %then printstring(" *") %else %c spaces(2) write(x,4); %if index#6 %start print((x*100)/tot, 2, 1) printsymbol('%') %finish %if index = 3 %and (lib(thisone)=0 %or lib(thisone+1)=0) %then %c printsymbol('#') %else space %end %unless str -> ss.("/").str %start printstring("parameters? ") %stop %finish define("1,".ss) define("2,".str) %cycle i = 1, 1, 63 lab(i)=0; con(i)=0; lib(i)=0;snp(i)=0;ind(i)=0 tota(i)=0;maj(i)=0;indx(i)=0 pc(i)=0 %repeat names(i) = "" %for i = 0, 1, 63 select input(1); select output(2) k=0 %cycle %if nextsymbol = '*' %then newlines(5) %and %exit ss = read line index=0;tot=0; num = num+1 pqs = pqs+1 this one = look up(pqs) names(this one) = ss %cycle i = read cand; %exit %if i = 0 %repeat tota(this one)=tot j=0 %repeat newpage PRINTSTRING(" LAB CON LIB SNP IND") PRINTSTRING(" TOTAL MAJ TURN ") %cycle i = 1, 2, 61 printstring(names(i)."/".names(i+1)); newline k = i//2+1 tot = tota(i)+tota(i+1) res(k, 1) = lab(i)+lab(i+1) res(k, 2) = con(i)+con(i+1) res(k, 3) = lib(i)+lib(i+1) res(k, 4) = snp(i)+snp(i+1) res(k, 5) = ind(i)+ind(I+1) res(k, 9) = tot j = int pt((tota(i)*100)/pc(i)) x = int pt((tota(i+1)*100)/pc(i+1)) res(k, 10) = j+x s = 0 %cycle l = 1, 1, 5 %if res(k, l) > s %then s = res(k, l) %and num = l %repeat res(k, 8) = num s = 0 %cycle l = 1, 1, 5 %continue %if l = num %if res(k, l) > s %then s = res(k, l) %and c = l %repeat res(k, 6) = res(k, num)-s res(k, 7) = c; ! who is 2nd printinfo(lab(i)+lab(i+1), 1) printinfo(con(i)+con(i+1), 2) this one = i printinfo(lib(i)+lib(i+1), 3) printinfo(snp(i)+snp(i+1), 4) printinfo(ind(i)+ind(i+1), 5) printinfo(tota(i)+tota(i+1), 6) printinfo(res(k, 6), 7) write(res(k, 10), 7) newlines(2) %repeat newpage %cycle l = 1, 1, 5 printstring(ps(l)); printstring (" held ") printstring(" ward maj % 2nd ") n = 0 %cycle i = 1, 1, 32 hold(i) = 0 %if res(i, 8) = l %start hold(i) = res(i, 6); n = n+1 %finish %repeat %if n > 0 %start %cycle i= 1, 1, n p = 0 %cycle k = 1, 1, 32 %if hold(K) > p %then p = hold(k) %and b = k %repeat printname(b) write(res(b, 6), 5) print((res(b, 6)*100)/res(b, 9), 4, 1); spaces(6) printstring(ps(res(b, 7))) newline hold(b) = 0 %repeat %finish newlines(5) %repeat %cycle i = 1, 1, 62 l = l+lab(i); c = c+con(i) b = b+lib(i); s = s+snp(i) k = k+ind(i) %repeat lab(63) = l; con(63) = c; lib(63) = b snp(63) = s; ind(63) = k num=63 tot = l+c+b+s+k; tota(63)=tot printinfo(lab(63),1);printinfo(con(63),2) printinfo(lib(63),3); printinfo(snp(63),4); printinfo(ind(63),5) printinfo(tota(63),6) newlines(5) printstring("SDP/Liberal wins for an X% drop in vote from both Lab & Con ") hold(i) = 0 %for i = 1, 1, 32 %cycle i = 0, 1, 75; ! swing x = 0 %cycle k = 1, 1, 31 %if hold(k) = 0 %start s = res(k, res(k, 8)); ! winner p1 = (res(k, 1)*i)/100+(res(k, 2)*i)/100 p2 = (s*i)/100 %if p1+res(k, 3) >= s-p2 %start %if x = 0 %start printstring(" Swing ="); write(i, 2) printstring("% ") x = 1 %finish spaces(6); print name(k); printstring(" from ") printstring(ps(res(k, 8))) hold(k) = 1; newline %finish %finish %repeat %repeat newpage printstring("Results for differing % drops in total electorate ") hold(i) = 0 %for i = 1, 1, 32 %cycle i = 10, -1, 1; ! scenario x = 0 %cycle k = 1, 1, 31 %if hold(k) = 0 %start s = res(k, res(k, 8)); ! winner p1 = res(k, 10)*(labl(i)/100); p2 = res(k, 10)*(conl(i)/100) %if p1 > res(k, 1) %then p1 = res(k, 1) %if p2 > res(k, 2) %then p2 = res(k, 2); ! max votes available %if res(k, 8) = 1 %then s = int pt(s-p1) %if res(k, 8) = 2 %then s = int pt(s-p2) %if res(k, 3)+p1+p2 > s %start %if x = 0 %start newlines(3) printstring("lab loses "); write(labl(i), 1); printstring(%c "% and Con loses "); write(conl(i), 1); printstring("% of total elect. ") x = 1 %finish spaces(6); print name(k); printstring(" from ") printstring(ps(res(k, 8))) spaces(10); printstring(" maj =") print(res(k, 3)+p1+p2-s, 4, 0) newline hold(k) = 1 %finish %finish %repeat %repeat newlines(5) j = 0; k=0 %cycle i = 1, 1, 62 %if indx(i) = 1 %then p1=p1+pc(i) %and k=k+1 %if indx(i) = 2 %then p2=p2+pc(i) %and j=j+1 %repeat printstring(" Average turnout in LAB seats was:") print(p1/k, 2, 1); printstring("% Average turnout in CON seats was:") print(p2/j, 2, 1); printstring("% ") b=0;s=0;tot=0;k=0 j=0;l=0 newlines(3) %cycle i = 1, 1, 62 %if lib(i)#0 %start b=b+lib(i); tot=tot+tota(i); j=j+1 %finish %if snp(i)#0 %start s=s+snp(i); k =k+tota(i); l=l+1 %finish %repeat printstring("Average LIB vote in seats they stood in:") print(b/j, 2, 0); print((b*100)/tot, 5, 1); printstring("% Average SNP vote in seats they stood in:") print(s/l, 2, 0); print((s*100)/k, 5, 1); printstring("% ") %end %endoffile