ysilly3es

code for program Decisiveness

program Decisiveness;

uses
Initialize, Reporting;
begin

{pqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpq}

{ Get the provincial and territorial data }

{bdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbd}

GetPaTdata; { see unit Initializing }

{ Talley the number of seats in each house of parliament }

for house := HoC to x3ES do
begin
Total[house] := 0;
for PoT := 1 to nPaTs do
Total[house] := Total[house] + Canada[PoT].seats[house];
end;

{pqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpq}

{ Determine majorities for each house of parliament }

{bdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbd}

for house := HoC to x3ES do
Majority[house] := Total[house] div 2 + 1;

{ Determine the number of 2 party conflicts with this many PaTs }
{ raise 2 to the power of nPaTs -1 }

TotalConflicts := 1;
for PoT := 1 to nPaTs do
TotalConflicts := TotalConflicts * 2;

{pqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpq}

{ start of main loop for each conflict }

{bdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbd}

for conflict := 0 to TotalConflicts – 1 do
{ the first conflict is 0, the compliment of which }
{ corresponds to the case of a unanimous vote result }

begin

{pqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpq}

{ Determine the two camps }

{bdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbd}

{ the strategy is to express the number of the conflict in base two, a numeral of 1’s and 0’s with a }
{ maximum length of nPaTs digits. ie fill in leading zeroes}
{ the positions of each 1 and each zero in the binary numeral are used to define the two teams.}
{ those PoTs whose ordinate in the Dominion type array correspond with a 1 are for a poposal, }
{ those whose ordinate in the array correspond with a 0 are against that proposal. }

straw := conflict; { straw is set equal to the conflict number }
PoT := 1; { start at the first member of the array }
infavour := []; { start with an empty set }

{ for each digit of the binary numeral for the conflict number }
while straw > 0 do
begin

{ if the binary numeral has a one at this position include current PoT in the set }
if odd(straw) then
infavour := infavour + [PoT];

{ increment PoT by one ordinate and halve straw to get to the next digit of the binary number }
PoT := PoT + 1;
straw := straw div 2;
end;

opposed := [1..nPaTs] – infavour;

{pqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpq}

{ Determine margin of victory or defeat in the House of Commons and each 3E Senate }

{bdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbd}

for house := HoC to x3ES do
begin

sumSeats[house] := 0;
for PoT := 1 to nPaTs do
if PoT in infavour then
sumSeats[house] := sumSeats[house] + Canada[PoT].seats[house];

pass[house] := sumSeats[house] >= majority[house];

if pass[house] then

margin[house] := sumSeats[house] – majority[house] { margin of victory }

else
margin[house] := majority[house] – sumSeats[house] – 1; { margin of defeat }

end;

{pqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpq}

{ Tally the wins }

{bdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbd}

for house := HoC to x3ES do
begin

{ determine the winners }

if (pass[HoC] and pass[house]) then
begin
winners := infavour;
passes[house] := passes[house] + 1;
end
else
winners := opposed;

{ talley loop for each province and territory }

for PoT := 1 to nPaTs do
with Canada[PoT] do
if PoT in winners then

begin

{ talley the wins }
wins[house] := wins[house] + 1;

{pqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpq}

{ Tally the instances of decisiveness }

{bdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbd}

{ case of the House of Commons without a 3E senate }

if house = HoC then

if seats[house] > margin[house] then
decisive[house] := decisive[house] + 1;

{ cases for the House of Commons and a 3E senate }

if not (house = HoC) then
begin

{ case of measure failed in House of Commons but passed in 3E Senate }

if (pass[house] and not pass[HoC]) then

if seats[HoC] > margin[HoC] then
decisive[house] := decisive[house] + 1;

{ case of measure failed in 3E Senate but passed in House of Commons }

if (pass[HoC] and not pass[house]) then

if seats[house] > margin[house] then
decisive[house] := decisive[house] + 1;

{ case of measure failed in 3E Senate and House of Commons }

if (not pass[HoC] and not pass[house]) then

if (seats[house] > margin[house]) and (seats[HoC] > margin[HoC]) then
decisive[house] := decisive[house] + 1;

{ case of measure passed in 3E Senate and House of Commons }

if (pass[HoC] and pass[house]) then

if (seats[house] > margin[house]) or (seats[HoC] > margin[HoC]) then
decisive[house] := decisive[house] + 1;

end; { if not (house = HoC) then }

end; { for PoT := 1 to nPaTs do }

end; { for house := HoC to x3ES do }

end; {conflict := 0 to TotalConflicts – 1 do}

ReportResults;

end.

{pqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpq}

{ code for unit Initialize }

{bdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbd}

unit initialize;

interface

const
nPaTs = 13; { number of provinces and territories’}

type
str3 = string[3];
str24 = string[24]

PaTset = 1..nPaTs;
Side = set of PaTset;

HouseType = (HoC, i3ES, x3ES); { HoC = House of Commons }
{ i3ES = triple-E senate that includes territories }
{ x3ES = triple-E senate that excludes territories }

SeatsType = array[HouseType] of integer;

talleyType = array[HouseType] of longint; { for talleying wins and instances of decisiveness }

ProvincesOrTerritories = record
name: str24; { the full name of the province or territory }
shortName: Str3; { 3 character short form identifier of the province or territory }
seats: SeatsType; { number of seats in each house of parliament }
wins: talleyType;
decisive: talleyType;

end;

Dominion = array[1..nPaTs] of ProvincesOrTerritories;
Victory = array[HouseType] of boolean;

var
Canada: Dominion;
PoT, t: integer; { a counter – PoT stands for ‘province or territory’}
Total, Majority, sumSeats, margin: SeatsType;
house, senate: HouseType; { counters }
straw, conflict, TotalConflicts: longint;
winners, infavour, opposed: Side;
passes: talleyType;
j: integer; { number of spaces alotted to columns in chart }
pass: Victory;

