nico.py 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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. return x
  46. def ip():
  47. """
  48. get public ip
  49. """
  50. return __salt__["http.query"]("https://checkip.amazonaws.com/", method="GET")