Compare commits

...

4 commits

Author SHA1 Message Date
Kiana Sheibani a3b53b180c
style: modify the output of scripts
Instead of separating output primes by newline, the scripts now separate
by spaces.
2024-07-28 06:43:01 -04:00
Kiana Sheibani 0e55a43863
fix(fish): fix improper prompt 2024-07-28 06:35:26 -04:00
Kiana Sheibani ce6920a1d4
remove(python-nixpkgs): remove input check for consistency 2024-07-28 06:35:02 -04:00
Kiana Sheibani a8a26921b4
Restructure everything 2024-07-28 06:34:56 -04:00
19 changed files with 235 additions and 80 deletions

43
bash/nixpkgs/flake.lock Normal file
View file

@ -0,0 +1,43 @@
{
"nodes": {
"nixpkgs": {
"locked": {
"lastModified": 1722073938,
"narHash": "sha256-OpX0StkL8vpXyWOGUD6G+MA26wAXK6SpT94kLJXo6B4=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "e36e9f57337d0ff0cf77aceb58af4c805472bfae",
"type": "github"
},
"original": {
"owner": "NixOS",
"ref": "nixpkgs-unstable",
"repo": "nixpkgs",
"type": "github"
}
},
"root": {
"inputs": {
"nixpkgs": "nixpkgs",
"systems": "systems"
}
},
"systems": {
"locked": {
"lastModified": 1681028828,
"narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=",
"owner": "nix-systems",
"repo": "default",
"rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e",
"type": "github"
},
"original": {
"owner": "nix-systems",
"repo": "default",
"type": "github"
}
}
},
"root": "root",
"version": 7
}

17
bash/nixpkgs/flake.nix Normal file
View file

@ -0,0 +1,17 @@
{
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
systems.url = "github:nix-systems/default";
};
outputs = { self, nixpkgs, systems, ... }:
let eachSystem = nixpkgs.lib.genAttrs (import systems);
in {
packages = eachSystem (system:
let pkgs = nixpkgs.legacyPackages.${system};
in {
soe = pkgs.callPackage ./package.nix {};
default = self.packages.${system}.soe;
});
};
}

View file

@ -1,10 +1,9 @@
{ stdenv { stdenv
, lib
, bash , bash
}: }:
stdenv.mkDerivation { stdenv.mkDerivation {
pname = "soe-bash"; pname = "soe";
version = "1.0"; version = "1.0";
src = ./.; src = ./.;
@ -13,6 +12,6 @@ stdenv.mkDerivation {
installPhase = '' installPhase = ''
mkdir -p $out/bin mkdir -p $out/bin
cp soe-bash $out/bin cp soe $out/bin
''; '';
} }

View file

@ -1,5 +1,6 @@
#!/usr/bin/env bash #!/usr/bin/env bash
echo -n "Primes up to: "
read num read num
echo echo
@ -12,10 +13,12 @@ unset nums[-1]
while [ -n "$nums" ]; do while [ -n "$nums" ]; do
prime=${nums[0]} prime=${nums[0]}
echo $prime echo -n "$prime "
nums_=() nums_=()
for elem in "${nums[@]}"; do for elem in "${nums[@]}"; do
[ $(( $elem % $prime )) -eq 0 ] || nums_+=($elem) [ $(( $elem % $prime )) -eq 0 ] || nums_+=($elem)
done done
nums=(${nums_[@]}) nums=(${nums_[@]})
done done
echo

43
fish/nixpkgs/flake.lock Normal file
View file

@ -0,0 +1,43 @@
{
"nodes": {
"nixpkgs": {
"locked": {
"lastModified": 1722141560,
"narHash": "sha256-Ul3rIdesWaiW56PS/Ak3UlJdkwBrD4UcagCmXZR9Z7Y=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "038fb464fcfa79b4f08131b07f2d8c9a6bcc4160",
"type": "github"
},
"original": {
"owner": "NixOS",
"ref": "nixpkgs-unstable",
"repo": "nixpkgs",
"type": "github"
}
},
"root": {
"inputs": {
"nixpkgs": "nixpkgs",
"systems": "systems"
}
},
"systems": {
"locked": {
"lastModified": 1681028828,
"narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=",
"owner": "nix-systems",
"repo": "default",
"rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e",
"type": "github"
},
"original": {
"owner": "nix-systems",
"repo": "default",
"type": "github"
}
}
},
"root": "root",
"version": 7
}

17
fish/nixpkgs/flake.nix Normal file
View file

@ -0,0 +1,17 @@
{
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
systems.url = "github:nix-systems/default";
};
outputs = { self, nixpkgs, systems, ... }:
let eachSystem = nixpkgs.lib.genAttrs (import systems);
in {
packages = eachSystem (system:
let pkgs = nixpkgs.legacyPackages.${system};
in {
soe = pkgs.callPackage ./package.nix {};
default = self.packages.${system}.soe;
});
};
}

View file

@ -1,10 +1,9 @@
{ stdenv { stdenv
, lib
, fish , fish
}: }:
stdenv.mkDerivation { stdenv.mkDerivation {
pname = "soe-fish"; pname = "soe";
version = "1.0"; version = "1.0";
src = ./.; src = ./.;
@ -13,6 +12,6 @@ stdenv.mkDerivation {
installPhase = '' installPhase = ''
mkdir -p $out/bin mkdir -p $out/bin
cp soe-fish $out/bin cp soe $out/bin
''; '';
} }

View file

@ -1,13 +1,13 @@
#!/usr/bin/env fish #!/usr/bin/env fish
read -P "" num read -P "Primes up to: " num
echo echo
set nums (seq 2 $num)[..-2] set nums (seq 2 $num)[..-2]
while test -n "$nums" while test -n "$nums"
set prime $nums[1] set prime $nums[1]
echo $prime echo -n "$prime "
set -e nums_ set -e nums_
for elem in $nums for elem in $nums
@ -15,3 +15,5 @@ while test -n "$nums"
end end
set nums $nums_ set nums $nums_
end end
echo

View file

@ -1,41 +1,6 @@
{ {
"nodes": { "nodes": {
"flake-utils": { "root": {}
"locked": {
"lastModified": 1667395993,
"narHash": "sha256-nuEHfE/LcWyuSWnS8t12N1wc105Qtau+/OdUAjtQ0rA=",
"owner": "numtide",
"repo": "flake-utils",
"rev": "5aed5285a952e0b949eb3ba02c12fa4fcfef535f",
"type": "github"
},
"original": {
"owner": "numtide",
"repo": "flake-utils",
"type": "github"
}
},
"nixpkgs": {
"locked": {
"lastModified": 1675132057,
"narHash": "sha256-lq7VYB8J2wn35CeByP9760tR6mwQtztPze+J8O4fHdU=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "5b374db81f4a26de2cef6dae71b4478b362866a4",
"type": "github"
},
"original": {
"owner": "NixOS",
"repo": "nixpkgs",
"type": "github"
}
},
"root": {
"inputs": {
"flake-utils": "flake-utils",
"nixpkgs": "nixpkgs"
}
}
}, },
"root": "root", "root": "root",
"version": 7 "version": 7

View file

@ -1,28 +1,43 @@
{ {
description = "The Sieve of Eratosthenes implemented in many different languages"; description = "Templates of the Sieve of Eratosthenes implemented in various languages";
inputs = { outputs = { self, ... }:
nixpkgs.url = "github:NixOS/nixpkgs"; let
flake-utils.url = "github:numtide/flake-utils"; # Get all project directories
}; subdirs = dir:
let sub = builtins.readDir dir;
in builtins.filter
(d: sub.${d} == "directory")
(builtins.attrNames sub);
outputs = { self, nixpkgs, flake-utils, ... }: vowelStart = str: builtins.elem (builtins.substring 0 1 str) [ "a" "e" "i" "o" "u" ];
flake-utils.lib.eachDefaultSystem (system:
let
pkgs = nixpkgs.legacyPackages.${system};
inherit (pkgs) lib;
# Check if project has a shell.nix concatMapAttrs = func: attr:
hasShell = dir: builtins.pathExists ./${dir}/shell.nix; builtins.foldl' (x: y: x // y) {}
(builtins.map func attr);
# Get all project directories templateDirs =
currentDir = builtins.readDir ./.; builtins.concatMap (lang:
dirs = builtins.attrNames (lib.filterAttrs (_: v: v == "directory") currentDir); builtins.map
in (pkg: { inherit lang pkg; })
builtins.foldl' lib.recursiveUpdate {} (builtins.map (dir: { (subdirs ./${lang}))
packages.${dir} = pkgs.callPackage ./${dir} {}; (subdirs ./.);
} // lib.optionalAttrs (hasShell dir) { in {
devShells.${dir} = pkgs.callPackage ./${dir}/shell.nix {}; templates = concatMapAttrs ({ lang, pkg }: {
}) dirs) "${lang}-${pkg}" = {
); description = "Packaging a${if vowelStart lang
then "n"
else ""} ${lang} executable using ${pkg}";
path = builtins.filterSource
(path: type: builtins.baseNameOf path != "flake.lock")
./${lang}/${pkg};
};
}) templateDirs // concatMapAttrs (lang: {
"${lang}" = self.templates."${lang}-nixpkgs" // {
description = "Packaging a${if vowelStart lang
then "n"
else ""} ${lang} executable";
};
}) (subdirs ./.);
};
} }

