def get_change(self, activation=None, use_time_scale=True): """Compute the next change to the system. By default, the current value of the field is used, but a different value can be supplied to compute the output for an arbitrary value. When use_time_scale is set to False, the time scale is not considered when computing the change.""" # get the current output of the dynamic field current_output = self.get_output() # if a specific current activation is supplied.. if activation is not None: # .. compute the output given this activation current_output = self.get_output(activation) else: # ..otherwise set the activation to the current value of the field activation = self._activation # if the time scale is to be used.. if use_time_scale is True: # ..compute the inverse of the time scale to have a factor.. relaxation_time_factor = 1. / self._relaxation_time else: # ..otherwise, set the factor to one relaxation_time_factor = 1. # compute the lateral interaction lateral_interaction = 0. if self._lateral_interaction_kernels is not None: for kernel in self._lateral_interaction_kernels: lateral_interaction += Kernel.convolve(current_output, kernel) # sum up the input coming in from all connected fields field_interaction = 0 for connectable in self.get_incoming_connectables(): field_interaction += connectable.get_output() global_inhibition = self._global_inhibition * current_output.sum( ) / math_tools.product(self._output_dimension_sizes) # generate the noise term noise = self._noise_strength * numpy.random.normal( 0.0, self._noise_standard_deviation, self._output_dimension_sizes) # compute the change of the system change = relaxation_time_factor * ( -self._normalization_factor * activation + self._resting_level + self._boost - global_inhibition + lateral_interaction + field_interaction + noise) return change
# coding: utf8 """ An irrational decimal fraction is created by concatenating the positive integers: 0.123456789101112131415161718192021... It can be seen that the 12th digit of the fractional part is 1. If dn represents the nth digit of the fractional part, find the value of the following expression. d1 × d10 × d100 × d1000 × d10000 × d100000 × d1000000 """ from math_tools import product digits = [str(i) for i in xrange(1, 200000)] pattern = '.' + ''.join(digits) dns = map(int, (pattern[1], pattern[10], pattern[100], pattern[1000], pattern[10000], pattern[100000], pattern[1000000])) # print dns print product(dns)
1 1 1 1 1 2 2 2 2 2 3 3 4 2 3 4 2 8 2 4 5 5 3 3 5 6 6 9 3 6 7 7 5 5 7 8 2 6 6 8 9 3 7 7 9 10 10 10 10 10 Let E(k) be the kth element in the sorted n column; for example, E(4) = 8 and E(6) = 9. If rad(n) is sorted for 1 ≤ n ≤ 100000, find E(10000). """ from math_tools import prime_factorize, product from operator import itemgetter rads = [(1,1)] + [(x, product(set(prime_factorize(x)))) for x in range(2,100001)] sorted_rads = sorted(rads, key=itemgetter(1,0)) print sorted_rads[9999][0] """ Runs in: real 1m13.928s user 1m13.579s sys 0m0.173s """
n2+an+bn2+an+b, where |a|<1000|a|<1000 and |b|≤1000|b|≤1000 where |n||n| is the modulus/absolute value of nn e.g. |11|=11|11|=11 and |−4|=4|−4|=4 Find the product of the coefficients, aa and bb, for the quadratic expression that produces the maximum number of primes for consecutive values of nn, starting with n=0n=0. """ from math_tools import million_primes, product, get_k_with_largest_v primes = set(million_primes()) results = dict() for a in range(-999, 1000): if abs( a ) in primes: # I assumed both a and b had to be primes to maximize prime generation. for b in range(-1000, 1001): if abs(b) in primes: t = (a, b) results[t] = 0 n = 0 while True: if (n**2 + a * n + b) in primes: results[t] += 1 n += 1 else: break print product(get_k_with_largest_v(results))
""" from fractions import Fraction from math_tools import product def get_tuples(): for a in xrange(10, 100): for b in xrange(10, 100): if a < b: a_str = str(a) b_str = str(b) a_head = int(a_str[0]) a_tail = int(a_str[1]) b_head = int(b_str[0]) b_tail = int(b_str[1]) if a_tail == 0 or a_tail != b_head: continue x = a * b_tail y = b * a_head if x == y: yield (a, b) results = list(get_tuples()) print product([Fraction(t[0], t[1]) for t in results]).denominator """ real 0m0.034s user 0m0.023s sys 0m0.008s """