Implement in shell scripts

This commit is contained in:
Kiana Sheibani 2023-02-08 12:07:14 -05:00
parent 4cd7275293
commit da579f08af
Signed by: toki
GPG key ID: 6CB106C25E86A9F7
4 changed files with 80 additions and 0 deletions

22
bash/default.nix Normal file
View file

@ -0,0 +1,22 @@
{ stdenv
, lib
, bash
, makeWrapper
}:
stdenv.mkDerivation {
pname = "soe-bash";
version = "1.0";
src = ./.;
buildInputs = [ bash ];
nativeBuildInputs = [ makeWrapper ];
installPhase = ''
mkdir -p $out/bin
install -m555 soe-bash $out/bin
wrapProgram $out/bin/soe-bash \
--prefix PATH : ${lib.makeBinPath [ bash ]}
'';
}

19
bash/soe-bash Normal file
View file

@ -0,0 +1,19 @@
#!/usr/bin/env bash
read num
echo
nums=()
for i in `seq 2 $num`; do
nums+=($i)
done
while [ -n "$nums" ]; do
prime=${nums[0]}
echo $prime
nums_=()
for elem in "${nums[@]}"; do
[ $(( $elem % $prime )) -eq 0 ] || nums_+=($elem)
done
nums=(${nums_[@]})
done

22
fish/default.nix Normal file
View file

@ -0,0 +1,22 @@
{ stdenv
, lib
, fish
, makeWrapper
}:
stdenv.mkDerivation {
pname = "soe-fish";
version = "1.0";
src = ./.;
buildInputs = [ fish ];
nativeBuildInputs = [ makeWrapper ];
installPhase = ''
mkdir -p $out/bin
install -m555 soe-fish $out/bin
wrapProgram $out/bin/soe-fish \
--prefix PATH : ${lib.makeBinPath [ fish ]}
'';
}

17
fish/soe-fish Normal file
View file

@ -0,0 +1,17 @@
#!/usr/bin/env fish
read -P "" num
echo
set nums (seq 2 $num)
while test -n "$nums"
set prime $nums[1]
echo $prime
set -e nums_
for elem in $nums
test (math $elem % $prime) -eq 0 || set -a nums_ $elem
end
set nums $nums_
end