Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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;
float[] acc = new float[N];
Random randNum = new Random();
for (int i = 0; i < acc.Length; i++)
{
acc[i] = randNum.Next(10, 100_000);
}
var base_level = (float)acc.Sum() / acc.Count();
var sw = Stopwatch.StartNew();
for (int i = 0; i < 100; i++)
{
var surplus = ProcessFatAccounts(acc, base_level);
ProcessPoorAccounts(acc, base_level, surplus);
System.Console.WriteLine($"[ {i}] снято с жирных счетов #{surplus}");
}
System.Console.WriteLine($"elapsed {sw.Elapsed}");
}
private static float ProcessFatAccounts(float[] acc, float base_level)
{
float Sum = 0;
for (int i = 0; i < acc.Length; i++)
{
var mm = acc[i];
if (mm > base_level)
{
float f = (float)Math.Pow(mm / base_level, 1.3);
if (acc[i] - f > base_level)
{
acc[i] -= f;
Sum += f;
}
}
}
return Sum;
}
private static void ProcessPoorAccounts(float[] acc, float BaseLevel, float Benefits)
{
float SmallAmountLimit(float ff) => ff > 20 ? 20 : ff;
float AllFactors = 0;
for (int i = 0; i < acc.Length; i++)
{
var mm = acc[i];
if (mm < BaseLevel) AllFactors += SmallAmountLimit(BaseLevel / mm);
}
var AmountToAdd = Benefits / AllFactors;
for (int i = 0; i < acc.Length; i++)
{
var mm = acc[i];
if (mm < BaseLevel)
{
var f = SmallAmountLimit(BaseLevel / mm) * AmountToAdd;
acc[i] += f;
}
}
}
}
}
elapsed 00:00:05.9377225
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.