瀏覽代碼

Added nico execution module

nee2c 4 年之前
父節點
當前提交
c6890ad4a3
共有 1 個文件被更改,包括 54 次插入0 次删除
  1. 54 0
      salt/_modules/nico.py

+ 54 - 0
salt/_modules/nico.py

@@ -0,0 +1,54 @@
+
+__func_alias__ = {
+    "list_": "list",
+}
+
+def __virtual__():
+    return True
+
+
+def _genprimes():
+    """
+    genarator of primes
+    """
+    prms = {}
+    n = 2
+    while True:
+        if all([n % pr for pr in prms]):
+            yield n
+            prms[n] = n**2
+        else:
+            for key, val in [(x,y) for x, y in prms.items() if y == n]:
+                prms[key] += key
+        n += 1
+
+def com(num):
+    """
+    Function that finds components primes of a given number
+    """
+    comp = []
+    for pr in _genprimes():
+        while not num % pr:
+            comp.append(pr)
+            num /= pr
+            if num == 1:
+                return comp
+
+def fib(num):
+    """
+    Gives the nth fibonacci number
+    """
+    return __salt__["test.fib"](num)
+
+
+def list_(num):
+    """
+    List all prime numbers below given number
+    """
+    x = []
+    for y in _genprimes():
+        if y < num:
+            x.append(y)
+        else:
+            break
+    return x