def fixation_prob(n, m, a): matrix = [[0 for i in range(len(a))] for j in range(m)] # Population is diploid so number of alleles is 2N n = 2*n for i in range(len(a)): # Frequency of each number of recessive alleles in the current pop. curr_gen = [0 for x in range(n+1)] curr_gen[a[i]] = 1 # For each generatjon... for gen in range(m): next_gen = [0 for x in range(n+1)] for j in range(n+1): # frequency in next generation... for k in range(n+1): # frequency in current geneneration... p1 = f(n) / f(j) / f(n-j) p2 = (k/n)**j * (1-(k/n))**(n-j) p3 = curr_gen[k] next_gen[j] += p1 * p2 * p3 curr_gen = next_gen # Store the common logarithm of the answer. matrix[gen][i] = log10(curr_gen[0]) return matrix
def main(): size = 20 # size 'rights' + size 'downs' # combinations formula steps = size * 2 result = f(steps) / (f(size) * f(steps - size)) print('Result: ', int(result))
def perms(alist): acounter = Counter(alist) n = len(alist) ans = f(n) for key in acounter: ans /= f(acounter[key]) return ans
def handle(self, *args, **options): school_dict = dict() for m in Project.objects.filter( category="micro_sumo",is_confirmed=True): if school_dict.has_key(m.manager.school): school_dict[m.manager.school] += 1 else: school_dict[m.manager.school] = 1 school_pairs = school_dict.items() school_pairs.sort(key=lambda tup: tup[1]) school_list = map(lambda x: x[0], school_pairs) robot_count = sum(school_dict.values()) # generate groups if robot_count % 4 == 1: group_count = robot_count / 4 elif robot_count % 4 == 2: group_count = robot_count / 4 + 1 elif robot_count % 4 == 3: group_count = robot_count / 4 + 1 elif robot_count % 4 == 0: group_count = robot_count / 4 for i in range(1, group_count+1): SumoGroup.objects.create(order=i, is_final=False) group_list = SumoGroup.objects.filter(is_final=False) active_groups = list(group_list) passive_groups = list() shuffle(active_groups) for school in school_list: for m in Project.objects.filter( category="micro_sumo", manager__school=school, is_confirmed=True): if len(active_groups) == 0: active_groups = passive_groups[:] shuffle(active_groups) passive_groups = list() current_group = active_groups.pop() passive_groups.append(current_group) SumoGroupTeam.objects.create( group=current_group, robot=m) self.stdout.write('Sumo groups generated.') for group in SumoGroup.objects.all(): order = 1 teams = SumoGroupTeam.objects.filter(group=group) team_list = list(teams) count = len(team_list) for j in range(f(count) / f(2) / f(count-2) / 2): for i in range(0, len(team_list) / 2): SumoGroupMatch.objects.create( home=team_list[i].robot, away=team_list[len(team_list) - i - 1].robot, group=group, order=order) order += 1 hold = team_list.pop() team_list.insert(1, hold) self.stdout.write("Fixtures generated.")
def pure_py(xyz, Snlm, Tnlm, nmax, lmax): from scipy.special import lpmv, gegenbauer, eval_gegenbauer, gamma from math import factorial as f Plm = lambda l,m,costh: lpmv(m, l, costh) Ylmth = lambda l,m,costh: np.sqrt((2*l+1)/(4 * np.pi) * f(l-m)/f(l+m)) * Plm(l,m,costh) twopi = 2*np.pi sqrtpi = np.sqrt(np.pi) sqrt4pi = np.sqrt(4*np.pi) r = np.sqrt(np.sum(xyz**2, axis=0)) X = xyz[2]/r # cos(theta) sinth = np.sqrt(1 - X**2) phi = np.arctan2(xyz[1], xyz[0]) xsi = (r - 1) / (r + 1) density = 0 potenti = 0 gradien = np.zeros_like(xyz) sph_gradien = np.zeros_like(xyz) for l in range(lmax+1): r_term1 = r**l / (r*(1+r)**(2*l+3)) r_term2 = r**l / (1+r)**(2*l+1) for m in range(l+1): for n in range(nmax+1): Cn = gegenbauer(n, 2*l+3/2) Knl = 0.5 * n * (n+4*l+3) + (l+1)*(2*l+1) rho_nl = Knl / twopi * sqrt4pi * r_term1 * Cn(xsi) phi_nl = -sqrt4pi * r_term2 * Cn(xsi) density += rho_nl * Ylmth(l,m,X) * (Snlm[n,l,m]*np.cos(m*phi) + Tnlm[n,l,m]*np.sin(m*phi)) potenti += phi_nl * Ylmth(l,m,X) * (Snlm[n,l,m]*np.cos(m*phi) + Tnlm[n,l,m]*np.sin(m*phi)) # derivatives dphinl_dr = (2*sqrtpi*np.power(r,-1 + l)*np.power(1 + r,-3 - 2*l)* (-2*(3 + 4*l)*r*eval_gegenbauer(-1 + n,2.5 + 2*l,(-1 + r)/(1 + r)) + (1 + r)*(l*(-1 + r) + r)*eval_gegenbauer(n,1.5 + 2*l,(-1 + r)/(1 + r)))) sph_gradien[0] += dphinl_dr * Ylmth(l,m,X) * (Snlm[n,l,m]*np.cos(m*phi) + Tnlm[n,l,m]*np.sin(m*phi)) A = np.sqrt((2*l+1) / (4*np.pi)) * np.sqrt(gamma(l-m+1) / gamma(l+m+1)) dYlm_dth = A / sinth * (l*X*Plm(l,m,X) - (l+m)*Plm(l-1,m,X)) sph_gradien[1] += (1/r) * dYlm_dth * phi_nl * (Snlm[n,l,m]*np.cos(m*phi) + Tnlm[n,l,m]*np.sin(m*phi)) sph_gradien[2] += (m/(r*sinth)) * phi_nl * Ylmth(l,m,X) * (-Snlm[n,l,m]*np.sin(m*phi) + Tnlm[n,l,m]*np.cos(m*phi)) cosphi = np.cos(phi) sinphi = np.sin(phi) gradien[0] = sinth*cosphi*sph_gradien[0] + X*cosphi*sph_gradien[1] - sinphi*sph_gradien[2] gradien[1] = sinth*sinphi*sph_gradien[0] + X*sinphi*sph_gradien[1] + cosphi*sph_gradien[2] gradien[2] = X*sph_gradien[0] - sinth*sph_gradien[1] return density, potenti, gradien
def solve(fname): v,c = read_connections(fname) c = sorted(c,key=lambda x:x[2]) from math import factorial as f n = len(c) print(f(n)/f(n-v+1)/f(v-1)) for subset in itertools.combinations(c,v-1): if fully_connected(v,subset): return weight(c)-weight(subset)
def surprise_value(ss): from dist import simple_dist from math import factorial as f if len(ss) < 2: return 0 l = len(ss) nC2 = f(l) / 2 / f(l-2) total_dist = sum(simple_dist(a,b) for (a,b) in itertools.combinations(ss,2)) return total_dist / nC2
def cntMatrix(self, A): # determine how far columns are sorted N, count = len(A), 0 for i in xrange(1, N + 1): if N % i == 0: # check if all i chunks of array are sorted if self.chunkSortedChecker(i, A): print 'For i: ', i, pow(f(i), N / i, mod) count += pow(f(i), N / i, mod) return count % mod
def bp_prob(s, a, b, k): n = len(s) N = count_kmers(s, 1) nn = [(i[1], i[0] in [a,b]) for i in N.items()] if k > min(N[a],N[b]) or k < 0: return 0 ns = sum([( f(n-j) / ( reduce(lambda x,y: x*( f(y[0] - (j if y[1] else 0) ) ) , nn, 1) * f(j-k) * f(k) ) ) * (-1)**(j-k)\ for j in range(k,min(N[a],N[b])+1)]) return (ns / ( f(n) / ( reduce(lambda x,y: x*f(y[0]) , nn, 1) ) / 10**100 ) )*(10.0**(-100))
def getPermutation(self, n, k): from math import factorial as f nums = range(1, n + 1) result = '' for i in range(n): q, r = k / f(n - 1 - i), k % f(n - 1 - i) if r > 0: q += 1 result += str(nums[q - 1]) nums.remove(nums[q - 1]) k = r return result
def solve_equation(a, b, c): d = b * b - 4 * a * c if d > 0: x1 = (-b + f(d)) / (2 * a) x2 = (-b - f(d)) / (2 * a) return x1, x2 elif d == 0: x = -b / (2 * a) return x, x else: x1 = complex(-b / (2 * a), f(-d) / (2 * a)) x2 = complex(-b / (2 * a), -f(-d) / (2 * a)) return x1, x2
def foo(num): a=[num] while 1: tmp=sum([f(int(i)) for i in list(str(a[-1]))]) if tmp in a: break a.append(tmp) return len(a)
def factorial_digits(x): x = str(x) total = 0 for c in x: total += f(int(c)) return total
def ncr(n,r): a = max(n-r,r) b = min(n-r,r) fac = 1 while n>a: fac *= n n -= 1 return fac/f(b)
def factorial_sum(n): if type(n) != list: n = list(str(n)) for j,i in enumerate(n): n[j] = int(i) sum = 0 for i in n: sum = sum + f(i) return sum
def main(): # the max that we can reach is 9! * the number of digits i = 1 lim = f(9) while lim * i > pow(10, i): i += 1 lim *= i return sum([n for n in xrange(lim + 1) if is_factorian(n)])
def foo2(num): a=[num] while 1: if a[-1] in b: tmp=b[a[-1]] else: tmp=sum([f(int(i)) for i in list(str(a[-1]))]) b[a[-1]]=tmp if tmp in a: break a.append(tmp) return len(a)
def __init__(self,h=5,w=8): bdata = [] ndata = [] mdata = [] for l in range(h): line1 = [] line2 = [] line3 = [] for c in range(w): line1 += [int(f(l+c)/(f(l+c-c)*f(c)))] line2 += [0] line3 += [0] ndata += [line1] bdata += [line2] mdata += [line3] bdata.reverse() ndata.reverse() self.h, self.w = h, w self.bdata = bdata self.ndata = ndata self.score = None
def getExpansion(beta_i,tList,lambda_s,alpha): term1 = [ alpha*np.exp(-beta_i*0.5)*np.exp(-1j*beta_i*t) / \ (2*beta_i*np.sinh(beta_i/2))+ \ alpha*np.exp(beta_i*0.5)*np.exp(1j*beta_i*t) /\ (-2*beta_i*np.sinh(-beta_i/2))\ for t in tList] expansionVersion = [0.0]*len(term1) for t_i in range(len(tList)): for n in range(100): expansionVersion[t_i] += ((np.exp(-alpha*lambda_s)/f(n))*term1[t_i]**n) return expansionVersion
def check(stars, smin=0, smax=2): if len(stars) == 0: return True len_s = len(stars) combos = f(len_s) / (f(len_s - 2) * 2) valid_combos = len( [pair for pair in combinations(stars, 2) if not adjacent(*pair)]) if not (combos == valid_combos): return False for i in range(10): # Column check col_count = sum([1 if p % 10 == i else 0 for p in stars]) if not (smin <= col_count <= smax): return False # Row check row_count = sum([1 if p // 10 == i else 0 for p in stars]) if not (smin <= row_count <= smax): return False group_count = len(positions[i] & stars) if not (smin <= group_count <= smax): return False return True
def form_Q(self): Q_list = [] for l in range(1,self.m+1): Q_i=np.zeros(shape=(self.n,self.n)) for i in range(self.n): for j in range(self.n): if (((i>3) and (j<=3))) or (((j>3) and (i<=3))): Q_i[i][j]=0 elif (i<=3) and (j<=3): Q_i[i][j]=0 else: r,c=i+1,j+1 Q_i[i][j]= (f(r)*f(c)*(pow(self.t[l],r+c-7)-pow(self.t[l-1],r+c-7)))/(f(r-4)*f(c-4)*(r+c-7)) Q_list.append(Q_i) Q = Q_list[0] Q_list.pop(0) for i in Q_list: Q=block_diag(Q,i) self.Q=Q+(0.0001*np.identity(self.n*self.m)) print(type(self.Q),'typeofQ')
def buildHeap(arr, n): ''' :param arr: given array :param n: size of array :return: None ''' arr.insert(0, None) # adding None start, stop, step = f(n / 2), 0, -1 for i in range(start, stop, step): heapify(arr, n, i) heap_sort(arr, n) del arr[0] # removing None
def __getitem__(self, n): assert type(n) == int, 'Moment number must be an integer' m = 0 a = np.real(self.fs[0]) for i in range(1000): try: change = 2 * pi / f(i) * np.conj(((self.fs)**i)[n]) except IndexError: continue m += change if abs(change) < 2**-10: break return m
def missing4(my_list): n = 100 mul_list = reduce(lambda x, y: x * y, my_list) x_mul_y = f(n) // mul_list x_add_y = n * (n + 1) // 2 - sum(my_list) """ Substituting x from x_add_y to x*y=x_mul_y, gives us polynomial equation : x**2 - x_add_y * x + x_mul_y = 0 Now, Lets solve this polynomial equation using numpy module. """ coef = [1, -x_add_y, x_mul_y] x = np.roots(coef) # Gives the two possible values of x. print(f'Two missing numbers are: {int(x[0])}, {int(x[1])}')
def pdf(self, k): """Probability density function calculator for the gaussian distribution. Args: k (float): point for calculating the probability density function Returns: float: probability density function output """ # TODO: Calculate the probability density function for a binomial distribution # For a binomial distribution with n trials and probability p, # the probability density function calculates the likelihood of getting # k positive outcomes. # # For example, if you flip a coin n = 60 times, with p = .5, # what's the likelihood that the coin lands on heads 40 out of 60 times? function = (f(self.n) / (f(k) * f(self.n - k))) * (self.p**k) * ( (1 - self.p)**(self.n - k)) return function
def probability(n, m, g, k): # Population is diploid so number of alleles is 2N n = 2*n # Hold the frequency of each number of dominant alleles in the current pop. curr_gen = [0 for i in range(n+1)] curr_gen[m] = 1 # For each generation... for gen in range(g): next_gen = [0 for i in range(n+1)] for i in range(n+1): # next generation... for j in range(n+1): # current geneneration... a = f(n) / f(i) / f(n-i) b = (j/n)**i * (1-(j/n))**(n-i) c = curr_gen[j] next_gen[i] += a * b * c curr_gen = next_gen return sum(curr_gen[:-k])
def solution(n, k): result = [] # 1~n까지의 배열 생성 line = list(range(1, n + 1)) while line: # 맨 앞자리수가 같은 수의 개수는 (n-1)! factorial = f(len(line) - 1) # 차례대로 존재하는 line 앞자리수의 인덱스를 구하기 result.append(line.pop((k - 1) // factorial)) k %= factorial return result
def main(): # how many lattice-routes (right, down) are there through a 20x20 grid? n = (20,20) path_length = n[0] ''' # n! ouch! one_route = [0 for i in xrange(n[0])] + [1 for i in xrange(n[0])] # one-route right:0, down:1 all_routes = set(list(permutations(one_route))) return len(all_routes) # this method assumes symmetry for grid # calculating combinations is much faster than permutations... like n^2 ? return len(list(combinations(range(path_length*2),path_length))) ''' # I think we can do better... # oh duh... we don't need a list of all the paths, # just get the number -> use math: # n! / ( r! (n - r)! ) n = path_length*2 r = path_length ret = f(n)/( f(r) * f(n-r) ) return ret
def calc(s): a, b = map(int, s.split(':')) if a < b: a, b = b, a if b < 24: return f(24 + b) // f(24) // f(b) return f(48) // f(24) // f(24) * 2**(b - 24)
def calc(s, k): a, b = map(int, s.split(':')) if a < b: a, b = b, a if b < k: return f(k + b) // f(k) // f(b) return f(2 * k) // f(k) // f(k) * 2**(b - k)
def getPermutation(self, n: int, k: int) -> str: k -= 1 arr = list(range(1, n + 1)) indices = [] step = f(n) while k != 0: step //= n i, k = divmod(k, step) indices.append(i) n -= 1 result = [] for i in indices: result.append(arr[i]) del arr[i] return "".join(map(str, result + arr))
def col(n): v=[n] sol=0 while True: n=sum(list(map(lambda x: f(int(x)),str(n)))) if n in v: break v.append(n) if n<1000001: if A[n]!=0: sol=A[n] break v=v[::-1] for i in range(len(v)): if v[i]<1000001: A[v[i]]=sol sol+=1
def func(): n = 0 x = n t1 = time.time() while n < 100000000000: if n == sum(f(int(d)) for d in str(n)): print("{}: {}".format(n, True)) n += 1 else: n += 1 y = n t2 = time.time() print("\nFirst item: {}".format(x)) print("Last item checked: {}".format(y)) print("Time taken: {}s".format(round(t2 - t1, 4)))
def doTriangle(delta): betas = list(np.linspace(beta_i-delta,beta_i+delta,101)) rho = [getRho(beta,delta,beta_i) for beta in betas] rhoArea = np.trapz(rho,x=betas) rho = [x/rhoArea for x in rho] P = [rho[b]/(2.0*betas[b]*np.sinh(betas[b]*0.5)) for b in range(len(betas))] integral = [alpha*np.trapz([P[b]*np.exp(-beta*0.5)*np.exp(-1j*beta*t) + \ P[b]*np.exp( beta*0.5)*np.exp( 1j*beta*t) \ for b,beta in enumerate(betas)],x=betas) for t in tList] triangleVersion = [0.0]*len(integral) for t_i in range(len(tList)): for n in range(50): triangleVersion[t_i] += ((np.exp(-alpha*lambda_s)/f(n))*integral[t_i]**n) return triangleVersion
def solve(): m = f(9) for i in range(1,10): if i*m < 10**(i-1): lim = 10**(i-1) break n = 10 s = 0 while n < lim: p = f_sum(n) if p == n: s += n if p > n: n = (n//10 + 1)*10 else: n += 1 return s
def main(): # Seek to find the number of non-repeating chains below one million # that have 60 terms # Upper limit lim = 1000000 # First populate a cache of the factorials so we don't repeat them factorials = dict((str(n), f(n)) for n in range(10)) # Cache chain lengths chain_lengths = {} for n in xrange(lim): current_chain = [] current_chain.append(n) new = n while True: new = sum(factorials[i] for i in str(new)) if new in chain_lengths: # We know how long this chain is break if new in current_chain: # repeated digit, chain is over break current_chain.append(new) # Find the additional contribution from the last sum additional_size = chain_lengths.get(new, 0) for i, num in enumerate(current_chain): if num not in chain_lengths: chain_lengths[num] = additional_size + len(current_chain) - i # Find all chains that are 60 sections long before they repeat # Note: in python, True is treated as 1 and False as 0 solution = sum(value == 60 for value in chain_lengths.values()) return solution
def poisson_pmf(rate, k): '''Given the rate, and k, the number of successes, write a function that calculates the PMF, E(X) and Var(X) of the Poisson distribution. In: The rate, k: number of successes; both ints or floats Out: PMF, E(X), Var(X); all ints or floats Ex: poisson_pmf(5, 0) >>>0.006737946999085469, 5, 5''' e = math.e numer = (rate**k) * (e**-rate) denom = f(k) pmf = numer / denom ex = rate varx = rate return pmf, ex, varx
def checkNthTerm(): ar = list('abcdefghijklm') term = int(input().strip()) - 1 length = 12 # this is len(ar)-1 string = '' while length: spam = f(length) egg = term // spam if term < spam: string += ar.pop(0) else: egg = term // spam string += ar.pop(egg) term -= (spam * egg) length -= 1 for item in ar: string += item print(string)
def numPairsDivisibleBy60(self, time: List[int]) -> int: time_simp = list(map(lambda x: x % 60, time)) time_simp.sort() dic = {} for i in time_simp: if i not in dic.keys(): dic[i] = 1 else: dic[i] += 1 counter = 0 for i in range(1, 30): if i not in dic.keys() or (60 - i) not in dic.keys(): continue counter += dic[i] * dic[60 - i] if 0 in dic.keys(): num = dic[0] if num >= 2: counter += f(num) // (f(num - 2) * f(2)) # n choose 2 if 30 in dic.keys(): num = dic[30] if num >= 2: counter += f(num) // (f(num - 2) * f(2)) # n choose 2 return counter
from math import factorial as f s = int(input()) div = s // 3 mod = s % 3 a = 10**9 + 7 res = 0 while div != 0: res = (res + f(div - 1 + mod) // (f(div - 1) * f(mod))) % a div -= 1 mod += 3 print(res)
def CatalanNumber(index): from math import factorial as f return f(2 * index) // (f(index) * f(index + 1))
from math import factorial as f print(int(f(40) / f(20)**2))
def cycle_count(cycle, n): return reduce(lambda cc, e: cc // (e[0]**e[1] * f(e[1])), Counter(cycle).items(), f(n))
def a(n): return f(2*n) / (f(n) ** 2) print a(20)
from math import factorial as f stringNum = list(map(str,range(10,100000))) facts = list(filter(lambda n: sum(map(lambda l: f(int(l)),n)) == int(n), stringNum)) facts = list(map(int, facts)) print(sum(facts))
from math import factorial as f ftable = {i:f(i) for i in range(10)} result = 0 for n in range(69, 1000000): chain = [] term = n while term not in chain: chain.append(term) if len(chain) == 60: #print (chain) result += 1 break term = sum (map(lambda x: ftable[int(x)], str(term))) print (result)
from math import factorial as f fact, ans, mod = [ f( i ) for i in range( 1001 ) ], [ 1 ] + [ 0 ] * 1000, 10056 for horse in range( 1, 1001 ): comb = horse for first in range( 1, horse + 1 ): ans[ horse ] = ( ans[ horse ] + comb * ans[ horse - first ] ) % mod comb = comb * ( horse - first ) // ( first + 1 ) for t in range( int( input() ) ): print( 'Case %d: %d' % ( t + 1, ans[ int( input() ) ] ) )
from math import factorial as f print(f(int(input()))) # def f(n): # return n * f(n-1) if n > 1 else 1 # print(f(int(input())))
from math import factorial as f def fd(n): digits = [f(int(x)) for x in str(n)] return sum(digits) print( sum([x for x in range(3, 100000) if sum([f(int(y)) for y in str(x)]) == x]))
def nCr(n, r): from math import factorial as f return f(n) // (f(n-r)*f(r))
#!/usr/bin/env python from math import factorial as f if __name__ == '__main__': count = 0 for r in range(101): for n in range(r, 101): if f(n) / (f(r) * f(n-r)) > 1000000: count += 1 print count
# factorial 함수만 import from math import factorial n = factorial(5) / factorial(3) # 여러 함수를 import from math import (factorial, acos) n = factorial(3) + acos(1) # 모든 함수를 import from math import * n = sqrt(5) + fabs(-12.5) # factorial() 함수를 f()로 사용 가능 from math import factorial as f n = f(5) / f(3) # 모듈 위치 # import하면 모듈을 찾기 위해 다음과 같은 경로를 순서대로 검색 # 1. 현재 디렉토리 # 2. 환경변수 PYTHONPATH에 지정된 경로 # 3. Python이 설치된 경로 및 그 밑의 라이브러리 경로 # 모듈 작성 # mylib.py def add(a, b): return a + b def substract(a, b):
from math import factorial as f for i in range(50000): s = 0 for num in list(str(i)): s += f(int(num)) if s == i: print('{} is a factorion.'.format(i))
def fd(n): digits = [f(int(x)) for x in str(n)] return sum(digits)
#!/usr/bin/python from math import factorial as f print f(40)/(f(40-20)*f(20)) # Combinations of 20 in 20 * 2 # MAX_DOWN = MAX_LEFT = 7 # def find_nb_paths(x = 0, y = 0): # if x == MAX_LEFT and y == MAX_DOWN: # return 1 # total = 0 # if x < MAX_LEFT: # total += find_nb_paths(x + 1, y) # if y < MAX_DOWN: # total += find_nb_paths(x, y + 1) # return total # print "Total:", find_nb_paths()
#1010 다리놓기 from math import factorial as f from sys import stdin for i in range(int(stdin.readline().strip())): n, m = map(int, stdin.readline().split()) if n == m: print(1) elif n == 1: print(m) else: print(int(f(m) / (f(n) * f(m - n)))) #02 from math import factorial as f exec( 'n,m=map(int,input().split())\nif n==m:print(1)\nelif n==1:print(m)\nelse:print(int(f(m)/(f(n)*f(m-n))))\n' * int(input()))
"""145 is a curious number, as 1! + 4! + 5! = 1 + 24 + 120 = 145. Find the sum of all numbers which are equal to the sum of the factorial of their digits. Note: as 1! = 1 and 2! = 2 are not sums they are not included. NOTES: 9! = 362880 ==> 9! * 8 = 7 digits ==> max of 7 digits or 10000000 bound or 9! ** 7 """ from math import factorial as f def curious(n): return n == sum(f(int(d)) for d in str(n)) ans = sum(filter(curious, range(3, f(9)*6))) print(ans)
def ncr(n, r): """a function to find the combinatorics""" return f(n) / (f(r) * f(n - r))
def curious(n): return n == sum(f(int(d)) for d in str(n))