Implement in shell scripts
This commit is contained in:
parent
4cd7275293
commit
da579f08af
22
bash/default.nix
Normal file
22
bash/default.nix
Normal 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
19
bash/soe-bash
Normal 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
22
fish/default.nix
Normal 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
17
fish/soe-fish
Normal 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
|
Loading…
Reference in a new issue