[Question]
  [
The idea of this is mainly from [BIO 2017 q1](http://www.olympiad.org.uk/papers/2017/bio/bio17-exam.pdf). I got the idea for posting this challenge from my [Binary Sequences challenge](https://codegolf.stackexchange.com/questions/150650/binary-sequences), since lots of people seemed to like it.
Also, this is the first challenge I've posted without posting on the sandbox. I'll delete it if no one likes it.
### Rules
Take in a sequence of digits in ternary (base 3); this could be as a string, an array or the numerical value along with the number of preceding zeros.
For each row in the triangle, a row below is generated until there is only one digit in the last row. To find a digit below two other digits, the digit will be the same as two above it if these two other digits above are equal. Otherwise, it will be the digit that is not equal to either of them. Here is an example:
```
0 0 1 2 0 1 2 2
 0 2 0 1 2 0 2
  1 1 2 0 1 1
   1 0 1 2 1
    2 2 0 0
     2 1 0
      0 2
       1
```
*You are only expected to return the last row.*
Make your code short.
### Test Cases
```
0 -> 0
11 -> 1
10 -> 2
000 -> 0
012 -> 1
21102 -> 2
201021 -> 1
111111 -> 1
1020202020 -> 2
0212121210 -> 0
```
  
[Answer]
## [Husk](https://github.com/barbuz/Husk), 9 bytes
```
%3‚ÜêŒ©Œµ·∫äo_+
```
[Try it online!](https://tio.run/##yygtzv7/X9X4UduEcyvPbX24qys/Xvv////RBjpGOoYo2CAWAA "Husk ‚Äì Try It Online")
### Explanation
The main idea is to compute the mapping of two digits to one as **f(a,b) = (-a-b) % 3**. For golfing purposes we can delay the modulo until the very end.
```
   Œ©Œµ       Apply the following function until the list is only one
            element in length.
     ·∫äo       Apply the following function to pairs of adjacent values.
       _+       Add the two values and negate the result.
  ‚Üê         Take the first (and only) element of this list.
%3          Take it modulo 3.
```
In principle, it's also possible to compute the result directly by multiplying each element by the corresponding binomial coefficient and multiplying the sum by **-1** for even-length lists, but I don't know of a way to do that in fewer bytes.
[Answer]
# [MATL](https://github.com/lmendo/MATL), 10 bytes
```
td"HYCEsI\
```
[Try it online!](https://tio.run/##y00syfn/vyRFySPS2bXYM@b//2gDBQMFQwUjKGkUCwA "MATL ‚Äì Try It Online") Or [verify all test cases](https://tio.run/##y00syfmf8L8kRckj0tm12DPmf6xLyP9og1iuaEMFQzAJYhsoGEBpQwUjIG0EpIEyULYBhA1VD4cQ3QpGqBhsCkg/MjaIBQA).
### Explanation
For each pair of digits, the code computes twice the sum modulo 3. The process is repeated as many times as the length of the input minus 1.
```
t        % Implicit input: array of length n. Duplicate
d        % Consecutive differences. Gives an array of length n-1
"        % For each (that is, do n-1 times)
  HYC    %   2-column matrix where each column is a sliding block of length 2
  E      %   Times 2, element-wise
  s      %   Sum of each column
  I\     %   Modulo 3
         % Implicit end. Implicit display
```
[Answer]
# [Python 2](https://docs.python.org/2/), 48 bytes
```
f=lambda a,*l:-(f(*l)+f(a,*l[:-1]))%3if l else a
```
[Try it online!](https://tio.run/##LU67CsMwDNzzFcJQsFMHLHcL@A@yZTQeXBrTgPIgztKvd2O1OriTdDfc/jnf22pLSY7i8nxFiLqlvpNJtqTuSdbT9x0GpW6POQHBRHmCWEbnhRFaIFaqmzHMaC@2iIbVXMoJHo7aP2rY4g9GhGZwfom7nNdTZwVpOyDDvMIYmv24nuC5ExtUjSGULw "Python 2 ‚Äì Try It Online")
Recurses on the sublists deleting the first and last elements respectively.
This would be cleaner in Python 3 if it could actually unpack `f=lambda a,*b,c:...`.
[Answer]
# [Emojicode](http://www.emojicode.org/), 242 bytes
```
üêãüç®üçáüêñüî¢‚û°Ô∏èüöÇüçáüîÇi‚è©‚ûñüêîüêï1 0üçáüîÇj‚è©0iüçáüçä‚ùéüòõüç∫üî≤üêΩüêïjüöÇüç∫üî≤üêΩüêï‚ûï1jüöÇüçáüê∑üêïj‚ûñ‚ûñ3üç∫üî≤üêΩüêïjüöÇüç∫üî≤üêΩüêï‚ûï1jüöÇüçâüçâüçâüçéüç∫üî≤üêΩüêï0üöÇüçâüçâ
```
Uses the same algorithm as [my C answer.](https://codegolf.stackexchange.com/a/152105/56721) [Try it online!](https://tio.run/##S83Nz8pMzk9J/f//w/wJ3R/m964A4nYge9qH@VMWPZq38P2O/g/zZzVBRKc0ZT7qX/loHlBywhQgnmqoYACTyQLKGGRCeL1dj@b2fZg/YzaQuQsouQmodi9IfRbULBTBR/OmGmYhLJmwHawSaAsQGZNsQicS7kNXaICsCOjl/kYFkKUKXApAekYDkJiyEEQsAgmvUDAAQkMFIyhpBBJsUzA04ALrBgA "Emojicode ‚Äì Try It Online")
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly), 9 bytes
```
+2\N$·∏ä¬ø%3
```
[Try it online!](https://tio.run/##y0rNyan8/1/bKMZP5eGOrkP7VY3///8fbaCjAESGOgpGSAyjWAA "Jelly ‚Äì Try It Online")
Using Martin Ender's Husk algorithm.
[Answer]
# [Haskell](https://www.haskell.org/), 36 bytes
```
f[a]=a
f(h:t)=mod(-f t-f(h:init t))3
```
[Try it online!](https://tio.run/##RYtNCsMgEIX3nmKQLhKooHYX6gF6BpEiiRJpYn6c7np3G21L58F7M7xvRpsebppy9toaZYlvxg5bNS9DwzwgK3eIAQHb9pJRacrpmQpRrGycVxfycCkEr8mPrESdisqvCizFR5wagst9CgkhgQK9Ozvo3rz6K0uGJLc9XexdqWa7wg9F6DrQ@hbRGDLbEI9@3UNEOFXOw/8zvwE "Haskell ‚Äì Try It Online")
Saves 1 byte over the more symmetrical:
```
f[a]=a
f l=mod(-f(tail l)-f(init l))3
```
[Try it online!](https://tio.run/##RYtBCsMgFET3nuIjXSTQgNpdqAfoGUSKJEqlxqTxd9e7W7Ut/QMzA/P@zaS7DSFnp4yWhjgIclnnbnAdGh8g9KX56LG0/pRRKsrokXJerTbGmnNRXHDOWrKSjWjXUPFVhQX/iFFNcL0GnxASSFC7NbOa9Gs6D0mTZB9PGydbp8Vs8EMRxhGUukTUmizGx7Jvu48Ih8Y5@H/mNw "Haskell ‚Äì Try It Online")
The idea is simple: recursively compute the function on the sublists deleting the first and last element respectively, and combine them with `\a b -> mod(-a-b)3`. This seems shorter than `zipWith`'ing this fuction .
**[Haskell](https://www.haskell.org/), 44 bytes**
```
f[a]=mod a 3
f l=f$zipWith((-).(0-))l$tail l
```
[Try it online!](https://tio.run/##RYtBCsIwFET3OcWndNGClSTuxBzAE7gIQUKb0GCa1ua7Ee8em6j4B2Y@zJtRx5vxPiUrtRLTPICGA7Hgha2fbrk4HJuma/cN7drW16idB59QyIpWu4qxbPmjtDjjm3PGaEm6ZSHKFZR/lWHOPqKVIjhfvYsIEQTI1ehB9urVn7qoSDT3hwm9ydWkF/ihCMcjSHkOqBSZtAtbv6wuINSFs/Bfpjc "Haskell ‚Äì Try It Online")
[Answer]
# [C (gcc)](https://gcc.gnu.org/), ~~91~~ ~~88~~ 84 bytes
*-1 byte thanks to @Mr.Xcoder!*
```
j;f(a,l)int*a;{for(;l-->1;)for(j=0;j<l;)a[j++]=a[j]^a[j+1]?3-a[j]-a[j+1]:a[j];a=*a;}
```
Gets the array and the length. [Try it online!](https://tio.run/##LY3BCsIwEER/RQpC1m4gqRdxjX5IibBEIg1pleIt9NtjFr3svGHYmaCfIdSaKCrGDNPyOTCV@FoVZa2vlkA4OUPpkgl4TH3vXRN/F7b@dtTi9M@dhYldK9nqzNOioLTOHY/eFYMGLQ7/O2z0XlsWVbd/dCj7J4D29gU "C (gcc) ‚Äì Try It Online")
[Answer]
# J, ~~23~~ 15 Bytes
```
3&(|2+/\-)~<:@#
```
Thanks to @miles
### Old Solution:
```
3|2&(-@+/\)^:(#>1:)^:_]
```
Inspired by Martin Ender's solution:
### Explanation
```
3|2&(-@+/\)^:(#>1:)^:_]    | Whole program
                      ]    | Seperates the argument from the _ (infinity)
           ^:(#>1:)^:_     | Do while the length is greater than one
  2&(-@+/\)                | Inverse of the sum of adjacent elements
3|                         | Modulo 3
```
[Answer]
# [APL (Dyalog)](https://www.dyalog.com/), 17 bytes
```
{3|3-2+/‚çµ}‚ç£{1=‚â¢‚ç∫}
```
[Try it online!](https://tio.run/##SyzI0U2pTMzJT///P@1R24Rq4xpjXSNt/Ue9W2sf9S6uNrR91LnoUe@uWqC0ggEQGioYQUkjrjQgbQDmI2EA "APL (Dyalog Unicode) ‚Äì Try It Online")
**How?**
`2+/‚çµ` - sum each two adjacent items
`3-` - vectorized subtract from three
`3|` - vectorized modulo by three
`‚ç£` - repeat until...
`1=‚â¢‚ç∫` - only one item is left
[Answer]
# Javascript (ES6), 58 bytes
```
f=s=>s[1]?f(s.replace(/.(?=(.?))/g,(a,b)=>b&&(6-a-b)%3)):s
```
[Answer]
## Batch, 122 bytes
```
@set/an=2,s=i=l=0
@for %%e in (%*)do @set/al+=1,n^^=3
@for %%e in (%*)do @set/as+=%%e*n,s%%=3,n*=l-=1,n/=i+=1
@echo %s%
```
Uses binomial expansion. As @MartinEnder points out, the sum has to be negated (modulo 3) if the number of values (which are counted in the first loop) is even, so `n` is set to either `1` or `2` accordingly. The second loop then computes the sum via the binomial coefficients.
[Answer]
# APL+WIN, ~~30~~ 28 bytes
2 bytes saved courtesy of Uriel.
```
n‚Üê‚éï‚ãÑ¬Ø1‚Üë‚àä‚çé¬®(‚ç¥n)‚ç¥‚äÇ'n‚Üê3|3-2+/n'
```
Explanation:
```
n‚Üê‚éï Prompt for screen input of the form: 0 0 1 2 0 1 2 2
'n‚Üê3|3-2+/n' Successive rows are 3 mod 3 minus successive digit pairs.
(‚ç¥n)‚ç¥‚äÇ Create a nested vector of the row code, one element per row. 
¬Ø1‚Üë‚àä‚çé¬® Execute each element of row code, flatten result and take final value.
```
This is one way of writing looping code in APL on a single line.
]