#!/usr/bin/env python3
+"""Mathematical helpers."""
+
import functools
import math
+from heapq import heappop, heappush
from typing import List
-from heapq import heappush, heappop
-class RunningMedian:
+class RunningMedian(object):
"""A running median computer.
>>> median = RunningMedian()
def get_median(self):
if len(self.lowers) == len(self.highers):
- return (-self.lowers[0] + self.highers[0])/2
+ return (-self.lowers[0] + self.highers[0]) / 2
elif len(self.lowers) > len(self.highers):
return -self.lowers[0]
else:
3.141
"""
- assert decimals > 0 and decimals < 10
- multiplier = 10 ** decimals
+ assert 0 < decimals < 10
+ multiplier = 10**decimals
return int(n * multiplier) / multiplier
# This is checked so that we can skip middle five numbers in below
# loop
- if (n % 2 == 0 or n % 3 == 0):
+ if n % 2 == 0 or n % 3 == 0:
return False
i = 5
while i * i <= n:
- if (n % i == 0 or n % (i + 2) == 0):
+ if n % i == 0 or n % (i + 2) == 0:
return False
i = i + 6
return True
if __name__ == '__main__':
import doctest
+
doctest.testmod()