Create new denomination distribution algorithm for Money activities
Open, Needs TriagePublic

Description

Current algorithm used to distribute the costs over a certain number of items has some bugs which results in the last item having the cost of 0 or -ve.

Further, taking the future of localised dataset, we are looking to create an algorithm which can handle the distributions of any denominations for any locale.

amankumargupta created this task.EditedFeb 13 2021, 8:18 PM

C++ code for the new algorithm using the concept of bitmask: https://onlinegdb.com/zXI75Kivi

Please start reading the code from line 92. Everything before that is the template I use for algorithmic competitions, and is unrelated to the implementation of this algorithm.

Some sample tests are mentioned at the bottom of the code as comment. You can run the code on any online/offline platform and provide various inputs to test and verify,

It does the job in under 200 milliseconds on my mac. But, if it takes longer time on weak processing devices, you can reduce the value of "optimisingDenominationCountThreshold" variable on line 147, and it will automatically tune and improve the performance,