Take any type of nested list(s) containing numbers. Check for how many even/odd numbers are within and output even, same or odd (-1, 0, 1) in some way.


[[1,2,3],4,[5,6],[[7,8], 9]] => 5 odd > 4 even => odd or -1
[1,2,2,1,2,2,2]              => 5 even > 2 odd => even or 1
[1,2,2,1]                    => 2 even = 2 odd => same or 0

closed as unclear what you're asking by Peter Taylor, WolframH, John Dvorak, Johannes Kuhn, manatwork Dec 11 '13 at 12:34

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

  • 2
    \$\begingroup\$ Mind clarifying the example (and possibly provide more of them)? Your task description talks about counting odd numbers and filtering out odd numbers, but your example doesn't really show anything of that ilk at all. Also, clarifying how input/output is supposed to work would help. \$\endgroup\$ – FireFly Dec 10 '13 at 23:27
  • 2
    \$\begingroup\$ And if there are the same number? \$\endgroup\$ – Ry- Dec 11 '13 at 0:44
  • \$\begingroup\$ Then say same or 0 \$\endgroup\$ – BoollumBits Dec 11 '13 at 2:29
  • \$\begingroup\$ -1 for changing important requirements after people posted their answers. Try to avoid that next time. \$\endgroup\$ – flodel Dec 11 '13 at 11:48
  • 2
    \$\begingroup\$ @Quincunx, as I can tell, the other solutions are also using that interpretation. I think the best would be to rephrase this question as “Take any type of list containing numbers separated by any noise.” – seems that would not disqualify any existing answer. Then BoollumBits could open a new question for real nested list, with good explanation and relevant example. \$\endgroup\$ – manatwork Dec 12 '13 at 9:05

Python - 63

This returns a negative number if its got more evens, 0 if their are an equal amount or a positive number if there are more odds.

for o in x:
print i

edit: Type checking, who needs that, lets just stab blindly.

  • \$\begingroup\$ Wouldn’t list be shorter than type([])? \$\endgroup\$ – Ry- Dec 11 '13 at 0:47
  • \$\begingroup\$ @minitech yes it would :) \$\endgroup\$ – user8777 Dec 11 '13 at 0:48
  • \$\begingroup\$ @minitech not type checking is even shorter! \$\endgroup\$ – user8777 Dec 11 '13 at 0:54
  • \$\begingroup\$ This doesn't return even or odd, as required. \$\endgroup\$ – Timtech Dec 11 '13 at 0:58
  • 1
    \$\begingroup\$ @Timtech all making people say 'odd' or 'even' will do is at least 7 (usually more) characters to their code. This way its truer to the idea of golf. \$\endgroup\$ – user8777 Dec 11 '13 at 1:17

Befunge 98 - 19


Outputs 1 if even, 0 if odd or the same. I'm still trying to figure out how to indicate that they are the same. However, I have not tested this because I don't have a Befunge 98 compiler. It works as follows:

&   receives input as a number, all parts that aren't numbers are ignored and skipped
2%  takes that number and divides it by two, then gets the remainder (1 if odd, 0 if even)
6*j jump 6 characters if odd, 0 if even

