Skip to content

Instantly share code, notes, and snippets.

@sandiks
Created March 15, 2020 20:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sandiks/6d6269cb93a7aa4c1a271e495ad05ceb to your computer and use it in GitHub Desktop.
Save sandiks/6d6269cb93a7aa4c1a271e495ad05ceb to your computer and use it in GitHub Desktop.
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
namespace Console.MathTester
{
class Program
{
static void Main(string[] args)
{
int N = 1000_000;
var sw = Stopwatch.StartNew();
float[] Accounts = new float[N];
Random randNum = new Random();
for (int i = 0; i < Accounts.Length; i++)
{
Accounts[i] = randNum.Next(10, 100_000);
}
var BaseLevel = (float)Accounts.Sum() / Accounts.Count();
for (int i = 0; i < 100; i++)
{
var surplus = ProcessFatAccounts(Accounts, BaseLevel);
ProcessPoorAccounts(Accounts, BaseLevel, surplus);
System.Console.WriteLine($"[ {i}] снято с жирных счетов #{surplus}");
}
System.Console.WriteLine($"elapsed {sw.Elapsed}");
}
private static float ProcessFatAccounts(float[] Accounts, float BaseLevel)
{
float Sum = 0;
for (int i = 0; i < Accounts.Length; i++)
{
var mm = Accounts[i];
if (mm > BaseLevel)
{
float f = (float)Math.Pow(mm / BaseLevel, 1.3);
if (Accounts[i] - f > BaseLevel)
{
Accounts[i] -= f;
Sum += f;
}
}
}
return Sum;
}
private static void ProcessPoorAccounts(float[] Accounts, float BaseLevel, float Benefits)
{
float SmallAmountLimit(float ff) => ff > 20 ? 20 : ff;
float AllFactors = 0;
for (int i = 0; i < Accounts.Length; i++)
{
var mm = Accounts[i];
if (mm < BaseLevel) AllFactors += SmallAmountLimit(BaseLevel / mm);
}
var AmountToAdd = Benefits / AllFactors;
for (int i = 0; i < Accounts.Length; i++)
{
var mm = Accounts[i];
if (mm < BaseLevel)
{
var f = SmallAmountLimit(BaseLevel / mm) * AmountToAdd;
Accounts[i] += f;
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment