APL(Dyalog Unicode), (削除) (削除ここまで)56 bytes SBCS
Assume ⎕io←0
A three-traintacit train that takes a three-dimensional array where time is the leading axis and outputs B and S in a nested array.
(⊂1 3)⌷((⍳4),∘,2⊥ ̈2,⌿⊢){⊂∪⍵~9}⌸(4⌿9),∘, ̄1↓{+/,⍵}⌺1 3 3-⊢
(⊂1 3)⌷((⍳4),∘,2⊥ ̈2,⌿⊢){⊂∪⍵~9}⌸(4⌿9),∘, ̄1↓{+/,⍵}⌺1 3 3-⊢
, ̄1↓{+/,⍵}⌺1 3 3-⊢ 1. ravelled adjacent counts, with the last iteration removed
(4⌿9),∘ 2. prepend 1. with 9 9 9 9
( ,2⊥ ̈2,⌿⊢) 3. ravelled encoded state transitions, with 0->0 as 0, 0->1 as 1, and so on.
((⍳4),∘ ) 4. prepend 3. with 0 1 2 3
{⊂∪⍵~9}⌸ 5. group 2. by 4. and discard 9
(⊂1 3)⌷ 6. take the 2nd and the 4th items in 5
We do 2. and 4. to sort the output of 5. and to deal with potential empty B and S.
APL(Dyalog Unicode), (削除) (削除ここまで)56 bytes SBCS
Assume ⎕io←0
A three-train that takes a three-dimensional array where time is the leading axis and outputs B and S in a nested array.
(⊂1 3)⌷((⍳4),∘,2⊥ ̈2,⌿⊢){⊂∪⍵~9}⌸(4⌿9),∘, ̄1↓{+/,⍵}⌺1 3 3-⊢
(⊂1 3)⌷((⍳4),∘,2⊥ ̈2,⌿⊢){⊂∪⍵~9}⌸(4⌿9),∘, ̄1↓{+/,⍵}⌺1 3 3-⊢
, ̄1↓{+/,⍵}⌺1 3 3-⊢ 1. ravelled adjacent counts, with the last iteration removed
(4⌿9),∘ 2. prepend 1. with 9 9 9 9
( ,2⊥ ̈2,⌿⊢) 3. ravelled encoded state transitions, with 0->0 as 0, 0->1 as 1, and so on.
((⍳4),∘ ) 4. prepend 3. with 0 1 2 3
{⊂∪⍵~9}⌸ 5. group 2. by 4. and discard 9
(⊂1 3)⌷ 6. take the 2nd and the 4th items in 5
We do 2. and 4. to sort the output of 5. and to deal with potential empty B and S.
APL(Dyalog Unicode), (削除) (削除ここまで)56 bytes SBCS
Assume ⎕io←0
A tacit train that takes a three-dimensional array where time is the leading axis and outputs B and S in a nested array.
(⊂1 3)⌷((⍳4),∘,2⊥ ̈2,⌿⊢){⊂∪⍵~9}⌸(4⌿9),∘, ̄1↓{+/,⍵}⌺1 3 3-⊢
(⊂1 3)⌷((⍳4),∘,2⊥ ̈2,⌿⊢){⊂∪⍵~9}⌸(4⌿9),∘, ̄1↓{+/,⍵}⌺1 3 3-⊢
, ̄1↓{+/,⍵}⌺1 3 3-⊢ 1. ravelled adjacent counts, with the last iteration removed
(4⌿9),∘ 2. prepend 1. with 9 9 9 9
( ,2⊥ ̈2,⌿⊢) 3. ravelled encoded state transitions, with 0->0 as 0, 0->1 as 1, and so on.
((⍳4),∘ ) 4. prepend 3. with 0 1 2 3
{⊂∪⍵~9}⌸ 5. group 2. by 4. and discard 9
(⊂1 3)⌷ 6. take the 2nd and the 4th items in 5
We do 2. and 4. to sort the output of 5. and to deal with potential empty B and S.
APL(Dyalog Unicode), (削除) (削除ここまで)56 bytes SBCS
Assume ⎕io←0
A three-train that takes a three-dimensional array where time is the leading axis and outputs B and S in a nested array.
(⊂1 3)⌷((⍳4),∘,2⊥ ̈2,⌿⊢){⊂∪⍵~9}⌸(4⌿9),∘, ̄1↓{+/,⍵}⌺1 3 3-⊢
(⊂1 3)⌷((⍳4),∘,2⊥ ̈2,⌿⊢){⊂∪⍵~9}⌸(4⌿9),∘, ̄1↓{+/,⍵}⌺1 3 3-⊢
, ̄1↓{+/,⍵}⌺1 3 3-⊢ 1. ravelled adjacent counts, with the last iteration removed
(4⌿9),∘ 2. prepend 1. with 9 9 9 9
( ,2⊥ ̈2,⌿⊢) 3. ravelled encoded state transitions, with 0->0 as 0, 0->1 as 1, and so on.
((⍳4),∘ ) 4. prepend 3. with 0 1 2 3
{⊂∪⍵~9}⌸ 5. group 2. by 4. and discard 9
(⊂1 3)⌷ 6. take the 2nd and the 4th items in 5
We do 2. and 4. to sort the output of 5. and to deal with potential empty B and S.