Created
March 16, 2020 09:42
-
-
Save daltonnyx/e3ab8be14643fd07db2032e9b847903d 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
//Give level and quantity of dragon you want to merge | |
//Calculate number of level 1 dragon you need to reach it. | |
//Knowning merging 3 lower level dragons will get 1 dragon which has higher 1 level. | |
//Merging 5 lower level will get 2 dragons which have higher 1 level. | |
function numOfDragon(level, quantity) { | |
if(level == 0) return 0; | |
else if(level == 1) return 1 * quantity; | |
if(quantity % 2 == 0) { | |
return numOfDragon(level - 1, quantity / 2 * 5); | |
} | |
else { | |
return numOfDragon(level - 1, (quantity - 1) / 2 * 5 + 3); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment