Skip to content

Commit

Permalink
Add WWI Example
Browse files Browse the repository at this point in the history
  • Loading branch information
nopara73 committed Dec 8, 2020
1 parent 3855077 commit 1d37930
Show file tree
Hide file tree
Showing 60 changed files with 24,982 additions and 0 deletions.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net5</TargetFramework>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\AmountOrganization\AmountOrganization.csproj" />
</ItemGroup>

</Project>
46 changes: 46 additions & 0 deletions AmountOrganization/AmountOrganization.WWI/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
using System;
using System.Linq;
using AmountOrganization;
using AmountOrganization.WWI;

Console.WriteLine("Hello World!");

var inputs = 50;
var users = 40;

var randomAmounts = Sample.Amounts.GetRandomElements(inputs);
var groups = randomAmounts.RandomGroups(users).ToArray();

var outputCount = 0;
IMixer mixer = new WwiMixer();
var mix = mixer.CompleteMix(groups);
foreach (var userOutputs in mix)
{
outputCount += userOutputs.Count();
Console.ForegroundColor = ConsoleColor.Green;
Console.Write($"{userOutputs.Sum()}\t");
Console.ForegroundColor = ConsoleColor.White;
Console.WriteLine($"{string.Join(", ", userOutputs.OrderByDescending(x => x))}");
Console.WriteLine();
}

foreach (var (value, count) in mix
.SelectMany(x => x).GroupBy(x => x)
.ToDictionary(x => x.Key, y => y.Count())
.Select(x => (x.Key, x.Value))
.OrderBy(x => x.Key))
{
if (count == 1)
{
Console.ForegroundColor = ConsoleColor.Red;
}
Console.WriteLine($"There are {count} occurrences of {value} BTC output.");
Console.ForegroundColor = ConsoleColor.White;
}

Console.WriteLine();
Console.WriteLine($"Number of users:\t{users}");
Console.WriteLine($"Number of inputs:\t{inputs}");
Console.WriteLine($"Number of outputs:\t{outputCount}");

Console.ReadLine();
29 changes: 29 additions & 0 deletions AmountOrganization/AmountOrganization.WWI/WwiMixer.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AmountOrganization.WWI
{
public class WwiMixer : IMixer
{
public IEnumerable<ulong> Mix(IEnumerable<ulong> myInputs, IEnumerable<ulong> othersInputs)
{
var remaining = myInputs.Sum();
for (int i = 0; i < 50; i++)
{
var denom = (ulong)Math.Pow(2, i);
if (denom > remaining)
{
yield return remaining;
break;
}

yield return denom;

remaining -= denom;
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
{
"runtimeTarget": {
"name": ".NETCoreApp,Version=v5.0",
"signature": ""
},
"compilationOptions": {},
"targets": {
".NETCoreApp,Version=v5.0": {
"AmountOrganization.WWI/1.0.0": {
"dependencies": {
"AmountOrganization": "1.0.0"
},
"runtime": {
"AmountOrganization.WWI.dll": {}
}
},
"AmountOrganization/1.0.0": {
"runtime": {
"AmountOrganization.dll": {}
}
}
}
},
"libraries": {
"AmountOrganization.WWI/1.0.0": {
"type": "project",
"serviceable": false,
"sha512": ""
},
"AmountOrganization/1.0.0": {
"type": "project",
"serviceable": false,
"sha512": ""
}
}
}
Binary file not shown.
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"runtimeOptions": {
"additionalProbingPaths": [
"C:\\Users\\user\\.dotnet\\store\\|arch|\\|tfm|",
"C:\\Users\\user\\.nuget\\packages",
"C:\\Program Files\\dotnet\\sdk\\NuGetFallbackFolder"
]
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"runtimeOptions": {
"tfm": "net5.0",
"framework": {
"name": "Microsoft.NETCore.App",
"version": "5.0.0"
}
}
}
Binary file not shown.
Binary file not shown.
Loading

0 comments on commit 1d37930

Please sign in to comment.