Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save sivachaitanya/58c95022c4d51e6e2dcd730c257dfd26 to your computer and use it in GitHub Desktop.
Save sivachaitanya/58c95022c4d51e6e2dcd730c257dfd26 to your computer and use it in GitHub Desktop.
Max fee that miner can earn - 14.348
Description - Max fee that miner can earn - 14.348
Code -
using System;
using System.Collections.Generic;
using System.Linq;
public class Program
{
public static void Main()
{
const int target = 1000000;
int[] numbers = new int[] { 57247, 98732, 134928, 77275, 29240, 15440, 70820, 139603, 63718, 143807, 190457, 40572 };
double[] btc_fee = new double[] {0.0887, 0.1856, 0.2307, 0.1522, 0.0532, 0.0250, 0.1409, 0.2541, 0.1147, 0.2660, 0.2933, 0.0686};
List<double> calculated_costs = new List<double>();
int i = 0;
var result = GetCombinations(numbers, target, "");
foreach (string subset in result) {
// calculate the btc fee cost as well
string[] nums = subset.Split(new string[] { "," }, StringSplitOptions.None);
double total = 0;
foreach(string tx in nums){
var index = Array.IndexOf(numbers, Int32.Parse(tx));
total = total + btc_fee[index] ;
calculated_costs.Add(total);
}
Console.WriteLine(subset + "total = "+total);
i++;
}
Console.WriteLine("Number of Combinations: " + result.Count());
Console.WriteLine("Max fee value calculated = "+calculated_costs.Max());
Console.WriteLine("Total BTC fee for the miner = 12.5 + "+calculated_costs.Max()+" = "+ (12.5 + calculated_costs.Max()));
}
public static IEnumerable<string> GetCombinations(int[] set, int sum, string values)
{
for (var i = 0; i < set.Length; i++)
{
var left = sum - set[i];
var vals = (values != "") ? set[i].ToString() + "," +values : set[i].ToString();
if (left < 0) yield return vals;
else
{
int[] possible = set.Take(i).Where(n => n <= sum).ToArray();
if (possible.Length <= 0) continue;
foreach (string s in GetCombinations(possible, left, vals)) yield return s;
}
}
}
}// end of program
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment