Mainly Tech projects on Python and Electronic Design Automation.

Thursday, January 21, 2021

The "Balls in a row" challenge

2 comments:

  1. > The challenge is to create a function that given a list of an initial arrangement of balls, returns the total number of balls that can be discarded.

    If this is interpreted to mean "the most number of balls that can be discarded", then all of the solutions presented have a bug, because they're all greedy algorithms.

    E.g. consider the sequence

    [0, 1, 1, 1, 0, 0, 0, 1, 1]

    If it starts from the left, it can discard 3x1 and then 4x0 for a total of seven. But if it starts from the right it can discard 3x0 and then 5x1 for a total of eight. An algorithm to find the *maximum* number of balls to discard must consider different discard orders. (I'm not sure how difficult that is, but it smells NP-complete.)

    ReplyDelete
  2. Updated the description to explicitly state "from the left" - thanks.

    ReplyDelete

Followers

Subscribe Now: google

Add to Google Reader or Homepage

Go deh too!

whos.amung.us

Blog Archive