Skip to content

Instantly share code, notes, and snippets.

@0xF6
Created April 26, 2021 15:50
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 0xF6/b692d021aae6f44faae3d59518a6a614 to your computer and use it in GitHub Desktop.
Save 0xF6/b692d021aae6f44faae3d59518a6a614 to your computer and use it in GitHub Desktop.
var rarity = new [] { 5000, 2000, 1000, 500, 100 };
int[] dispenser_action(int sum)
{
if (sum % rarity.OrderBy(x => x).First() != 0)
throw new Exception();
var result = new List<int>();
foreach (var r in rarity)
{
var x = (sum - (sum % r)) / r;
result.AddRange(Enumerable.Range(0, x).Select(_ => r));
sum -= r * x;
if (sum == 0) break;
}
return result.ToArray();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment