Counting ways of scoring k points in n games with half-points for draws If a game can result in a win, worth one point; a draw, worth half a point; or a loss, worth no points; how many ways are there of scoring k points in n games?

Applicable scenarios include NFL and chess.


Input is via stdin, and consists of n and k on separate lines.
n will be a non-negative integer. (n ≤ 16)
k will be either a non-negative integer or a non-negative integer plus a half. (k ≤ n)
Output is to stdout. It may, but does not have to, include a trailing newline.


Test cases

In each case, the first two lines are user-supplied input and the third line is the program output.

10
4.5
8350

16
8
5196627

16
13.5
13328

12
12
1
Perl 59 bytes

@0=map"$v"+($v=$u)+($u=$_),@0,0,0for(@0=1)x&lt;&gt;;print@0[&lt;&gt;*2]


Iteratively generates each row of the triangle of trinomial coefficients up to n, and then prints the correct term, 2k.



Ruby 73 bytes

r=*1
gets.to_i.times{r&lt;&lt;0&lt;&lt;u=v=0;r.map!{|t|v+(v=u)+u=t}}
p r[gets.to_f*2]


Largely equivalent to the Perl solution above.



Python 84 bytes

r=[1]
exec"r=map(sum,zip(r+[0],[0]+r,[0,0]+r))+[1];"*input()
print r[int(input()*2)]


Same method as both solutions above.



PHP 91 bytes

&lt;?for($n=+fgets(STDIN);(${$j--}+=$$j+${$j-1})?:$n--*$j=$i+=2;${0}=1);echo${fgets(STDIN)*2};


Despite being the longest, this was actually the most fun to work on.