procedure GetPaTdata;

implementation

{oioioioioioioioioioioioioiooioiooioioioioioioioioioioioioioioioio}

procedure GetPaTdata;

{oioioioioioioioioioioioioiooioiooioioioioioioioioioioioioioioioio}

var
c, PoT: integer; { a counter – PoT stands for ‘province or territory’}
house: HouseType;

begin
with Canada[1] do
begin
name := ‘Ontario’;
shortName := ‘Ont’;

seats[HoC] := 106;
seats[i3ES] := 1;
seats[x3ES] := 1;

end;

with Canada[2] do
begin
name := ‘Québec’;
shortName := ‘Qué’;

seats[HoC] := 75;
seats[i3ES] := 1;
seats[x3ES] := 1;

end;

with Canada[3] do
begin
name := ‘British Columbia’;
shortName := ‘ BC’;

seats[HoC] := 36;
seats[i3ES] := 1;
seats[x3ES] := 1;

end;

with Canada[4] do
begin
name := ‘Alberta’;
shortName := ‘AB’;

seats[HoC] := 28;
seats[i3ES] := 1;
seats[x3ES] := 1;

end;

with Canada[5] do
begin
name := ‘Manitoba’;
shortName := ‘Man’;

seats[HoC] := 14;
seats[i3ES] := 1;
seats[x3ES] := 1;

end;

with Canada[6] do
begin
name := ‘Saskatchewan’;
shortName := ‘SK’;

seats[HoC] := 14;
seats[i3ES] := 1;
seats[x3ES] := 1;

end;

with Canada[7] do
begin
name := ‘Nova Scotia’;
shortName := ‘NS’;

seats[HoC] := 11;
seats[i3ES] := 1;
seats[x3ES] := 1;

end;

with Canada[8] do
begin
name := ‘New Brunswick’;
shortName := ‘NB’;

seats[HoC] := 10;
seats[i3ES] := 1;
seats[x3ES] := 1;

end;

with Canada[9] do
begin
name := ‘Newfoundland & Labrador’;
shortName := ‘N&L’;

seats[HoC] := 7;
seats[i3ES] := 1;
seats[x3ES] := 1;

end;

with Canada[10] do
begin
name := ‘Prince Edward Island’;
shortName := ‘PEI’;

seats[HoC] := 4;
seats[i3ES] := 1;
seats[x3ES] := 1;

end;

with Canada[11] do
begin
name := ‘Northwest Territories’;
shortName := ‘NWT’;

seats[HoC] := 1;
seats[i3ES] := 1;
seats[x3ES] := 0;

end;

with Canada[12] do
begin
name := ‘Yukon’;
shortName := ‘YK’;

seats[HoC] := 1;
seats[i3ES] := 1;
seats[x3ES] := 0;

end;

with Canada[13] do
begin
name := ‘Nunavut’;
shortName := ‘NV’;

seats[HoC] := 1;
seats[i3ES] := 1;
seats[x3ES] := 0;

end;

{ initialize all talleys to start at 0 }

for PoT := 1 to nPaTs do

for house := HoC to x3ES do
begin
passes[House] := 0;

with Canada[PoT] do
begin
wins[house] := 0;
decisive[house] := 0;

end;
end;

end;

end.

{pqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpq}

{ code for unit Reporting }

{bdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbd}

unit Reporting;
interface

uses
Initialize;

procedure ReportResults;

implementation

{oioioioioioioioioioioioioioioioioioioioioioioioioio}

procedure ReportResults;

{oioioioioioioioioioioioioioioioioioioioioioioioioio}

var
PoT: integer; { counter for provinces or territories }
begin
writeln(‘The number of members is ‘, nPaTs : 0);
writeln(‘The total number of conflicts is ‘, TotalConflicts : 0);
writeln(‘The total number of votes in the House of Commons is ‘, Total[HoC] : 0);
writeln(‘The majority of votes in the House of Commons is ‘, majority[HoC] : 0);
writeln(‘The total number of ways a proposal can pass the House of Commons is ‘, passes[HoC] : 0);
writeln(‘The total number of votes in the inclusive 3E Senate is ‘, Total[i3ES] : 0);
writeln(‘The majority of votes in the inclusive 3E Senate is ‘, majority[i3ES] : 0);
writeln(‘The total number of ways a proposal can pass the House of Commons and inclusive 3E Senate is ‘, passes[i3ES] : 0);
writeln(‘The total number of votes in the exclusive 3E Senate is ‘, Total[x3ES] : 0);
writeln(‘The majority of votes in the exclusive 3E Senate is ‘, majority[x3ES] : 0);
writeln(‘The total number of ways a proposal can pass the House of Commons and exclusive 3E Senate is ‘, passes[x3ES] : 0);

j := 15; { number of spaces alotted to columns in chart }

writeln;
writeln;
writeln(‘Member’ : 18, ‘House of Commons’ : 2 * j, ‘with inclusive 3E Senate’ : 2 * j, ‘with exclusive 3E Senate’ : 2 * j);

write(‘name’ : 18);

write(‘wins’ : j, ‘decisives’ : j);
write(‘wins’ : j, ‘decisives’ : j);
write(‘wins’ : j, ‘decisives’ : j);

writeln;
writeln;

for PoT := 1 to nPaTs do
with Canada[PoT] do
begin
write(name : 18);
write(wins[HoC] : j, decisive[HoC] : j);
write(wins[i3ES] : j, decisive[i3ES] : j);
write(wins[x3ES] : j, decisive[x3ES] : j);
writeln;
end;

end;
end.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: