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 while [ -n "$nums" ]; do
prime=${nums[0]} prime=${nums[0]}
echo $prime echo -n "$prime "
nums_=() nums_=()
for elem in "${nums[@]}"; do for elem in "${nums[@]}"; do
[ $(( $elem % $prime )) -eq 0 ] || nums_+=($elem) [ $(( $elem % $prime )) -eq 0 ] || nums_+=($elem)
done done
nums=(${nums_[@]}) nums=(${nums_[@]})
done done
echo

View file

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

View file

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