def specialCombinations(vec): b = [] j = 0 for a in cr(vec, 4): b.append(a) j += 1 return b
def specialCombinations(self): """This function computes the number of possible configurations of N basis functions into poducts of four functions.""" vec = list(xrange(self.N)) b = [] # for a1 in cr(vec, 2): # for a2 in cr(vec, 2): # b.append(a1+a2) for a in cr(vec, 4): b.append(a) return b
def calculate(self): loop = cr(range(len(self.X)),2) L = 0 if np.linalg.norm(self.X-self.X_) == 0: # self inductance correction L += (np.sum(np.linalg.norm(self.dX,axis=1)))/2 mutual = False else: mutual = True for ij in loop: if ij[0] != ij[1] or mutual: L += self.intergrate(ij,self.X,self.X_,self.dX,self.dX_,self.r) else: dl = np.linalg.norm(self.dX[ij[0],:]) if dl > self.r: L += 2*np.log(dl/self.r) #L += self.substeps(ij) # self inductance sub-calc L *= cc.mu_o/(4*np.pi) return L
def main(): num_of_testcase = int(stdin.readline()) for _ in range(num_of_testcase): number = int(stdin.readline()) prime_list = get_prime_list(number) prime_comb = list(cr(prime_list, 2)) for comb in prime_comb: if number - sum(comb) in prime_list: third_number = number - sum(comb) answer = '' for num in comb: answer += str(num) + ' ' print(answer.rstrip() + ' ' + str(third_number)) break else: print(0)
# project euler problem 23 # http://projecteuler.net/problem=23 # brute force, finished in 13.1s on my computer. Need to optimize # Is it possible to avoid computing the abundant numbers in the first place ? # NOTE: using generators instead of lists can save some CPU time. from itertools import combinations_with_replacement as cr END = 28123 def is_abundant(n): s = set() for i in xrange(1, int(n**0.5) + 1): if n % i == 0: s.add(i) s.add(n/i) s.remove(n) return sum(s) > n nums = [False] * END abundant_numbers = (x for x in xrange(1, END) if is_abundant(x)) sieve = (sum(i) for i in cr(abundant_numbers, 2) if sum(i) < END) for i in sieve: nums[i] = True print sum(i for i in xrange(1, END) if not nums[i])
def source(): data = input_data() exc = data[1:] points = list(i for i in range(1, data[0] + 1) if i not in exc) return len(list(cr(points, 3)))
from itertools import combinations_with_replacement as cr x, y = input().split() x = sorted(x) for i in cr(x, int(y)): print("".join(i))
# problem-link = https://www.hackerrank.com/challenges/itertools-combinations-with-replacement/problem from itertools import combinations_with_replacement as cr input_value = list(input().strip().split()) for i in list(cr(sorted(input_value[0]), int(input_value[1]))): print(''.join(i))
from itertools import combinations_with_replacement as cr import string alpa = list(zip(string.ascii_lowercase,list(range(1,27)))) s = '' for t in range(int(input())): n, k = map(int, input().split()) pr = [i for i in list(cr(range(1, 27), n)) if sum(i) == k][0] for i in pr: for a in alpa: if i == a[1]: s = s + a[0] print(s) s = ''
from itertools import combinations_with_replacement as cr word, num = input().split() print('\n'.join(''.join(i) for i in cr(sorted(word), int(num))))
Print the combinations with their replacements of string S on separate lines. Sample Input: HACK 2 Sample Output: AA AC AH AK CC CH CK HH HK KK """ from itertools import combinations_with_replacement as cr S, num = list(input().split(' ')) string = [] for i in S: string.append(i) string.sort() for j in list(cr(string, int(num))): for k in j: print(k, end='') print('')