style: modify the output of scripts

Instead of separating output primes by newline, the scripts now separate
by spaces.
This commit is contained in:
Kiana Sheibani 2024-07-28 06:43:01 -04:00
parent 0e55a43863
commit a3b53b180c
Signed by: toki
GPG key ID: 6CB106C25E86A9F7
3 changed files with 8 additions and 4 deletions

View file

@ -13,10 +13,12 @@ unset nums[-1]
while [ -n "$nums" ]; do
prime=${nums[0]}
echo $prime
echo -n "$prime "
nums_=()
for elem in "${nums[@]}"; do
[ $(( $elem % $prime )) -eq 0 ] || nums_+=($elem)
done
nums=(${nums_[@]})
done
echo

View file

@ -7,7 +7,7 @@ set nums (seq 2 $num)[..-2]
while test -n "$nums"
set prime $nums[1]
echo $prime
echo -n "$prime "
set -e nums_
for elem in $nums
@ -15,3 +15,5 @@ while test -n "$nums"
end
set nums $nums_
end
echo

View file

@ -1,5 +1,4 @@
def sieve_of_eratosthenes(n):
nums = list(range(2, n))
while nums:
@ -11,7 +10,8 @@ def main():
num = int(input("Primes up to: "))
print()
for i in sieve_of_eratosthenes(num):
print(i)
print(i, end=" ")
print()
if __name__ == "__main__":