Skip to main content
added 24 characters in body
Source Link
xnor
  • 149.7k
  • 26
  • 287
  • 676

Haskell, 21 bytes

n%a=product[n,n-a..1] 

Try it online!

Combining the built-in product function with stepped range enumeration beats what I could code up recursively (even with flawr saving a byte).

2322 bytes

n%a|n<1=1 n%a=n*(n%a|n<1=1|m<-n-a)%aa=n*m%a 

Try it online!Try it online!

Here's a solution taking input in string format like 9!!, which I think is more interesting.

42 bytes

(\[(n,a)]->product[n,n-length a..1]).reads 

Try it online!

Haskell, 21 bytes

n%a=product[n,n-a..1] 

Try it online!

Combining the built-in product function with stepped range enumeration beats what I could code up recursively.

23 bytes

n%a|n<1=1 n%a=n*(n-a)%a 

Try it online!

Here's a solution taking input in string format like 9!!, which I think is more interesting.

42 bytes

(\[(n,a)]->product[n,n-length a..1]).reads 

Try it online!

Haskell, 21 bytes

n%a=product[n,n-a..1] 

Try it online!

Combining the built-in product function with stepped range enumeration beats what I could code up recursively (even with flawr saving a byte).

22 bytes

n%a|n<1=1|m<-n-a=n*m%a 

Try it online!

Here's a solution taking input in string format like 9!!, which I think is more interesting.

42 bytes

(\[(n,a)]->product[n,n-length a..1]).reads 

Try it online!

Source Link
xnor
  • 149.7k
  • 26
  • 287
  • 676

Haskell, 21 bytes

n%a=product[n,n-a..1] 

Try it online!

Combining the built-in product function with stepped range enumeration beats what I could code up recursively.

23 bytes

n%a|n<1=1 n%a=n*(n-a)%a 

Try it online!

Here's a solution taking input in string format like 9!!, which I think is more interesting.

42 bytes

(\[(n,a)]->product[n,n-length a..1]).reads 

Try it online!