[Question]
  [
# Task
Given an array of positive integers, replace each element with the parity of the sum of the other elements. The array is guaranteed to have **at least** 2 elements.
# Definition
* Parity: whether a number is odd or even.
# Example
For the array `[1,2,3,1]`:
* Replace `1` with the parity of `2+3+1`, i.e. `even`.
* Replace `2` with the parity of `1+3+1`, i.e. `odd`.
* Replace `3` with the parity of `1+2+1`, i.e. `even`.
* Replace `1` with the parity of `1+2+3`, i.e. `even`.
Output: `[even, odd, even, even]`
# Input
An array of positive integer.
You may take it as a proper array, or as a linefeed-separated string of positive integers.
You may assume that the array and the values inside are within the handling capability of your language.
# Output
An array of **two consistent values**, one representing `odd`, one representing `even`.
You may output it as a linefeed-separated string of the two values.
# Testcases
Inputs:
```
[1, 2, 3, 1]
[1, 2, 3, 2, 1]
[2, 2]
[100, 1001]
```
Outputs:
```
[even, odd, even, even]
[even, odd, even, odd, even]
[even, even]
[odd, even]
```
Note: you may choose other consistent values other than `odd` and `even`.
# Scoring
This is [code-golf](/questions/tagged/code-golf "show questions tagged 'code-golf'"). Shortest answer in bytes wins.
[Standard loophole](https://codegolf.meta.stackexchange.com/questions/1061/loopholes-that-are-forbidden-by-default) applies.
  
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly), 3 bytes
```
+SḂ
```
[Try it online!](https://tio.run/nexus/jelly#@68d/HBH0//D7Y@a1rj//x8dbaijYKSjYKyjYBirw6WA4BrBRIAMI4iUgQFQzMDAMDYWAA "Jelly – TIO Nexus")
### How it works
```
+SḂ  Main link. Argument: A (array)
 S   Compute the sum of A.
+    Add the sum to each element of A.
     Using _ (subtraction) or ^ (bitwise XOR) would also work.
  Ḃ  Bit; compute the parity of each resulting integer.
```
[Answer]
# JavaScript (ES6), ~~38 36~~ 32 bytes
```
a=>a.map(b=>eval(a.join`+`)-b&1)
```
Uses `0` for even and `1` for odd.
# Test
```
f=
a=>a.map(b=>eval(a.join`+`)-b&1)
console.log(f([1, 2, 3, 1]))
console.log(f([1, 2, 3, 2, 1]))
console.log(f([100, 1001]))
```
[Answer]
## Haskell, 20 bytes
```
f x=odd.(sum x-)<$>x
```
Uses `True` for odd values and `False`for even values.
[Try it online!](https://tio.run/nexus/haskell#@5@mUGGbn5Kip1FcmqtQoatpo2JX8T83MTNPwVahoCgzr0RBRSFNIdpQx0jHGIgNY/8DAA "Haskell – TIO Nexus")
Subtract each element from the sum of the list and test if it's odd.
`f` turned to pointfree has also 20 bytes: `map=<<(odd.).(-).sum`.
[Answer]
# [MATL](https://github.com/lmendo/MATL), ~~5~~, 4 bytes
```
ts-o
```
[Try it online!](https://tio.run/nexus/matl#@19SrJv//3@0oY6CkY6CMZg0jAUA "MATL – TIO Nexus")
*One byte saved thanks to Dennis!*
This gives '1' for odd and '0' for even. Explanation:
```
t       % Duplicate the input
 s      % Get the sum of the input
  -     % Subtract it from the original input
   o    % Get the parity of each element
```
[Answer]
## [Alice](https://github.com/m-ender/alice), ~~31~~ 28 bytes
```
/O.HQ\d$K@
\i#\ /d2-&+!w?+2%
```
[Try it online!](https://tio.run/nexus/alice#@6/vr@cRGJOi4u3AFZOpHKOgn2Kkq6atWG6vbaT6/78hlxEQGnMZAgA "Alice – TIO Nexus")
The input format doesn't matter as long as the integers are separated. The output format is linefeed-separated.
The layout is probably still not optimal but I haven't found a way to shorten this further yet.
### Explanation
```
/     Reflect to SE. Switch to Ordinal.
i     Read all input as a string.
      Reflect off bottom boundary. Move to NE.
.     Duplicate the input string.
      Reflect off top boundary. Move to SE.
\     Reflect to N. Switch to Cardinal.
H     Implicitly convert the top copy of the input to the integers it
      contains and take the absolute value of the top-most one. (Taking
      the absolute value doesn't do anything, but we need the implicit
      conversion to integers.)
      The IP wraps back to the second line.
\     Reflect to SE. Switch to Ordinal.
      Immediately reflect off bottom boundary. Move to NE.
Q     Reverse the stack (this converts the integers back to strings but
      that's irrelevant). After this, we end up with all the individual
      integers on the bottom of the stack in reverse order and the other
      copy of the input string with all integers on top.
      Reflect off top boundary. Move to SE.
/     Reflect to E. Switch to Cardinal.
d     Push the stack depth, which is one more than the number of list
      elements (due to the other input string on the stack).
2-    Subtract 2.
&+    Run + that many times, which implicitly converts the second string
      to the integers it contains and then adds up all the list elements.
!     Store the sum on the tape.
w     Push the current IP position to the return address stack. This
      lets us return here repeatedly to implement a loop.
  ?+    Retrieve the input sum from the tape and add it to the current
        element.
  2%    Compute its parity. Other ways to do this are 1A and 0x. 2F would
        also work but it gives 0/2 instead of 0/1.
        The IP wraps the first column of the grid.
  \     Reflect to NE. Switch to Ordinal. The IP bounces diaginally up
        and down until it hits the next \.
  O     Implicitly convert the current parity to a string and print it
        with a trailing linefeed.
  #     Skip the next command (the H).
  \     Reflect to E. Switch to Cardinal.
  d     Push the stack depth. This is zero when we're done.
  $     Skip the next command if the stack depth is indeed zero, which
        exits the loop.
K     Jump to the return address on top of the return address stack without
      popping it (so that the next K will jump there again).
@     Terminate the program.
```
[Answer]
# Pyth, ~~7~~ 6 bytes
```
mi2-sQ
```
*-1 Byte thanks to @KZhang*
Outputs 1 for odd, 2 for even.
[Try it!](https://pyth.herokuapp.com/?code=mi2-sQ&input=%5B1%2C2%2C3%2C1%5D&test_suite=1&test_suite_input=%5B1%2C+2%2C+3%2C+1%5D%0A%5B1%2C+2%2C+3%2C+2%2C+1%5D%0A%5B2%2C+2%5D%0A%5B100%2C+1001%5D&debug=0)
### Explanation
```
m%-sQd2
m      Q    # For each element in the (implicit) input list
   sQ       # Take the sum of all the elements
  -  d      # subtract that element, so that we now have the sum of the other elements
 %    2     # modulo 2; 1=off, 0=even
```
[Answer]
# [05AB1E (legacy)](https://github.com/Adriandmen/05AB1E/tree/fb4a2ce2bce6660e1a680a74dd61b72c945e6c3b), ~~4~~ 3 bytes
```
O^È
```
[Try it online!](https://tio.run/##MzBNTDJM/f/fP@5wx///0YY6CkY6CsZg0jAWAA "05AB1E (legacy) – Try It Online")
```
O   # Sum
 ^  # XOR with (implicit) input
  È # Print 1 for even / 0 for odd
```
[Answer]
# [Python 2](https://docs.python.org/2/), ~~33~~ 31 bytes
-2 bytes thanks to Leaky Nun
```
lambda x:[sum(x)-z&1for z in x]
```
[Try it online!](https://tio.run/nexus/python2#S7ON@Z@TmJuUkqhQYRVdXJqrUaGpW6VmmJZfpFClkJmnUBH7H8QuSS0uAXGjow11FIx0FIx1FAxjdRAcIwgfSBmBhA0MgHwDA8PYWCsuhYKizLwSsAk66rrqOmkaIKYm138A "Python 2 – TIO Nexus")
[Answer]
# R, 21 bytes
```
(sum(n<-scan())-n)%%2
```
reads the list from stdin and returns 0 for even, 1 for odd. binds the input to the variable `n` inside the call to `sum` instead of calling it outside, i.e., `n=scan();(sum(n)-n)%%2`
[Try it online!](https://tio.run/nexus/r#@69RXJqrkWOjW5ycmKehqambo6mqavTfUMFIwVjB8D8A)
[Answer]
# [J](http://jsoftware.com/), 6 bytes
```
2|]++/
```
[Try it online!](https://tio.run/nexus/j#@59ma2VUE6utrf8/NTkjXyFNwVDBSMFYwZALhWuEEDBSMILLGRiAMFCqIrNEweA/AA "J – TIO Nexus")
[Answer]
## Mathematica, 13 bytes
```
#+Tr@#&/*OddQ
```
or
```
OddQ[#+Tr@#]&
```
[Answer]
## Clojure, 30 bytes
```
#(for[i %](odd?(apply - i %)))
```
Substracts all values from each value in turn, for example with input `[a b c d]` the 2nd calculated value is `b - a - b - c - d` = `-(a + c + d)`. Output is `false` for even and `true` for odd.
But you might as well use `+` and calculate each subsequent term twice so it doesn't affect the parity.
[Answer]
# [CJam](https://sourceforge.net/p/cjam), 10 bytes
```
{_:+f+1f&}
```
This is an anonymous block (function) that takes the input from the stack and replaces it by the output.
[Try it online!](https://tio.run/nexus/cjam#izZUMFIwVjCM/V8db6Wdpm2Yplb7v67gfzRYPBYA "CJam – TIO Nexus")
### Explanation
Consider input `[1 2 3 1]`.
```
{         e# Begin block
          e#   STACK: [1 2 3 1]
  _       e#   Duplicate
          e#   STACK: [1 2 3 1], [1 2 3 1]
  :+      e#   Fold addition over the array: compute its sum
          e#   STACK: [1 2 3 1], 7 
  f+      e#   Map addition over the array with extra parameter
          e#   STACK: [8 10 11 8]
  1       e#   Push 1
          e#   STACK: [8 10 11 8], 1
  f&      e#   Map bit-wise "and" over the array with extra parameter
          e#   STACK: [0 0 1 0]
}         e# End block
```
[Answer]
# [APL (Dyalog Unicode)](https://www.dyalog.com/), ~~19~~ 7 bytes
*Golfed 12 bytes thanks to @Adám*
```
2|+/-¨⊢
```
[Try it online!](https://tio.run/nexus/apl-dyalog#@@/0qG2CUY22vu6hFY@6Fv3/76RgqGCkYKxgyAVjGYHZRgpGIBEDAxA2BAA "APL (Dyalog Unicode) – TIO Nexus")
[Answer]
# [Japt](https://github.com/ETHproductions/japt), 7 bytes
```
£x +X&1
```
[Try it online!](https://tio.run/nexus/japt#@39ocYWCdoSa4f//0YY6RjrGOoaxAA "Japt – TIO Nexus")
### Explanation
```
 £   x +X&1
 mX{ x +X&1}  // Ungolfed
UmX{Ux +X&1}  // Variable introduction
UmX{       }  // Replace each item in the input array with
         &1   //   the parity of
    Ux        //   the sum of the input array
       +X     //   plus X.
              // Implicit: output result of last expression
```
[Answer]
# Perl 5, 31 bytes
```
sub{map$x+=$_,@_;map$x-$_&1,@_}
```
Outputs `1` for odd and `0` for even.
[Answer]
# Clojure(Script), 36 bytes
Output is `true` for odd and `false` for even. Both output and input are sequences.
```
(fn[l](map #(odd?(-(apply + l)%))l))
```
[Answer]
# PHP, 50 Bytes
[Online Versions](http://sandbox.onlinephpfunctions.com/code/115c6cae183cf2e67de1c315108e2d99cace708d)
1 for odd , 0 for even
Output as string separated with `_`
```
<?foreach($_GET as$v)echo array_sum($_GET)-$v&1,_;
```
# PHP, 72 Bytes
Output as array use `array_map`
```
<?print_r(array_map(function($v){return array_sum($_GET)-$v&1;},$_GET));
```
[Answer]
# C, ~~68~~ 62 bytes
```
i;s;f(c,l)int*l;{while(i<c)s+=l[i++];while(i)l[--i]=s-l[i]&1;}
```
1 for odd, 0 for even
**Detailed** [*Try Online*](https://tio.run/nexus/c-gcc#nYvLCsIwFAXXzVdcKkpiUzGtu7T@SMxC@qAXYhRTMRDy7TUFwb2LM4s5zLJB25lXP0Dj5h7vh@lMUDo50o4bhnbeGxneE5qBYtMxV7RGYVFo@XXMqLJE3boyeb0TMhJyu6KljASSpR680tBCAMGh4lBzEBAlyR7PdI40D9uew2/xYnPu1VEniBXVilqzlIz0xD37q43L8gE)
```
f(int c, int * l)
{
    int i = 0, s = 0;
    while(i < c)
    {
        s = s + l[i];
        i = i + 1;
    }
    // assert(i == c)
    while(i > 0)
    {
        i = i - 1;
        l[i] = s - l[i]&1;
    }
}
```
[Answer]
# [Retina](https://github.com/m-ender/retina), ~~40~~ 38 bytes
```
\d+
¶$` $'
^¶
\d+
$*
+` |11
%M`1
¶
   
```
[Try it online!](https://tio.run/nexus/retina#U9VwT/gfk6LNdWibSoKCijpX3KFtXFwgARUtLu0EhRpDQy4uVd8EQ6ACLoX//w0VjBSMFQy5ILQRkGWkYMRlaGCgAMSGAA "Retina – TIO Nexus") Outputs 1 for odd and 0 for even. Explanation: The first two lines duplicate the input once for each number in the input, but without the element itself. This creates an extra blank line which is then deleted. The input is then converted from decimal to unary, the spaces are deleted and the parity computed. Even parity is then converted to zero and the results joined back in to one line. Edit: Saved 2 bytes thanks to @FryAmTheEggman. I tried some other versions which are conceptually more pleasing but which take far too many bytes to express:
```
\d\B
T`2468O`00001
T`d`10`^([^1]*1[^1]*1)*[^1]*1[^1]*$
```
Changes all inputs to their parity, then flips all their parities if the total has odd parity.
```
\d+
$*
^.*
$&¶$&
 (?=.*$)
11
\B
0
T`d`10`.*¶1
¶0
```
Sums a duplicate of the input, then takes the parity of everything, then inverts the parities if the sum is odd, then deletes the sum again.
[Answer]
# [Ohm](https://github.com/MiningPotatoes/Ohm), 4 bytes
```
DΣ-é
```
[Try it online!](https://tio.run/nexus/ohm#@@9ybrHu4ZX//wMA "Ohm – TIO Nexus")
Basically a direct port of the [MATL](https://codegolf.stackexchange.com/a/118521/65298) and [05AB1E](https://codegolf.stackexchange.com/a/118510/65298) answers. Uses `true` for even and `false` for odd.
[Answer]
# [Julia 1.0](http://julialang.org/), 17 bytes
```
x->(sum(x).-x).%2
```
[Try it online!](https://tio.run/##ZY1NDoIwFIT3nGJSY0KTYtq6Myl6D@MCQ/kxQAltFU5fi3EjLmbx5n0z8/BdW4g5VOqu63YIc5an1vfpTA9Z1F4GPZTJxTbmhSq9CgbJcGQQN5rUkYJCX4zpkuWLUgJnEFOWBCcQ/dQDYTE0U4odGt2NeoI1aJ2FLuwCZzDpooTxbvSOrUUWYrU/Jd/VerP678rNI97yB@Q8EpxHKLwB "Julia 1.0 – Try It Online")
[Answer]
# k, 9 bytes
```
{2!x-+/x}
```
The output is a `1` for `odd`, and a `0` for even. [Try it online.](http://johnearnest.github.io/ok/?run=%7B2%21x-%2B%2Fx%7D%5B1%202%203%201%5D)
Converted to pseudocode, it would be:
```
for number in x:
    yield (number - sum(x)) % 2
```
[Answer]
# [Scala](http://www.scala-lang.org/), 19 bytes
```
x=>x.map(x.sum-_&1)
```
[Try it online!](https://tio.run/nexus/scala#y0/KSk0uUfBNzMxTSK0oSc1LKVZwLChQqOYqS8xRSLNScCwqSqyM9swriVWwtUPhKfyvsLWrUMhNLNCo0CsuzdWNVzPU/F9QlJlXkpOnkaYBVqthqKNgpKNgrKNgqKmpkJsdXAKUT1dQ0lFQ0uSq/Q8A "Scala – TIO Nexus")
[Answer]
# [Brain-Flak](https://github.com/DJMcMayhem/Brain-Flak), ~~94~~ ~~68~~ 66 bytes
```
({({}<>)<>})<>{<>(({})<({}<>{}<>(())){({}[()]<([{}])>)}{}>)<>}<>{}
```
[Try it online!](https://tio.run/nexus/brain-flak#HcuxDQAxCAPAVSjtMnol3yAWiTIJYnYCKa6wZSccHmpUi@JqqEx9ZQNI9maDR7E9Do3h8S69yRwy5Cuz/LIu "Brain-Flak – TIO Nexus")
This seems a little long for the task. There might be a more convenient way to do this.
## Explanation
First we calculate the sum of the stack with:
```
({({}<>)<>})
```
The we go through the entire stack adding that result to each element and determine the pairity
```
<>{<>(({})<({}<>{}<>(())){({}[()]<([{}])>)}{}>)<>}<>{}
```
---
This uses a pretty cool mod 2 algorithm I came up with for this challenge. 
```
({}(())){({}[()]<([{}]())>)}{}
```
This pushes 1 under the input decrements until the input reaches zero each time performing `1-n` to the 1 we placed earlier, it then removes the input.
[Answer]
# [Wise](https://github.com/Wheatwizard/Wise), ~~54~~ 52 bytes
```
::^:??[:!^:?^:!^:?^?]|!::^??[!:?^:><^!:?^:!^:?^?]!&|
```
[Try it online!](https://tio.run/nexus/wise#@29lFWdlbx9tpQik4iCkfWyNIlAYKKoIErOKq9NVU0SSVVSr@f//v@F/o//GIBIA "Wise – TIO Nexus")
## Explanation
This code would be a lot shorter if it didn't take so many bytes to swap the top two elements. The current record is
```
:?^:!^:?^!
```
This unfortunately constitutes the majority of the code.
---
First we take the XOR sum of the stack
```
::^:??[:!^:?^:!^:?^?]|!
```
We then XOR this with every element and the element with it last bit zeroed
```
::^??[!:?^:><^!:?^:!^:?^?]!&|
```
[Answer]
# [Java](http://openjdk.java.net/), ~~81~~ 78 bytes
3 bytes thanks to Kevin Cruissen
```
void f(int[]a){int s=0,i=a.length;for(int x:a)s+=x;for(;i-->0;a[i]=s-a[i]&1);}
```
[Try it online!](https://tio.run/nexus/java-openjdk#VVAxboQwEKzhFa4iLMAypIvjSHlAqisRxYYA2YgzCJvLnRBvJ2u4Q4pcrD27szPjYfrssGJVB9ayD0Azr5cev1gToXFFCXymyqyWCWoQXW1a962afvRtdn0BbmN93QCFafomFRRYapv68pRxtazDrmAdOCrb8jPpRCc3omlJYmwtn8Ng0ytK5mrrKrC1ZZqZ@pfdcZoI5ixhecKeE5Ytyb93fkB0y@9NKQmVMlvCYFFh8HCNWip8PWQeoTCOvY3dB5D4MUFRiB54M/6HIi6aCLiHTjfr6rPoJycGSuM6E/3ABcTksBPv4wg3K1y/JyWK5ywhnfUP "Java (OpenJDK 8) – TIO Nexus")
Modifies the array in-place.
[Answer]
# [AWK](https://www.gnu.org/software/gawk/manual/gawk.html), 64 bytes
```
{for(i=0;++i<=NF;print s[i]%2)for(j=0;++j<=NF;)if(i!=j)s[i]+=$j}
```
[Try it online!](https://tio.run/nexus/awk#@1@dll@kkWlrYK2tnWlj6@dmXVCUmVeiUBydGatqpAmSzAJLZoElNTPTNDIVbbM0QfLatipZtf//GyoYKRgDsSEXAA "AWK – TIO Nexus")
Outputs a `0` for even sums and `1` for odd sums separated by newlines. The only even slightly out-of-the-box thinking was placing the `print` command inside the `for` "increment" step. I tried a few "clever" ways to print, but they didn't save bytes.
Just for giggles, if you don't want newlines:
```
{for(i=0;++i<=NF;m=m,s[i]%2)for(j=0;++j<=NF;)if(i!=j)s[i]+=$j}1
```
which has the same byte-count as above, but is a bit more obtuse.
[Answer]
# Swift - 55 bytes
*Finally beats C!* Also, 0 for even, 1 for odd
```
func g(a:[Int]){for i in a{print((a.reduce(0,+)-i)%2)}}
```
A function, with usage: `g(a: [1,2,3,2,1] // => 0 1 0 1 0`
**[Check it out!](http://swift.sandbox.bluemix.net/#/repl/5909745bd9945251091fd3f9)**
[Answer]
# Axiom, 45 bytes
```
f(a)==[(reduce(+,a)-a.j)rem 2 for j in 1..#a]
```
no check for input type, possible recalculation of sum "a" each element...tests
```
(27) -> [[a,f(a)] for a in [[1,2,3,1], [1,2,3,2,1], [2,2], [100, 1001] ]]
   (27)
   [[[1,2,3,1],[0,1,0,0]], [[1,2,3,2,1],[0,1,0,1,0]], [[2,2],[0,0]],
    [[100,1001],[1,0]]]
```
]