458.poor-pigs.go 289 B

12345
  1. func poorPigs(buckets int, minutesToDie int, minutesToTest int) int {
  2. base := minutesToTest/minutesToDie + 1 // Status of a pig: die at x min or still alive
  3. // So the number of pigs is log(buckets)/log(base)
  4. return int(math.Ceil(math.Log(float64(buckets)) / math.Log(float64(base))))
  5. }