Fairshare between two and more: Difference between revisions
Content added Content deleted
(→{{header|Ruby}}: added another translation) |
No edit summary |
||
Line 797: | Line 797: | ||
With 50000 people: 1 |
With 50000 people: 1 |
||
With 50001 people: Only 50000 have a turn</pre> |
With 50001 people: Only 50000 have a turn</pre> |
||
=={{header|Delphi}}== |
|||
{{works with|Delphi|6.0}} |
|||
{{libheader|SysUtils,StdCtrls}} |
|||
<syntaxhighlight lang="Delphi"> |
|||
procedure DoFairshare(Memo: TMemo; Base: integer); |
|||
{Display 25 fairshare sequence items} |
|||
var I, N, Sum: integer; |
|||
var S: string; |
|||
begin |
|||
S:=Format('Base - %2d: ',[Base]); |
|||
for I:= 0 to 25-1 do |
|||
begin |
|||
N:= I; Sum:= 0; |
|||
while N>0 do |
|||
begin |
|||
Sum:= Sum + (N mod Base); |
|||
N:= N div Base; |
|||
end; |
|||
S:=S+' '+IntToStr(Sum mod Base); |
|||
end; |
|||
Memo.Lines.Add(S); |
|||
end; |
|||
procedure ShowFairshare(Memo: TMemo); |
|||
begin |
|||
DoFairshare(Memo,2); |
|||
DoFairshare(Memo,3); |
|||
DoFairshare(Memo,5); |
|||
DoFairshare(Memo,11); |
|||
end; |
|||
</syntaxhighlight> |
|||
{{out}} |
|||
<pre> |
|||
Base - 2: 0 1 1 0 1 0 0 1 1 0 0 1 0 1 1 0 1 0 0 1 0 1 1 0 0 |
|||
Base - 3: 0 1 2 1 2 0 2 0 1 1 2 0 2 0 1 0 1 2 2 0 1 0 1 2 1 |
|||
Base - 5: 0 1 2 3 4 1 2 3 4 0 2 3 4 0 1 3 4 0 1 2 4 0 1 2 3 |
|||
Base - 11: 0 1 2 3 4 5 6 7 8 9 10 1 2 3 4 5 6 7 8 9 10 0 2 3 4 |
|||
Elapsed Time: 4.753 ms. |
|||
</pre> |
|||
=={{header|Draco}}== |
=={{header|Draco}}== |