How to resolve the algorithm Fairshare between two and more step by step in the XPL0 programming language
How to resolve the algorithm Fairshare between two and more step by step in the XPL0 programming language
Table of Contents
Problem Statement
The Thue-Morse sequence is a sequence of ones and zeros that if two people take turns in the given order, the first persons turn for every '0' in the sequence, the second for every '1'; then this is shown to give a fairer, more equitable sharing of resources. (Football penalty shoot-outs for example, might not favour the team that goes first as much if the penalty takers take turns according to the Thue-Morse sequence and took 2^n penalties) The Thue-Morse sequence of ones-and-zeroes can be generated by:
Use this method:
Counting from zero; using a function/method/routine to express an integer count in base b, sum the digits modulo b to produce the next member of the Thue-Morse fairshare series for b people.
Show the first 25 terms of the fairshare sequence:
Let's start with the solution:
Step by Step solution about How to resolve the algorithm Fairshare between two and more step by step in the XPL0 programming language
Source code in the xpl0 programming language
proc Fair(Base); \Show first 25 terms of fairshare sequence
int Base, Count, Sum, N, Q;
[RlOut(0, float(Base)); Text(0, ": ");
for Count:= 0 to 25-1 do
[Sum:= 0; N:= Count;
while N do
[Q:= N/Base;
Sum:= Sum + rem(0);
N:= Q;
];
RlOut(0, float(rem(Sum/Base)));
];
CrLf(0);
];
[Format(3,0);
Fair(2); Fair(3); Fair(5); Fair(11);
]
You may also check:How to resolve the algorithm Real constants and functions step by step in the BASIC256 programming language
You may also check:How to resolve the algorithm XML/DOM serialization step by step in the J programming language
You may also check:How to resolve the algorithm Logical operations step by step in the OpenEdge/Progress programming language
You may also check:How to resolve the algorithm Doubly-linked list/Element insertion step by step in the Oz programming language
You may also check:How to resolve the algorithm Set step by step in the Simula programming language