g | x | w | all
Bytes Lang Time Link
005Jalapeño250204T215148ZATaco
007Husk250203T175141Zint 21h
003Thunno 2230810T085309ZThe Thon
nanFig230223T003512Zsouth
024Arturo230222T230731Zchunes
009TIBasic211218T190402ZYouserna
032Python 2211214T151514ZLarry Ba
027Factor + math.unicode211214T160352Zchunes
017Julia 1.0190531T180845Zgggg
00305AB1E legacy170502T183425ZRiley
006Japt190530T223555ZShaggy
045Axiom170503T131420Zuser5898
055Swift170503T061152ZMr. Xcod
nan170504T183440ZBrad Gil
nan170503T133904Zauhmaan
031Ruby170503T171724ZCyoce
064AWK170503T185425ZRobert B
007APL Dyalog Unicode170503T101316Zuser4180
006Pyth170502T210549ZKarlKast
078Java170503T025638ZLeaky Nu
004Ohm170503T030559ZNick Cli
021R170502T184258ZGiuseppe
038Retina170502T215533ZNeil
062C170502T223355ZKhaled.K
050PHP170502T200408ZJör
020Haskell170502T194004Znimi
052Wise170503T051233ZWheat Wi
066BrainFlak170503T035631ZWheat Wi
006J170503T041726ZLeaky Nu
036ClojureScript170503T031622Zmadstap
019Scala170502T234529ZBrian Mc
010CJam170502T222738ZLuis Men
031Perl 5170502T214221ZChris
009k170502T211425Zzgrep
028Alice170502T203408ZMartin E
030Clojure170502T200935ZNikoNyrh
004MATL170502T191716ZDJMcMayh
013Mathematica170502T192343ZMartin E
032JavaScript ES6170502T183213ZLuke
003Jelly170502T184230ZDennis
007Japt170502T183651ZETHprodu
031Python 2170502T183403ZRod

Jalapeño, 5 bytes

Σ-I₀%2

Explained

Σ-I₀%2
Σ       # Sum of input
 -I₀    # Subtract, vectorized over the input
    %2  # Modulo 2, get pairity.

Outputs 1 for odd, 0 for even.

Hex-Dump of Bytecode

       0  1  2  3  4  5  6  7  8  9  A  B  C  D  E  F
0000: e9 51 90 54 32                                  

Try it Online!

All Test Cases

Husk, 7 bytes

Mo%2-¹Σ

Try it online!

Outputs 0 for even, 1 for odd.

Explanation:

        -- implicit input
      Σ -- sum up the input list
M       -- map each element of the list:
 o      -- (via a function combinator o)
    -¹  -- | subtract the element from the total sum
  %2    -- | and modulo 2

Thunno 2, 3 bytes

S+ɗ

Try it online!

Explanation

S+ɗ  # Implicit input
S    # Sum the input
 +   # Add to input
  ɗ  # Parity of each
     # Implicit output

Fig, \$4\log_{256}(96)\approx\$ 3.292 bytes

%2-S

1 for odd, 0 for even.

Try it online!

%2-S
   S  # sum
  -   # minus each item of input array
%2    # mod each by 2

Arturo, 24 bytes

$[a][map a=>[%&-∑a 2]]

Try it

TI-Basic, 9 bytes

fPart(.5(sum(Ans)+Ans

Takes input in Ans. Output is stored in Ans and displayed. Outputs .5 for odd numbers and 0 for even ones.

Python 2, 32 bytes

map(lambda x:sum(s)-x&1,input())

Try it online!

Factor + math.unicode, 32 27 bytes

[ dup Σ v-n [ odd? ] map ]

Try it online!

Outputs t for odd and f for even.

               ! { 1 2 3 1 }
dup            ! { 1 2 3 1 } { 1 2 3 1 }
Σ              ! { 1 2 3 1 } 7
v-n            ! { -6 -5 -4 -6 }
[ odd? ] map   ! { f t f f }

Julia 1.0, 17 bytes

x->(sum(x).-x).%2

Try it online!

05AB1E (legacy), 4 3 bytes

O^È

Try it online!

O   # Sum
 ^  # XOR with (implicit) input
  È # Print 1 for even / 0 for odd

Japt, 6 bytes

®nUx)v

Try it

®nUx)v     :Implicit input of array U
®          :Map
 n         :Subtract from
  Ux       :  Sum of U
    )      :End subtraction
     v     :Divisible by 2?

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]]]

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!

Perl 6, 16 bytes

{(.sum X-$_)X%2}

Try it

This results in a list where 0 represents even and 1 represents odd.

Expanded:

{  # bare block lambda with implicit parameter $_
  (
    .sum  # the sum of the input array
    X[-]  # crossed using &infix:« - »
    $_    # the input

    # this produces the sum of the other elements

  )
  X[%]    # cross that using &infix:« % » the modulus operator
  2       # with 2
}

