Skip to main content
added 560 characters in body
Source Link
Dennis
  • 210.6k
  • 41
  • 370
  • 825

Python 2, 132 130 bytes

import math,fractions
f=math.factorial
B=lambda m:~-m*m%2or 1+sum(B(k)*f(m)/f(k)/f(m-k)/fractions.Fraction(k+~m)for k in range(m))

This is just a golfed version of the reference implementation.

This is a little slow in practice, but can be sped up significantly with memoization:

import math,fractions
f=math.factorial
 
def memoize(f):
 memo = {}
 def helper(x):
  if x not in memo:
   memo[x] = f(x)
  return memo[x]
 return helper
 
@memoize
def B(m):
 return~-m*m%2or 1+sum(B(k)*f(m)/f(k)/f(m-k)/fractions.Fraction(k+~m)for k in range(m))
 
for m in range(61):
 print(B(m))

You can try this version online on Ideone.

Python, 132 130 bytes

import math,fractions
f=math.factorial
B=lambda m:~-m*m%2or 1+sum(B(k)*f(m)/f(k)/f(m-k)/fractions.Fraction(k+~m)for k in range(m))

This is just a golfed version of the reference implementation.

Python 2, 132 130 bytes

import math,fractions
f=math.factorial
B=lambda m:~-m*m%2or 1+sum(B(k)*f(m)/f(k)/f(m-k)/fractions.Fraction(k+~m)for k in range(m))

This is just a golfed version of the reference implementation.

This is a little slow in practice, but can be sped up significantly with memoization:

import math,fractions
f=math.factorial
 
def memoize(f):
 memo = {}
 def helper(x):
  if x not in memo:
   memo[x] = f(x)
  return memo[x]
 return helper
 
@memoize
def B(m):
 return~-m*m%2or 1+sum(B(k)*f(m)/f(k)/f(m-k)/fractions.Fraction(k+~m)for k in range(m))
 
for m in range(61):
 print(B(m))

You can try this version online on Ideone.

added 9 characters in body
Source Link
Dennis
  • 210.6k
  • 41
  • 370
  • 825

Python, 132132 130 bytes

import math,fractions
f=math.factorial
B=lambda m:~-m*m%2or 1+sum(B(k)*fractions.Fraction(f*f(m))/f(k)/f(m-k)/fractions.Fraction(k+~m)for k in range(m))

This is just a golfed version of the reference implementation.

Python, 132 bytes

import math,fractions
f=math.factorial
B=lambda m:~-m*m%2or 1+sum(B(k)*fractions.Fraction(f(m))/f(k)/f(m-k)/(k+~m)for k in range(m))

This is just a golfed version of the reference implementation.

Python, 132 130 bytes

import math,fractions
f=math.factorial
B=lambda m:~-m*m%2or 1+sum(B(k)*f(m)/f(k)/f(m-k)/fractions.Fraction(k+~m)for k in range(m))

This is just a golfed version of the reference implementation.

Source Link
Dennis
  • 210.6k
  • 41
  • 370
  • 825

Python, 132 bytes

import math,fractions
f=math.factorial
B=lambda m:~-m*m%2or 1+sum(B(k)*fractions.Fraction(f(m))/f(k)/f(m-k)/(k+~m)for k in range(m))

This is just a golfed version of the reference implementation.