Ładny brzuch
Jw. prosz o pomoc w opisie skryptu basha chodzi mi tu o dokadny opis co robi kady znacznik. Nie znam si na tym zabardzo a potrzebuje tego na zaliczenie laborek :/
Example A-17. Generating prime numbers using the modulo operator
1 #!/bin/bash
2 # primes.sh: Generate prime numbers, without using arrays.
3 # Script contributed by Stephane Chazelas.
4
5 # This does *not* use the classic "Sieve of Eratosthenes" algorithm,
6 #+ but instead uses the more intuitive method of testing each candidate number
7 #+ for factors (divisors), using the "%" modulo operator.
8
9
10 LIMIT=1000 # Primes 2 - 1000
11
12 Primes()
13 {
14 (( n = $1 + 1 )) # Bump to next integer.
15 shift # Next parameter in list.
16 # echo "_n=$n i=$i_"
17
18 if (( n == LIMIT ))
19 then echo $*
20 return
21 fi
22
23 for i; do # "i" gets set to "@", previous values of $n.
24 # echo "-n=$n i=$i-"
25 (( i * i > n )) && break # Optimization.
26 (( n % i )) && continue # Sift out non-primes using modulo operator.
27 Primes $n $@ # Recursion inside loop.
28 return
29 done
30
31 Primes $n $@ $n # Recursion outside loop.
32 # Successively accumulate positional parameters.
33 # "$@" is the accumulating list of primes.
34 }
35
36 Primes 1
37
38 exit 0
39
40 # Uncomment lines 17 and 25 to help figure out what is going on.
41
42 # Compare the speed of this algorithm for generating primes
43 # with the Sieve of Eratosthenes (ex68.sh).
44
45 # Exercise: Rewrite this script without recursion, for faster execution.
Z gry dziki.
Jezeli chodzi Ci tylko o opis "znacznikow" to poczytaj na manpages ;]
Najlepiej jakby ktos mi mg opisa linijka po linijce co ktra robi. Mniejwicej znaczniki ju znam bo wykad przeczytaem.
zanotowane.pl doc.pisz.pl pdf.pisz.pl zsf.htw.pl
Example A-17. Generating prime numbers using the modulo operator
1 #!/bin/bash
2 # primes.sh: Generate prime numbers, without using arrays.
3 # Script contributed by Stephane Chazelas.
4
5 # This does *not* use the classic "Sieve of Eratosthenes" algorithm,
6 #+ but instead uses the more intuitive method of testing each candidate number
7 #+ for factors (divisors), using the "%" modulo operator.
8
9
10 LIMIT=1000 # Primes 2 - 1000
11
12 Primes()
13 {
14 (( n = $1 + 1 )) # Bump to next integer.
15 shift # Next parameter in list.
16 # echo "_n=$n i=$i_"
17
18 if (( n == LIMIT ))
19 then echo $*
20 return
21 fi
22
23 for i; do # "i" gets set to "@", previous values of $n.
24 # echo "-n=$n i=$i-"
25 (( i * i > n )) && break # Optimization.
26 (( n % i )) && continue # Sift out non-primes using modulo operator.
27 Primes $n $@ # Recursion inside loop.
28 return
29 done
30
31 Primes $n $@ $n # Recursion outside loop.
32 # Successively accumulate positional parameters.
33 # "$@" is the accumulating list of primes.
34 }
35
36 Primes 1
37
38 exit 0
39
40 # Uncomment lines 17 and 25 to help figure out what is going on.
41
42 # Compare the speed of this algorithm for generating primes
43 # with the Sieve of Eratosthenes (ex68.sh).
44
45 # Exercise: Rewrite this script without recursion, for faster execution.
Z gry dziki.
Jezeli chodzi Ci tylko o opis "znacznikow" to poczytaj na manpages ;]
Najlepiej jakby ktos mi mg opisa linijka po linijce co ktra robi. Mniejwicej znaczniki ju znam bo wykad przeczytaem.