Created
April 26, 2021 15:50
-
-
Save 0xF6/b692d021aae6f44faae3d59518a6a614 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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