Calculating total slots
05AB1E, 22 bytes
v¯R¬yQiõˆ}2£yåiˆ}yˆ}¯g
Try it online or verify all test cases.
Explanation:
v # Loop over the integers `y` of the (implicit) input-list:
¯R # Push the global_array, and reverse it
¬ # Get the first item (without popping the reversed global_array itself)
yQi } # If it's equal to the integer `y`:
õˆ # Add an empty string to the global_array
2£ # Then only leave the first 2 items of the reversed global_array
yåi } # If the integer `y` is in these first 2 items:
ˆ # Add the (implicit) input-list to the global_array
yˆ # And push the integer `y` itself to the global_array
}¯g # After the loop: push the global array, and then pop and push its length
# (which is output implicitly as result)
Brachylog, 10 bytes
It's always nice to see problem where Brachylog performs best
⊆Is₃ᶠ≠ᵐ∧Il
Explanation
⊆I # Find the minimal ordered superset of the input (and store in I) where:
s₃ᶠ # each substring of length 3
≠ᵐ # has only distinct numbers
∧Il # and output the length of that superset
Try it online!
R, 123 bytes
`-`=nchar;x=scan(,'');while(x!=(y=gsub("([^,]+),(([^,]*,){0,1})\\1(,|$)","\\1,\\2,\\1\\4",x)))x=y;-gsub("[^,]","",y)+(-y>1)
Try it online - single program!
Try it online - multiple examples!
A full program that reads a comma-separated list of integers as the input, and outputs the slots needed. I’m sure this could be golfed some more, and implementing this regex-based solution in some other languages would be more efficient in bytes.
Note on the second TIO I’ve wrapped it in a function to permit multiple examples to be shown. This function also shows the final list, but this is not output my the main program if run in isolation.