2023-02-08 12:07:14 -05:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
2024-07-28 06:01:20 -04:00
|
|
|
echo -n "Primes up to: "
|
2023-02-08 12:07:14 -05:00
|
|
|
read num
|
|
|
|
echo
|
|
|
|
|
|
|
|
nums=()
|
|
|
|
for i in `seq 2 $num`; do
|
|
|
|
nums+=($i)
|
|
|
|
done
|
|
|
|
|
2023-02-08 12:56:01 -05:00
|
|
|
unset nums[-1]
|
|
|
|
|
2023-02-08 12:07:14 -05:00
|
|
|
while [ -n "$nums" ]; do
|
|
|
|
prime=${nums[0]}
|
2024-07-28 06:43:01 -04:00
|
|
|
echo -n "$prime "
|
2023-02-08 12:07:14 -05:00
|
|
|
nums_=()
|
|
|
|
for elem in "${nums[@]}"; do
|
|
|
|
[ $(( $elem % $prime )) -eq 0 ] || nums_+=($elem)
|
|
|
|
done
|
|
|
|
nums=(${nums_[@]})
|
|
|
|
done
|
2024-07-28 06:43:01 -04:00
|
|
|
|
|
|
|
echo
|