Implement in Python

This commit is contained in:
Kiana Sheibani 2023-02-07 13:46:57 -05:00
parent ff4632d533
commit e02319ff24
Signed by: toki
GPG key ID: 6CB106C25E86A9F7
9 changed files with 59 additions and 2 deletions

3
.gitignore vendored Normal file
View file

@ -0,0 +1,3 @@
result*
.direnv

View file

@ -15,6 +15,6 @@
dirs = pkgs.lib.filterAttrs (_: v: v == "directory") currentDir; dirs = pkgs.lib.filterAttrs (_: v: v == "directory") currentDir;
in { in {
packages = builtins.mapAttrs (dir: _: pkgs.callPackage ./${dir} {}) dirs; packages = builtins.mapAttrs (dir: _: pkgs.callPackage ./${dir} {}) dirs;
} devShells = builtins.mapAttrs (dir: _: pkgs.callPackage ./${dir}/shell.nix {}) dirs;
); });
} }

3
python/.envrc Normal file
View file

@ -0,0 +1,3 @@
#!/usr/bin/env bash
use flake ..#python

4
python/bin/soe Normal file
View file

@ -0,0 +1,4 @@
#!/usr/bin/env python
import soe
soe.main()

11
python/default.nix Normal file
View 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
View 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
View file

@ -0,0 +1,2 @@
{ python3, ... }:
python3.buildEnv.env

1
python/soe/__init__.py Normal file
View file

@ -0,0 +1 @@
from .main import *

26
python/soe/main.py Normal file
View 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()