1
1
import time
2
2
import math
3
3
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
+ }
21
19
22
20
struct Sieve {
23
21
sieve_size u64
24
22
mut :
25
23
bits []bool
26
24
}
27
25
28
- [direct_array_access ]
26
+ @ [direct_array_access]
29
27
fn (mut sieve Sieve) run_sieve () {
30
28
mut factor := u64 (3 )
31
29
@@ -54,7 +52,7 @@ fn (sieve Sieve) print_results(show_results bool, duration time.Duration, passes
54
52
for num := u64 (3 ); num < = sieve.sieve_size; num + = u64 (2 ) {
55
53
if sieve.bits[num] {
56
54
if show_results {
57
- print ('$num , ' )
55
+ print ('${ num} , ' )
58
56
}
59
57
60
58
count++
@@ -68,9 +66,9 @@ fn (sieve Sieve) print_results(show_results bool, duration time.Duration, passes
68
66
avg := f64 (duration / passes)
69
67
count_primes := sieve.count_primes ()
70
68
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} ' )
72
70
73
- println ('marghidanu;$passes ; $ duration ;1;algorithm=base,faithful=yes' )
71
+ println ('marghidanu;${ passes} ; ${ duration} ;1;algorithm=base,faithful=yes' )
74
72
}
75
73
76
74
fn (sieve Sieve) count_primes () u64 {
@@ -92,7 +90,7 @@ fn main() {
92
90
for {
93
91
mut sieve := Sieve{
94
92
sieve_size: 1_000_000
95
- bits: all_bits_true_array
93
+ bits: all_bits_true_array
96
94
}
97
95
sieve.run_sieve ()
98
96
0 commit comments