Skip to main content
output method is also only loosely specified
Source Link
r.e.s.
  • 3.1k
  • 22
  • 32

(The OP only loosely specified the input method & formatoutput method/format, so the following seems acceptable.)

Sage Notebook (3939 41 40)

In the current cell,

f=lambda n,k:k<1or f(n-1,k-1)*n/k;fk;+f(*_)

where the input in the form n,k is entered & evaluated in the preceding cell. This simulates "command-line input" by assigning it to _ (similar to command-line arguments).

Sage Notebook (4242 44 43)

Alternatively, using "in-source input" (with only the x= and newline characters adding to the score), e.g.,

x=5,2
f=lambda n,k:k<1or f(n-1,k-1)*n/k;fk;+f(*x)

Both of these approaches are obviously spin-offs from earlier answers by others.

(The OP only loosely specified the input method & format, so the following seems acceptable.)

Sage Notebook (39)

In the current cell,

f=lambda n,k:k<1or f(n-1,k-1)*n/k;f(*_)

where the input in the form n,k is entered & evaluated in the preceding cell. This simulates "command-line input" by assigning it to _ (similar to command-line arguments).

Sage Notebook (42)

Alternatively, using "in-source input" (with only the x= and newline characters adding to the score), e.g.,

x=5,2
f=lambda n,k:k<1or f(n-1,k-1)*n/k;f(*x)

Both of these approaches are obviously spin-offs from earlier answers by others.

(The OP only loosely specified the input & output method/format, so the following seems acceptable.)

Sage Notebook (39 41 40)

In the current cell,

f=lambda n,k:k<1or f(n-1,k-1)*n/k;+f(*_)

where the input in the form n,k is entered & evaluated in the preceding cell. This simulates "command-line input" by assigning it to _ (similar to command-line arguments).

Sage Notebook (42 44 43)

Alternatively, using "in-source input" (with only the x= and newline characters adding to the score), e.g.,

x=5,2
f=lambda n,k:k<1or f(n-1,k-1)*n/k;+f(*x)

Both of these approaches are obviously spin-offs from earlier answers by others.

Source Link
r.e.s.
  • 3.1k
  • 22
  • 32

(The OP only loosely specified the input method & format, so the following seems acceptable.)

Sage Notebook (39)

In the current cell,

f=lambda n,k:k<1or f(n-1,k-1)*n/k;f(*_)

where the input in the form n,k is entered & evaluated in the preceding cell. This simulates "command-line input" by assigning it to _ (similar to command-line arguments).

Sage Notebook (42)

Alternatively, using "in-source input" (with only the x= and newline characters adding to the score), e.g.,

x=5,2
f=lambda n,k:k<1or f(n-1,k-1)*n/k;f(*x)

Both of these approaches are obviously spin-offs from earlier answers by others.