def __find_best(name: str, targetCP: int, validator: Callable[["Pokemon", "Pokemon"], bool], lowerIV) -> Tuple[float, List[int]]: if targetCP == LEAGUES[-1].cp: return (40.0, [15, 15, 15]) best = Pokemon(name, 1, [0, 0, 0]) staminaIV = 15 while staminaIV >= lowerIV: defenseIV = 15 while defenseIV >= lowerIV: attackIV = 15 while attackIV >= lowerIV: targetCPM = fpow( targetCP * 10 / ((best.baseAttack + attackIV) * fpow( (best.baseDefense + defenseIV), 0.5) * fpow( (best.baseStamina + staminaIV), 0.5)), 0.5, ) try: level = (next(i for i, cpm in enumerate(Pokemon.CPMS) if cpm >= targetCPM) / 2 - 1) except StopIteration: level = 40.0 while level <= 40: pokemon = Pokemon(name, level, [attackIV, defenseIV, staminaIV]) if pokemon.cp > targetCP: break if validator(pokemon, best): best = pokemon level += 0.5 attackIV -= 1 defenseIV -= 1 staminaIV -= 1 return (best.level, [best.attackIV, best.defenseIV, best.staminaIV])
def read_sensor(self): # Split and return only compass data data = self.device_handler.read() ((x_a, y_a, z_a), (x_m, y_m, z_m, or_)) = data # logging.info("Compass:\tX: %f, Y: %f, Z: %f" % (x_m, y_m, z_m)) # Test # heading = (atan2(y_m, x_m)*180)/pi # if heading < 0: # heading = 360 + heading # print("testheading: %F" % heading) # Calculate roll and pitch in radians pitch_r = atan2(x_a, sqrt(fpow(y_a, 2) + fpow(z_a, 2))) roll_r = atan2(y_a, z_a) x_h = x_a * cos(pitch_r) + z_m * sin(pitch_r) y_h = ((x_m * sin(roll_r) * sin(pitch_r)) + (y_m * cos(roll_r)) - (z_m * sin(roll_r) * cos(pitch_r))) heading = (atan2(y_h, x_h)*180)/pi if y_h < 0: heading = 360 + heading pitch = pitch_r * 180 / pi roll = roll_r * 180 / pi return heading, pitch, roll
def cp(self): return max( floor(((self.baseAttack + self.attackIV) * fpow( (self.baseDefense + self.defenseIV), 0.5) * fpow( (self.baseStamina + self.staminaIV), 0.5) * fpow(self.cpm, 2)) / 10), 10, )
def xyz_to_llh(x, y, z): """Converty XYZ coordinate into longitude/latitude/height coordinates""" llh = [] da = 0.0 df = 0.0 a = 6378137 - da f = 1 / 298.2572235630 - df b = (1 - f) * a e2 = 2 * f - f * f E2 = (a * a - b * b) / (b * b) p = sqrt(x * x + y * y) llh.append(atan2(y, x)) theta = atan((z * a) / (p * b)) llh.append( atan((z + E2 * b * fpow(sin(theta), 3)) / (p - e2 * a * fpow(cos(theta), 3)))) N = a / sqrt(1 - e2 * sin(llh[1]) * sin(llh[1])) llh.append(p / cos(llh[1]) - N) llh[0] = degrees(llh[0]) llh[1] = degrees(llh[1]) return llh
def euclidian(p, q): """Compute the euclidian distance between two tuples of numbers. The tuples must be of the same length, and should both be numbers. """ assert len(p) == len(q), \ "Distance between tuples of unequal length doesn't work." # This function basically computes (formula in LaTeX) # $\sqrt{(p_1 - q_1)^2 + (p_2 - q_2)^2 + \ldots + (p_n - p_n)^2}$ # coordinate_pairs is an iterable of tuples, with each tuple being made up # of the i-th element of p an q. It's prep for doing the subtraction and # summation later. coordinate_pairs = zip(p, q) # differences is an iterable of the difference between the items of each # item in coordinate_pairs differences = starmap(sub, coordinate_pairs) # raise differences to the second power (square them) raised_differences = map(lambda x: fpow(x, 2), differences) # Sum raised_differences in preparation for... sum_coordinates = fsum(raised_differences) # ...finding the square root and returning. return sqrt(sum_coordinates)
def test_blinkc_duty(seg): print("Calamari Seg7 test: blinkc duty") from math import pow as fpow for pace in range(7, 0, -1): seg.blinkc('@', period=0.01, duty=1.0/fpow(2, pace), cycles=100)
def test_blink_duty(seg): print("Calamari Seg7 test: blink duty") from math import pow as fpow for pace in range(0, 7, 1): seg.blink('@', period=0.02, duty=1.0/fpow(2, pace), elapse=1.0)
def test_blinkc_period(seg): print("Calamari Seg7 test: blinkc period") # test 'blink' by blinking all segments with decreasing periods from math import pow as fpow for pace in range(7, 0, -1): seg.blinkc('@', period=1.0/fpow(2, pace), cycles=2 ** pace)
def test_blink_period(seg): print("Calamari Seg7 test: blink period") # test 'blink' by blinking all segments with decreasing periods from math import pow as fpow for pace in range(0, 7, 1): seg.blink('@', period=1.0/fpow(2, pace), elapse=1.0)
def decay(x, half_life): return fpow(0.5, (float(x) / float(half_life)))
# Author: Martin Tran # Email: [email protected] # Feel free to send any questions about this problem to the email above # or ask in the CPC discord. (discord.gg/MEXwfze) # --------------------------------------------------------------------- from math import pow as fpow # Make sure you use the pow() from the math library N = float(input()) # since the regular pow() is only accurate for ints! print(fpow(N, 1/N))
def test_blinkc_duty(seg): print("Calamari Seg7 test: blinkc duty") from math import pow as fpow for pace in range(7, 0, -1): seg.blinkc('@', period=0.01, duty=1.0 / fpow(2, pace), cycles=100)
def test_blink_duty(seg): print("Calamari Seg7 test: blink duty") from math import pow as fpow for pace in range(0, 7, 1): seg.blink('@', period=0.02, duty=1.0 / fpow(2, pace), elapse=1.0)
def test_blinkc_period(seg): print("Calamari Seg7 test: blinkc period") # test 'blink' by blinking all segments with decreasing periods from math import pow as fpow for pace in range(7, 0, -1): seg.blinkc('@', period=1.0 / fpow(2, pace), cycles=2**pace)
def test_blink_period(seg): print("Calamari Seg7 test: blink period") # test 'blink' by blinking all segments with decreasing periods from math import pow as fpow for pace in range(0, 7, 1): seg.blink('@', period=1.0 / fpow(2, pace), elapse=1.0)
# In[12]: get_ipython().run_line_magic('matplotlib', 'inline') import matplotlib.pyplot as plt plt.stem([4, 3, 2, 1]) plt.ylabel(r'$x_n$') plt.xlabel(r'$n$') plt.title('A sequence of numbers') plt.show() # We can also rename a function as we import it to avoid name collision: # In[13]: from math import pow as fpow fpow(2, 2), pow(2, 2) # **Exercise** What is wrong with the following code? # In[14]: import math as m for m in range(5): m.pow(m, 2) # There is a name collision: `m` is assigned to an integer in the for loop and so it is no longer the module `math` when calling `m.pow`. # **Exercise** Use the `randint` function from `random` to simulate the rolling of a die, by printing a random integer from 1 to 6. # In[15]: