Skip to content

Commit

Permalink
Added formatting and removed deprecated attributes syntax (#982)
Browse files Browse the repository at this point in the history
Co-authored-by: Tudor Marghidanu <[email protected]>
  • Loading branch information
marghidanu and Tudor Marghidanu authored Oct 20, 2024
1 parent d229a8c commit 57a5077
Show file tree
Hide file tree
Showing 2 changed files with 962 additions and 944 deletions.
42 changes: 20 additions & 22 deletions PrimeV/solution_1/primes.v
Original file line number Diff line number Diff line change
@@ -1,31 +1,29 @@
import time
import math

const (
sieve_size = 1_000_000
q = math.sqrt(sieve_size)
all_bits_true_array = []bool{len: sieve_size, init: true}
dictionary = {
'10': 4
'100': 25
'1000': 168
'10000': 1229
'100000': 9592
'1000000': 78498
'10000000': 664579
'100000000': 5761455
'1000000000': 50847534
'10000000000': 455052511
}
)
const sieve_size = 1_000_000
const q = math.sqrt(sieve_size)
const all_bits_true_array = []bool{len: sieve_size, init: true}
const dictionary = {
'10': 4
'100': 25
'1000': 168
'10000': 1229
'100000': 9592
'1000000': 78498
'10000000': 664579
'100000000': 5761455
'1000000000': 50847534
'10000000000': 455052511
}

struct Sieve {
sieve_size u64
mut:
bits []bool
}

[direct_array_access]
@[direct_array_access]
fn (mut sieve Sieve) run_sieve() {
mut factor := u64(3)

Expand Down Expand Up @@ -54,7 +52,7 @@ fn (sieve Sieve) print_results(show_results bool, duration time.Duration, passes
for num := u64(3); num <= sieve.sieve_size; num += u64(2) {
if sieve.bits[num] {
if show_results {
print('$num, ')
print('${num}, ')
}

count++
Expand All @@ -68,9 +66,9 @@ fn (sieve Sieve) print_results(show_results bool, duration time.Duration, passes
avg := f64(duration / passes)
count_primes := sieve.count_primes()
valid := (count_primes == u64(dictionary[sieve.sieve_size.str()]))
eprintln('Passes: $passes, Time: $duration, Avg: $avg, Limit: $sieve.sieve_size, Count1: $count, Count2: $count_primes, Valid: $valid')
eprintln('Passes: ${passes}, Time: ${duration}, Avg: ${avg}, Limit: ${sieve.sieve_size}, Count1: ${count}, Count2: ${count_primes}, Valid: ${valid}')

println('marghidanu;$passes;$duration;1;algorithm=base,faithful=yes')
println('marghidanu;${passes};${duration};1;algorithm=base,faithful=yes')
}

fn (sieve Sieve) count_primes() u64 {
Expand All @@ -92,7 +90,7 @@ fn main() {
for {
mut sieve := Sieve{
sieve_size: 1_000_000
bits: all_bits_true_array
bits: all_bits_true_array
}
sieve.run_sieve()

Expand Down
Loading

0 comments on commit 57a5077

Please sign in to comment.