Skip to content

Instantly share code, notes, and snippets.

@daltonnyx
Created March 16, 2020 09:42
Show Gist options
  • Save daltonnyx/e3ab8be14643fd07db2032e9b847903d to your computer and use it in GitHub Desktop.
Save daltonnyx/e3ab8be14643fd07db2032e9b847903d to your computer and use it in GitHub Desktop.
//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