11import time
22import math
33
4- const (
5- sieve_size = 1_000_000
6- q = math.sqrt (sieve_size)
7- all_bits_true_array = []bool {len: sieve_size, init: true }
8- dictionary = {
9- '10' : 4
10- '100' : 25
11- '1000' : 168
12- '10000' : 1229
13- '100000' : 9592
14- '1000000' : 78498
15- '10000000' : 664579
16- '100000000' : 5761455
17- '1000000000' : 50847534
18- '10000000000' : 455052511
19- }
20- )
4+ const sieve_size = 1_000_000
5+ const q = math.sqrt (sieve_size)
6+ const all_bits_true_array = []bool {len: sieve_size, init: true }
7+ const dictionary = {
8+ '10' : 4
9+ '100' : 25
10+ '1000' : 168
11+ '10000' : 1229
12+ '100000' : 9592
13+ '1000000' : 78498
14+ '10000000' : 664579
15+ '100000000' : 5761455
16+ '1000000000' : 50847534
17+ '10000000000' : 455052511
18+ }
2119
2220struct Sieve {
2321 sieve_size u64
2422mut :
2523 bits []bool
2624}
2725
28- [direct_array_access ]
26+ @ [direct_array_access]
2927fn (mut sieve Sieve) run_sieve () {
3028 mut factor := u64 (3 )
3129
@@ -54,7 +52,7 @@ fn (sieve Sieve) print_results(show_results bool, duration time.Duration, passes
5452 for num := u64 (3 ); num < = sieve.sieve_size; num + = u64 (2 ) {
5553 if sieve.bits[num] {
5654 if show_results {
57- print ('$num , ' )
55+ print ('${ num} , ' )
5856 }
5957
6058 count++
@@ -68,9 +66,9 @@ fn (sieve Sieve) print_results(show_results bool, duration time.Duration, passes
6866 avg := f64 (duration / passes)
6967 count_primes := sieve.count_primes ()
7068 valid := (count_primes == u64 (dictionary[sieve.sieve_size.str ()]))
71- eprintln ('Passes: $passes , Time: $duration , Avg: $avg , Limit: $sieve.sieve_size , Count1: $count , Count2: $count_primes , Valid: $valid ' )
69+ eprintln ('Passes: ${ passes} , Time: ${ duration} , Avg: ${ avg} , Limit: ${ sieve.sieve_size} , Count1: ${ count} , Count2: ${ count_primes} , Valid: ${ valid} ' )
7270
73- println ('marghidanu;$passes ; $ duration ;1;algorithm=base,faithful=yes' )
71+ println ('marghidanu;${ passes} ; ${ duration} ;1;algorithm=base,faithful=yes' )
7472}
7573
7674fn (sieve Sieve) count_primes () u64 {
@@ -92,7 +90,7 @@ fn main() {
9290 for {
9391 mut sieve := Sieve{
9492 sieve_size: 1_000_000
95- bits: all_bits_true_array
93+ bits: all_bits_true_array
9694 }
9795 sieve.run_sieve ()
9896
0 commit comments