C#, 142 121 bytes


Data


Golfed

(int[] i)=>{var l=i.Length;var o=new int[l];var s=0;foreach(int x in i)s+=x;for(int x=0;x<l;x++)o[x]=s-i[x]&1;return o;};

Ungolfed

( int[] i ) => {
   var l = i.Length;
   var o = new int[ l ];
   var s = 0;
   
   foreach( int x in i )
      s += x;
   
   
   for( int x = 0; x < l; x++ )
      o[ x ] = s - i[ x ] & 1;
   
   return o;
};

Ungolfed readable

// Takes an array of Int32 objects ( 32-byte signed integers )
( int[] i ) => {
   // Save the length of the array to save on byte count
   var l = i.Length;
   
   // Initialize an array with the same size the the input array
   var o = new int[ l ];
   
   // Initialize a var to store the sum of all numbers
   var s = 0;
   
   // Cycle through every number from the input
   foreach( int x in i )
      
      // Sum all of them
      s += x;
   
   // Cycle again through every number
   for( int x = 0; x < l; x++ )
      
      // Subtracts the number for the sum
      //    and performs a bitwise and
      o[ x ] = s - i[ x ] & 1;
   
   // Return the array with odds and evens
   return o;
};

Full code

using System;
using System.Collections.Generic;

namespace Namespace {
   class Program {
      static void Main( String[] args ) {
         Func<Int32[], Int32[]> f = ( int[] i ) => {
            var l = i.Length;
            var o = new int[ l ];
            var s = 0;
            
            foreach( int x in i )
               s += x;
            
            
            for( int x = 0; x < l; x++ )
               o[ x ] = s - i[ x ] & 1;
            
            return o;
         };

         List<Int32[]>
            testCases = new List<Int32[]>() {
               new Int32[] { 1, 2, 3, 1 },
               new Int32[] { 1, 2, 3, 2, 1 },
               new Int32[] { 2, 2 },
               new Int32[] { 100, 1001 },
            };

         foreach( Int32[] testCase in testCases ) {
            Console.WriteLine( $" Input: {String.Join( ",", testCase )}\nOutput: {string.Join( ",", f( testCase ) )}\n" );
         }

         Console.ReadLine();
      }
   }
}

Releases


Notes

Ruby, 47 33 31 Bytes

->a{a.map{|x|a.inject(:+)-x&1}}

It maps through each element, determining the parity of the sum of all elements minus the current element (thus making it 0).

AWK, 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!

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.

APL (Dyalog Unicode), 19 7 bytes

Golfed 12 bytes thanks to @Adám

2|+/-¨⊢

Try it online!

Pyth, 7 6 bytes

mi2-sQ

-1 Byte thanks to @KZhang

Outputs 1 for odd, 2 for even.

Try it!

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

Java, 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!

Modifies the array in-place.

Ohm, 4 bytes

DΣ-é

Try it online!

Basically a direct port of the MATL and 05AB1E answers. Uses true for even and false for odd.

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!

Retina, 40 38 bytes

\d+
¶$` $'
^¶

\d+
$*
+` |11

%M`1
¶
 

Try it online! 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.

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

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;
    }
}

PHP, 50 Bytes

Online Versions

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));

Haskell, 20 bytes

f x=odd.(sum x-)<$>x

Uses True for odd values and Falsefor even values.

Try it online!

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.

Wise, 54 52 bytes

::^:??[:!^:?^:!^:?^?]|!::^??[!:?^:><^!:?^:!^:?^?]!&|

Try it online!

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

::^??[!:?^:><^!:?^:!^:?^?]!&|

Brain-Flak, 94 68 66 bytes

({({}<>)<>})<>{<>(({})<({}<>{}<>(())){({}[()]<([{}])>)}{}>)<>}<>{}

Try it online!

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.

J, 6 bytes

2|]++/

Try it online!

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))

Scala, 19 bytes

x=>x.map(x.sum-_&1)

Try it online!

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!

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

Perl 5, 31 bytes

sub{map$x+=$_,@_;map$x-$_&1,@_}

Outputs 1 for odd and 0 for even.

k, 9 bytes

{2!x-+/x}

The output is a 1 for odd, and a 0 for even. Try it online.

Converted to pseudocode, it would be:

for number in x:
    yield (number - sum(x)) % 2

Alice, 31 28 bytes

/O.HQ\d$K@
\i#\ /d2-&+!w?+2%

Try it online!

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.

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.

MATL, 5, 4 bytes

ts-o

Try it online!

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

Mathematica, 13 bytes

#+Tr@#&/*OddQ

or

OddQ[#+Tr@#]&

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]))

Jelly, 3 bytes

+SḂ

Try it online!

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.

Japt, 7 bytes

£x +X&1

Try it online!

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

Python 2, 33 31 bytes

-2 bytes thanks to Leaky Nun

lambda x:[sum(x)-z&1for z in x]

Try it online!