The Ship of Theseus is an old question that goes something like:
If a ship has had all of its original parts replaced, is it still the same ship?
For this golf, we're going to slowly replace "parts" on a "ship", and see how long it takes to get a whole new ship.
Task
A ship is comprised of at least two parts. The parts are given as an array of positive (non-zero) integers, representing the part's condition.
On each cycle, randomly choose one part from the list in a uniform fashion. That part's condition will be reduced by one. When a part's condition reaches zero, it is replaced by a new part. The new part starts with the same condition value as the original did.
On the first cycle where all parts have been replaced (at least) once, stop and output the number of cycles it took.
For example (assume I'm choosing parts randomly here):
2 2 3 <- starting part conditions (input)
2 1 3 <- second part reduced
2 1 2 ...
2 1 1
2 2 1 <- second part reduced to zero, replaced
1 2 1
1 2 3 <- third part replaced
1 1 3
2 1 3 <- first part replaced
Output for this example would be 8
, since it took eight cycles for all parts to be replaced. Exact output should differ for each run.
I/O
The only input is the list/array of integers for part condition. The only output is a number of cycles. You can take/give these values in any of the usual ways: STDIO, function arguments/returns, etc.
Test Cases
Since output is not fixed, you could use whatever you want to test, but here's a couple for standardization purposes:
1 2 3 4
617 734 248 546 780 809 917 168 130 418
19384 74801 37917 81706 67361 50163 22708 78574 39406 4051 78099 7260 2241 45333 92463 45166 68932 54318 17365 36432 71329 4258 22026 23615 44939 74894 19257 49875 39764 62550 23750 4731 54121 8386 45639 54604 77456 58661 34476 49875 35689 5311 19954 80976 9299 59229 95748 42368 13721 49790