Podcast #128: We chat with Kent C Dodds about why he loves React and discuss what life was like in the dark days before Git. Listen now.
2 added 140 characters in body
source | link

R, 70 bytes70 64 bytes

function(x,n)sum(sapply(1:n-1,function(y)x^(2*y)*(-1x^2)^y/gamma(2*y+1)))

71saved 6 bytes thanks to pizzapants184's answer with the (-x^2)^y trick

65 bytes:

function(x,n)Reduce(function(a,b)a+x^(2*b)*a+(-1x^2)^b/gamma(2*b+1),1:n-1,0)

pretty much the naive implementation of this but a tiny bit golfed; returns an anonymous function that computes the Taylor series to the specified n

  • using a Reduce takes one more byte as init has to be set to 0
  • uses gamma(n+1) instead of factorial(n)
  • 1:n-1 is equivalent to 0:(n-1)

R, 70 bytes

function(x,n)sum(sapply(1:n-1,function(y)x^(2*y)*(-1)^y/gamma(2*y+1)))

71 bytes:

function(x,n)Reduce(function(a,b)a+x^(2*b)*(-1)^b/gamma(2*b+1),1:n-1,0)

pretty much the naive implementation of this but a tiny bit golfed; returns an anonymous function that computes the Taylor series to the specified n

  • using a Reduce takes one more byte as init has to be set to 0
  • uses gamma(n+1) instead of factorial(n)
  • 1:n-1 is equivalent to 0:(n-1)

R, 70 64 bytes

function(x,n)sum(sapply(1:n-1,function(y)(-x^2)^y/gamma(2*y+1)))

saved 6 bytes thanks to pizzapants184's answer with the (-x^2)^y trick

65 bytes:

function(x,n)Reduce(function(a,b)a+(-x^2)^b/gamma(2*b+1),1:n-1,0)

pretty much the naive implementation of this but a tiny bit golfed; returns an anonymous function that computes the Taylor series to the specified n

  • using a Reduce takes one more byte as init has to be set to 0
  • uses gamma(n+1) instead of factorial(n)
  • 1:n-1 is equivalent to 0:(n-1)
1
source | link

R, 70 bytes

function(x,n)sum(sapply(1:n-1,function(y)x^(2*y)*(-1)^y/gamma(2*y+1)))

71 bytes:

function(x,n)Reduce(function(a,b)a+x^(2*b)*(-1)^b/gamma(2*b+1),1:n-1,0)

pretty much the naive implementation of this but a tiny bit golfed; returns an anonymous function that computes the Taylor series to the specified n

  • using a Reduce takes one more byte as init has to be set to 0
  • uses gamma(n+1) instead of factorial(n)
  • 1:n-1 is equivalent to 0:(n-1)