Created
June 17, 2020 09:50
-
-
Save lljxx1/6e5bc5e742ee9d79cb608578fa9a9693 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| 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