Skip to content

Instantly share code, notes, and snippets.

@lljxx1
Created June 17, 2020 09:50
Show Gist options
  • Select an option

  • Save lljxx1/6e5bc5e742ee9d79cb608578fa9a9693 to your computer and use it in GitHub Desktop.

Select an option

Save lljxx1/6e5bc5e742ee9d79cb608578fa9a9693 to your computer and use it in GitHub Desktop.
const typeReturn = {
498: 80,
320: 60,
245: 40
}
// var Combinatorics = require('js-combinatorics');
// Combinatorics.permutation([498, 320, 245]).toArray();
const allChoices = [
[498, 320, 245],
[498, 245, 320],
[320, 498, 245],
[320, 245, 498],
[245, 320, 498],
[245, 498, 320]
];
const state = {};
const steps = [498, 320, 245];
function getChoinceSpend(choices) {
let totalSpend = 0;
let rewardTotal = 0;
choices.forEach(price => {
let needSpend = 0;
let r = typeReturn[price];
if(rewardTotal > 0 ){
needSpend = price - rewardTotal;
rewardTotal = 0;
} else{
needSpend = price;
}
const num = Math.floor(needSpend / 100);
const reward = num * r;
totalSpend += needSpend;
if(needSpend > 0) {
rewardTotal += reward;
}
// console.log({
// num,
// reward,
// needSpend,
// rewardTotal
// });
})
console.log({
totalSpend,
rewardTotal
}, choices.join('-'))
}
// getChoinceSpend(allChoices[1])
allChoices.forEach(_ => {
getChoinceSpend(_);
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment