| Bytes | Lang | Time | Link |
|---|---|---|---|
| 458 | Python3 | 250504T180556Z | Ajax1234 |
| 097 | Charcoal | 250503T205147Z | Neil |
Python3, 458 bytes
E=enumerate
def f(b):
q,s=[(b,0)],[b]
while q:
q=sorted(q,key=lambda x:len(x[0]))
b,c=q.pop(0)
if len(b)==1:return 1
v=[x for i,a in E(b[:-1])for x in[i,i+1]if -a==b[i+1]]
Q=[([a for i,a in E(b)if i not in v],0),(b[1:]+b[:1],c),([[i,[1,-1][i==1]][i==1]for i in b],c),([{1:2,2:1,-1:-2,-2:-1}[i]for i in b],c)]
if 0==c:Q+=[([j for i in b for j in[[[-2,-1],[1,2]][i==1],[i]][abs(i)!=1]],1)]
for X,Y in Q:
if X and X not in s:q+=[(X,Y)];s+=[X]
Charcoal, 97 bytes
⊞υθFυF…±²¦³F∧κ÷⟦²±²⟧κ«≔⟦⟧ηFι≡μκ⊞⊞Oηκ±λ±κ⊞⊞Oηλ±κ⊞ημW⌊Φη⁼ν±§η⊕ξ≔Φη∨⁻↔μ↔ν⁺ν§η⎇⁼μν⊕ξ⊖ξηP⁼¹Lη¿‹LηLι⊞υη
Try it online! Link is to verbose version of code. Outputs a Charcoal boolean, i.e. - for primitive, nothing if not. Explanation: Performs an exhaustive greedy search, which the hints suggest is a valid approach.
⊞υθFυ
Perform a search for moves that reduce the length of the list.
F…±²¦³F∧κ÷⟦²±²⟧κ«
Applying moves 5. 2. and 1. might reduce the length of the list if there are enough occurrences of 1, -2 and/or 2, -1, but there are other options via moves 3. and 4. as listed below.
≔⟦⟧ηFι≡μκ⊞⊞Oηκ±λ±κ⊞⊞Oηλ±κ⊞ημ
Apply move 5. (and moves 3. and 4. where applicable) to the list.
W⌊Φη⁼ν±§η⊕ξ≔Φη∨⁻↔μ↔ν⁺ν§η⎇⁼μν⊕ξ⊖ξη
Apply moves 2. and 1. to delete all cyclically adjacent negations. (Normally these are only the ones introduced by move 5. but on the first pass there may be some bonus adjacencies in the input; applying move 5. doesn't affect them since e.g. 1, -1 becomes 1, 2, -2, -1 and so the original 1, -1 will collapse anyway. As this is code-golf I put off the cyclic reduction until this point as I can use it to clean up after move 5. as well.)
P⁼¹Lη
Note whether this identifies the original list as being primitive.
¿‹LηLι⊞υη
If this resulted in a shorter list then push it to the search list. (This only applies one of the relevant hints but it would be less golfy to apply the other one.)
Rule combinations and their effects:
5.2.1.Tries to delete2before-1or-2after1.3.5.2.1.3.Tries to delete2before1or-2after-1.4.5.2.1.4.Tries to delete1before-2or-1after2.4.3.5.2.1.3.4.Tries to delete1before2or-1after-2.3.4.5.2.1.4.3.Tries to delete-1before-2or1after2.3.4.3.5.2.1.3.4.3.Tries to delete-1before2or1after-2.4.3.4.5.2.1.4.3.4.Tries to delete-2before-1or2after1.4.3.4.3.5.2.1.3.4.3.4.Tries to delete-2before1or2after-1. (Same as3.4.3.4.5.2.1.4.3.4.3.)