DEV Community

Discussion on: Can you solve the fastest horse 🐴 algorithm problem?

Collapse
 
3cho0 profile image
3cho0 • Edited

7 races? That doesn't seem right.
Split the 25 horses into 5 arbitrary groups of 5. For each group, determine the fastest horse. Race each group. You now have 5 horses, each the fastest of their group. Race those 5 horses to determine the fastest horse overall - a total of 6 races.

EDIT: I misread the question statement, so the above answer is incorrect. Sorry about that. I would still encourage you to solve my question down below (it's easy and fun!), though it gets a little trickier when you want to know the j fastest horses instead of just the fastest :)

Collapse
 
idanarye profile image
Idan Arye

But you need the top 3, not just the top 1.

Collapse
 
3cho0 profile image
3cho0

Yes. Please read my post and learn from my silly mistakes :)

Collapse
 
3cho0 profile image
3cho0

Another fun, but simple exercise:
Find a closed formula that will answer this question for an arbitrary number of horses k and an arbitrary number of racetracks n.
Hint: Look at cases where n divides k first :)