templates/bash/nixpkgs/soe
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

25 lines
347 B
Bash
Executable file

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