Created
June 25, 2022 00:16
-
-
Save germanescobar/32bf01a5074b72ef45fc0c88eeac13c3 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
var earliestFullBloom = function(plantTime, growTime) { | |
console.log(plantTime, growTime) | |
if (plantTime.every(e => e === 0) && growTime.every(e => e === 0)) { | |
return 1 | |
} | |
if (plantTime.every(e => e === 0)) { | |
const max = Math.max(...growTime) | |
console.log("max: " + max) | |
return max | |
} | |
let minDays = Infinity | |
for (let i=0; i < plantTime.length; i++) { | |
let days = Infinity; | |
if (plantTime[i] !== 0) { | |
plantTime[i]-- | |
days = earliestFullBloom(plantTime, growTime) + 1 | |
console.log(`Days for seed ${i}: ${days}`) | |
plantTime[i]++ | |
} else { | |
if (growTime[i] > 0) { | |
days = growTime[i] | |
growTime[i] = 0 | |
} | |
} | |
if (days < minDays) { | |
minDays = days | |
} | |
} | |
return minDays | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
No funciona :(