Skip to main content
replaced http://codegolf.stackexchange.com/ with https://codegolf.stackexchange.com/
Source Link

J, 15 13 bytes

There is also the builtin t: which calculates the nth coefficient of the exponential generating function of tan(x).

(1&o.%2&o.)t:

Thanks to @Leaky NunLeaky Nun for reminding me of Taylor series adverbs in J which saved 2 bytes.

Alternative for 15 bytes.

3 :'(3&o.d.y)0'

Another approach is to calculate the nth derivative of tan(x) and evaluate it at x = 0.

Note: In J, the amount of memory used by the derivative function d. grows quickly as n passes 10.

Usage

   f =: (1&o.%2&o.)t:
   f 7
272
   (,.f"0) i. 11  NB. Additional commands are just for formatting the output
 0    0
 1    1
 2    0
 3    2
 4    0
 5   16
 6    0
 7  272
 8    0
 9 7936
10    0

Explanation

(1&o.%2&o.)t:  Input: n
(         )    Define a monad (one argument function), call the input y
 1&o.          Get the trig function sin(x) and call it on y
      2&o.     Get the trig function cos(x) and call it on y
     %         Divide sin(y) by cos(y) to get tan(y)
           t:  Get the nth coefficient of the exponential generating series
               for that function and return

3 :'(3&o.d.y)0'  Input: n
3 :'          '  Define a monad (one argument function) with input y
     3&o.        Get the trig function tan(x)
           y     The input n
         d.      Get the nth derivative of tan(x)
             0   Evaluate the nth derivative at x = 0 and return

J, 15 13 bytes

There is also the builtin t: which calculates the nth coefficient of the exponential generating function of tan(x).

(1&o.%2&o.)t:

Thanks to @Leaky Nun for reminding me of Taylor series adverbs in J which saved 2 bytes.

Alternative for 15 bytes.

3 :'(3&o.d.y)0'

Another approach is to calculate the nth derivative of tan(x) and evaluate it at x = 0.

Note: In J, the amount of memory used by the derivative function d. grows quickly as n passes 10.

Usage

   f =: (1&o.%2&o.)t:
   f 7
272
   (,.f"0) i. 11  NB. Additional commands are just for formatting the output
 0    0
 1    1
 2    0
 3    2
 4    0
 5   16
 6    0
 7  272
 8    0
 9 7936
10    0

Explanation

(1&o.%2&o.)t:  Input: n
(         )    Define a monad (one argument function), call the input y
 1&o.          Get the trig function sin(x) and call it on y
      2&o.     Get the trig function cos(x) and call it on y
     %         Divide sin(y) by cos(y) to get tan(y)
           t:  Get the nth coefficient of the exponential generating series
               for that function and return

3 :'(3&o.d.y)0'  Input: n
3 :'          '  Define a monad (one argument function) with input y
     3&o.        Get the trig function tan(x)
           y     The input n
         d.      Get the nth derivative of tan(x)
             0   Evaluate the nth derivative at x = 0 and return

J, 15 13 bytes

There is also the builtin t: which calculates the nth coefficient of the exponential generating function of tan(x).

(1&o.%2&o.)t:

Thanks to @Leaky Nun for reminding me of Taylor series adverbs in J which saved 2 bytes.

Alternative for 15 bytes.

3 :'(3&o.d.y)0'

Another approach is to calculate the nth derivative of tan(x) and evaluate it at x = 0.

Note: In J, the amount of memory used by the derivative function d. grows quickly as n passes 10.

Usage

   f =: (1&o.%2&o.)t:
   f 7
272
   (,.f"0) i. 11  NB. Additional commands are just for formatting the output
 0    0
 1    1
 2    0
 3    2
 4    0
 5   16
 6    0
 7  272
 8    0
 9 7936
10    0

Explanation

(1&o.%2&o.)t:  Input: n
(         )    Define a monad (one argument function), call the input y
 1&o.          Get the trig function sin(x) and call it on y
      2&o.     Get the trig function cos(x) and call it on y
     %         Divide sin(y) by cos(y) to get tan(y)
           t:  Get the nth coefficient of the exponential generating series
               for that function and return

3 :'(3&o.d.y)0'  Input: n
3 :'          '  Define a monad (one argument function) with input y
     3&o.        Get the trig function tan(x)
           y     The input n
         d.      Get the nth derivative of tan(x)
             0   Evaluate the nth derivative at x = 0 and return
added 773 characters in body
Source Link
miles
  • 17k
  • 2
  • 30
  • 94

J, 1515 13 bytes

There is also the builtin t: which calculates the nth coefficient of the exponential generating function of tan(x).

(1&o.%2&o.)t:

Thanks to @Leaky Nun for reminding me of Taylor series adverbs in J which saved 2 bytes.

Alternative for 15 bytes.

3 :'(3&o.d.y)0'

Straight-forwardAnother approach. Calculate is to calculate the nth derivative of tan(x) and evaluate it at x = 0.

Note: In J, the amount of memory used by the derivative function d. grows quickly as n passes 10.

Usage

   f =: 3 :'(3&o1&o.d%2&o.y)0't:
   f 7
272
   (,.f"0) i. 11  NB. Additional commands are just for formatting the output
 0    0
 1    1
 2    0
 3    2
 4    0
 5   16
 6    0
 7  272
 8    0
 9 7936
10    0

Explanation

(1&o.%2&o.)t:  Input: n
(         )    Define a monad (one argument function), call the input y
 1&o.          Get the trig function sin(x) and call it on y
      2&o.     Get the trig function cos(x) and call it on y
     %         Divide sin(y) by cos(y) to get tan(y)
           t:  Get the nth coefficient of the exponential generating series
               for that function and return

3 :'(3&o.d.y)0'  Input: n
3 :'          '  Define a monad (one argument function) with input y
     3&o.        Get the trig function tan(x)
           y     The input n
         d.      Get the nth derivative of tan(x)
             0   Evaluate the nth derivative at x = 0 and return

J, 15 bytes

3 :'(3&o.d.y)0'

Straight-forward approach. Calculate the nth derivative of tan(x) and evaluate it at x = 0.

Note: In J, the amount of memory used by the derivative function d. grows quickly as n passes 10.

Usage

   f =: 3 :'(3&o.d.y)0'
   f 7
272
   (,.f"0) i. 11  NB. Additional commands are just for formatting the output
 0    0
 1    1
 2    0
 3    2
 4    0
 5   16
 6    0
 7  272
 8    0
 9 7936
10    0

Explanation

3 :'(3&o.d.y)0'  Input: n
3 :'          '  Define a monad (one argument function) with input y
     3&o.        Get the trig function tan(x)
           y     The input n
         d.      Get the nth derivative of tan(x)
             0   Evaluate the nth derivative at x = 0 and return

J, 15 13 bytes

There is also the builtin t: which calculates the nth coefficient of the exponential generating function of tan(x).

(1&o.%2&o.)t:

Thanks to @Leaky Nun for reminding me of Taylor series adverbs in J which saved 2 bytes.

Alternative for 15 bytes.

3 :'(3&o.d.y)0'

Another approach is to calculate the nth derivative of tan(x) and evaluate it at x = 0.

Note: In J, the amount of memory used by the derivative function d. grows quickly as n passes 10.

Usage

   f =: (1&o.%2&o.)t:
   f 7
272
   (,.f"0) i. 11  NB. Additional commands are just for formatting the output
 0    0
 1    1
 2    0
 3    2
 4    0
 5   16
 6    0
 7  272
 8    0
 9 7936
10    0

Explanation

(1&o.%2&o.)t:  Input: n
(         )    Define a monad (one argument function), call the input y
 1&o.          Get the trig function sin(x) and call it on y
      2&o.     Get the trig function cos(x) and call it on y
     %         Divide sin(y) by cos(y) to get tan(y)
           t:  Get the nth coefficient of the exponential generating series
               for that function and return

3 :'(3&o.d.y)0'  Input: n
3 :'          '  Define a monad (one argument function) with input y
     3&o.        Get the trig function tan(x)
           y     The input n
         d.      Get the nth derivative of tan(x)
             0   Evaluate the nth derivative at x = 0 and return
added 65 characters in body
Source Link
miles
  • 17k
  • 2
  • 30
  • 94

J, 15 bytes

3 :'(3&o.d.y)0'

Straight-forward approach. Calculate the nth derivative of tan(x) and evaluate it at x = 0. 

Note: In JJ, the amount of memory used by the derivative function d. grows quickly as n passes 10.

Usage

   f =: 3 :'(3&o.d.y)0'
   f 7
272
   (,.f"0) i. 11  NB. Additional commands are just for formatting the output
 0    0
 1    1
 2    0
 3    2
 4    0
 5   16
 6    0
 7  272
 8    0
 9 7936
10    0

Explanation

3 :'(3&o.d.y)0'  Input: n
3 :'          '  Define a monad (one argument) function) with input y
     3&o.        Get the trig function tan(x)
           y     The input n
         d.      Get the nth derivative of tan(x)
             0   Evaluate the nth derivative at x = 0 and return

J, 15 bytes

3 :'(3&o.d.y)0'

Straight-forward approach. Calculate the nth derivative of tan(x) and evaluate it at x = 0. Note: In J, the amount of memory used by the derivative function d. grows quickly as n passes 10.

Usage

   f =: 3 :'(3&o.d.y)0'
   f 7
272
   (,.f"0) i. 11
 0    0
 1    1
 2    0
 3    2
 4    0
 5   16
 6    0
 7  272
 8    0
 9 7936
10    0

Explanation

3 :'(3&o.d.y)0'  Input: n
3 :'          '  Define a monad (one argument) function with input y
     3&o.        Get the trig function tan(x)
           y     The input n
         d.      Get the nth derivative of tan(x)
             0   Evaluate the nth derivative at x = 0 and return

J, 15 bytes

3 :'(3&o.d.y)0'

Straight-forward approach. Calculate the nth derivative of tan(x) and evaluate it at x = 0. 

Note: In J, the amount of memory used by the derivative function d. grows quickly as n passes 10.

Usage

   f =: 3 :'(3&o.d.y)0'
   f 7
272
   (,.f"0) i. 11  NB. Additional commands are just for formatting the output
 0    0
 1    1
 2    0
 3    2
 4    0
 5   16
 6    0
 7  272
 8    0
 9 7936
10    0

Explanation

3 :'(3&o.d.y)0'  Input: n
3 :'          '  Define a monad (one argument function) with input y
     3&o.        Get the trig function tan(x)
           y     The input n
         d.      Get the nth derivative of tan(x)
             0   Evaluate the nth derivative at x = 0 and return
Source Link
miles
  • 17k
  • 2
  • 30
  • 94
Loading