Implement in Python
This commit is contained in:
parent
ff4632d533
commit
e02319ff24
3
.gitignore
vendored
Normal file
3
.gitignore
vendored
Normal file
|
@ -0,0 +1,3 @@
|
|||
|
||||
result*
|
||||
.direnv
|
|
@ -15,6 +15,6 @@
|
|||
dirs = pkgs.lib.filterAttrs (_: v: v == "directory") currentDir;
|
||||
in {
|
||||
packages = builtins.mapAttrs (dir: _: pkgs.callPackage ./${dir} {}) dirs;
|
||||
}
|
||||
);
|
||||
devShells = builtins.mapAttrs (dir: _: pkgs.callPackage ./${dir}/shell.nix {}) dirs;
|
||||
});
|
||||
}
|
||||
|
|
3
python/.envrc
Normal file
3
python/.envrc
Normal file
|
@ -0,0 +1,3 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
use flake ..#python
|
4
python/bin/soe
Normal file
4
python/bin/soe
Normal file
|
@ -0,0 +1,4 @@
|
|||
#!/usr/bin/env python
|
||||
|
||||
import soe
|
||||
soe.main()
|
11
python/default.nix
Normal file
11
python/default.nix
Normal file
|
@ -0,0 +1,11 @@
|
|||
{ python3, ... }:
|
||||
|
||||
python3.pkgs.buildPythonApplication {
|
||||
pname = "soe-python";
|
||||
version = "1.0";
|
||||
src = ./.;
|
||||
|
||||
doCheck = false;
|
||||
|
||||
meta.mainProgram = "soe";
|
||||
}
|
7
python/setup.py
Normal file
7
python/setup.py
Normal file
|
@ -0,0 +1,7 @@
|
|||
from setuptools import setup
|
||||
|
||||
setup(
|
||||
name="soe",
|
||||
version="1.0.0",
|
||||
scripts=["bin/soe"]
|
||||
)
|
2
python/shell.nix
Normal file
2
python/shell.nix
Normal file
|
@ -0,0 +1,2 @@
|
|||
{ python3, ... }:
|
||||
python3.buildEnv.env
|
1
python/soe/__init__.py
Normal file
1
python/soe/__init__.py
Normal file
|
@ -0,0 +1 @@
|
|||
from .main import *
|
26
python/soe/main.py
Normal file
26
python/soe/main.py
Normal file
|
@ -0,0 +1,26 @@
|
|||
|
||||
|
||||
def sieve_of_eratosthenes(n):
|
||||
nums = list(range(2, n))
|
||||
while nums:
|
||||
prime = nums[0]
|
||||
nums = [i for i in nums if i % prime]
|
||||
yield prime
|
||||
|
||||
def main():
|
||||
num = 0
|
||||
another = True
|
||||
while another:
|
||||
try:
|
||||
num = int(input())
|
||||
another = False
|
||||
except ValueError:
|
||||
pass
|
||||
|
||||
print()
|
||||
for i in sieve_of_eratosthenes(num):
|
||||
print(i)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
Loading…
Reference in a new issue