when even:
\   swap top two numbers on stack (I'm storing evens under the odds)
1+  add one to that value
\   swap back
2j  jump 2 characters

when odd:
1+  add 1 to top number on stack

3j  jump 3 characters (to end of line ie the beginning (Befunge wraps))

When & is hit again, if there are no more values, it acts like a reflector, sending the instruction pointer back the other way and running this:


(executed in reverse order):

` compares the even and odd values, if even is greater, then push 1, else 0
. prints it out
@ ends the program

With one simple change, it can be made to print some negative number if there are more odds, some positive number if there are more evens, and 0 if there are the same amount:


R, 64

three possible outputs



   list(list(1, 2, 3), 4, list(5, 6), list(list(7, 8), 9)))
[1] "odd"

   list(list(2, 3), 4))
[1] "even"

  list(list(2, 3), list(4, 5)))
[1] "same"

R 58

This was written at a time the OP was asking for two "even" or "odd" possible outputs.


Example usage:

   list(list(1, 2, 3), 4, list(5, 6), list(list(7, 8), 9)))
# [1] "odd"


34 characters.

Outputs o for odd, e for even, s for same.

{"ose"1+{(x>0)-x<0}@+/-1 xexp,//x}

{(`s#-0w -.5 .5!"ose")@+/-1 xexp,//x}


{"ose"1+{(x>0)-x<0}@+/-1 xexp,//x}((1 3;5 10);12 2 4 6 8)

Golf-Basic 84, 17


Returns 0s for even numbers and 1s for odd numbers. Accepts nested arrays - 1D, 2D, 3D, 4D, etc.

Old version, 30 characters:


Explanation (for old version)


Store input in A. Accepts arrays, e.g. {1,2,3,4} or {{1,2},3,{4,5,{6,7}},8}


If (@) one or more numbers in array A are odd, display ODD. Else (#) display EVEN.

  • 1
    \$\begingroup\$ “If (@) one or more numbers in array A are odd, display ODD. Else (#) display EVEN.” That’s not the challenge. The idea is to check whether there are more even numbers than odd numbers. \$\endgroup\$ – Ry- Dec 11 '13 at 1:07
  • \$\begingroup\$ @minitech WHAT?!?! Someone SERIOUSLY edited the question!!! \$\endgroup\$ – Timtech Dec 11 '13 at 1:09
  • 1
    \$\begingroup\$ @minitech Nevermind, that was the old version. The new one outputs 1s for odd and 0s for even. \$\endgroup\$ – Timtech Dec 11 '13 at 1:11
  • \$\begingroup\$ I think that might be taking “indicate in some way” a little far :D \$\endgroup\$ – Ry- Dec 11 '13 at 1:12
  • \$\begingroup\$ @minitech I might as well, taken that Golf-Basic 84 actually runs through every digit in the array every time I put it into a mathematical equation (e.g. modulus). \$\endgroup\$ – Timtech Dec 11 '13 at 11:50

Ti-Basic 84, 26 characters

:Input A:Disp fpart(A/2)*2

Returns 1 for odd numbers and 0 for even numbers. Takes nested arrays - 1D, 2D, 3D, 4D, 5D, etc.

Old version, 50 characters:

:Input A:If fpart(A/2)*2:Disp"ODD":Else:Disp"EVEN"

Takes arrays like {1,2,3} and also {1,{2,3},4,{5,{6,7}},{{8,9},10},11}

Returns EVEN for all even and ODD if it contains odd.

  • \$\begingroup\$ The new version complies with the new requirements of measuring how many odd and even numbers there are (it displays an array of true and false). \$\endgroup\$ – Timtech Dec 11 '13 at 11:52

JavaScript, 65


Defaults to “odd” if there are equal numbers of each. Requires arrow function support, which currently means “SpiderMonkey”.

If you don’t mind output as a number, it’s just this part, at 42:


JavaScript, 51+

Variation 1, 61 or 51

Reads input via prompt, outputs via alert, encodes answer as a number with sign denoting if more evens or odds.

b=0;prompt().replace(/\d+/g,function(s){b+=s%2*2-1});alert(b) // ES5, 61
b=0;prompt().replace(/\d+/g,s=>b+=s%2*2-1);alert(b) // ES6, 51

Variation 2, 72 or 49

As above, but as a function taking an array instead of using prompt/alert.

function f(s){b=0;return s.big?b+=s%2*2-1:s.join().replace(/\d+/g,f)&&b} // ES5, 72
f=a=>b=0,a.join().replace(/\d+/g,s=>b+=s%2*2-1),b // ES6, 49

Not the answer you're looking for? Browse other questions tagged or ask your own question.