nico.py 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. __func_alias__ = {
  2. "list_": "list",
  3. }
  4. def __virtual__():
  5. return True
  6. def _genprimes():
  7. """
  8. genarator of primes
  9. """
  10. prms = {}
  11. n = 2
  12. while True:
  13. if all([n % pr for pr in prms]):
  14. yield n
  15. prms[n] = n**2
  16. else:
  17. for key, val in [(x,y) for x, y in prms.items() if y == n]:
  18. prms[key] += key
  19. n += 1
  20. def com(num):
  21. """
  22. Function that finds components primes of a given number
  23. """
  24. comp = []
  25. for pr in _genprimes():
  26. while not num % pr:
  27. comp.append(pr)
  28. num /= pr
  29. if num == 1:
  30. return comp
  31. def fib(num):
  32. """
  33. Gives the nth fibonacci number
  34. """
  35. return __salt__["test.fib"](num)
  36. def list_(num):
  37. """
  38. List all prime numbers below given number
  39. """
  40. x = []
  41. for y in _genprimes():
  42. if y < num:
  43. x.append(y)
  44. else:
  45. break
  46. return x
  47. def ip():
  48. """
  49. get public ip
  50. """
  51. return __salt__["http.query"]("https://checkip.amazonaws.com/", method="GET")