Skip to main content
added 108 characters in body
Source Link
pajonk
  • 18.3k
  • 3
  • 25
  • 74

R, 3030 29 bytes

Or **R>=4.1, 2322 bytes by replacing the word function with a \.

Edit: -1 byte thanks to @Giuseppe.

function(v)sum(v%%2)%in%c(0,/2)%in%0:1

Try it online!Try it online!

TheAlmost straightforward approach.

Less straightforward, but used by many other answers, approach results in the same byte-count:

function(v)abs(sum(v%%2)-1)==1^2==1

Try it online!Try it online!

R, 30 bytes

Or **R>=4.1, 23 bytes by replacing the word function with a \.

function(v)sum(v%%2)%in%c(0,2)

Try it online!

The straightforward approach.

Less straightforward, but used by many other answers, approach results in the same byte-count:

function(v)abs(sum(v%%2)-1)==1

Try it online!

R, 30 29 bytes

Or **R>=4.1, 22 bytes by replacing the word function with a \.

Edit: -1 byte thanks to @Giuseppe.

function(v)sum(v%%2/2)%in%0:1

Try it online!

Almost straightforward approach.

Less straightforward, but used by many other answers, approach results in the same byte-count:

function(v)(sum(v%%2)-1)^2==1

Try it online!

Source Link
pajonk
  • 18.3k
  • 3
  • 25
  • 74

R, 30 bytes

Or **R>=4.1, 23 bytes by replacing the word function with a \.

function(v)sum(v%%2)%in%c(0,2)

Try it online!

The straightforward approach.

Less straightforward, but used by many other answers, approach results in the same byte-count:

function(v)abs(sum(v%%2)-1)==1

Try it online!