43
python/nixpkgs/flake.lock Normal file
View file

@ -0,0 +1,43 @@
{
"nodes": {
"nixpkgs": {
"locked": {
"lastModified": 1722141560,
"narHash": "sha256-Ul3rIdesWaiW56PS/Ak3UlJdkwBrD4UcagCmXZR9Z7Y=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "038fb464fcfa79b4f08131b07f2d8c9a6bcc4160",
"type": "github"
},
"original": {
"owner": "NixOS",
"ref": "nixpkgs-unstable",
"repo": "nixpkgs",
"type": "github"
}
},
"root": {
"inputs": {
"nixpkgs": "nixpkgs",
"systems": "systems"
}
},
"systems": {
"locked": {
"lastModified": 1681028828,
"narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=",
"owner": "nix-systems",
"repo": "default",
"rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e",
"type": "github"
},
"original": {
"owner": "nix-systems",
"repo": "default",
"type": "github"
}
}
},
"root": "root",
"version": 7
}

17
python/nixpkgs/flake.nix Normal file
View file

@ -0,0 +1,17 @@
{
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
systems.url = "github:nix-systems/default";
};
outputs = { self, nixpkgs, systems, ... }:
let eachSystem = nixpkgs.lib.genAttrs (import systems);
in {
packages = eachSystem (system:
let pkgs = nixpkgs.legacyPackages.${system};
in {
soe = pkgs.callPackage ./package.nix {};
default = self.packages.${system}.soe;
});
};
}

View file

@ -1,7 +1,7 @@
{ python3 }: { python3 }:
python3.pkgs.buildPythonApplication { python3.pkgs.buildPythonApplication {
pname = "soe-python"; pname = "soe";
version = "1.0"; version = "1.0";
src = ./.; src = ./.;

View file

@ -3,5 +3,5 @@ from setuptools import setup
setup( setup(
name="soe", name="soe",
version="1.0.0", version="1.0.0",
scripts=["bin/soe-python"] scripts=["bin/soe"]
) )

View file

@ -1,5 +1,4 @@
def sieve_of_eratosthenes(n): def sieve_of_eratosthenes(n):
nums = list(range(2, n)) nums = list(range(2, n))
while nums: while nums:
@ -8,18 +7,11 @@ def sieve_of_eratosthenes(n):
yield prime yield prime
def main(): def main():
num = 0 num = int(input("Primes up to: "))
another = True
while another:
try:
num = int(input())
another = False
except ValueError:
pass
print() print()
for i in sieve_of_eratosthenes(num): for i in sieve_of_eratosthenes(num):
print(i) print(i, end=" ")
print()
if __name__ == "__main__": if __name__ == "__main__":