More compile timers, euler3

This commit is contained in:
Krzosa Karol
2022-06-08 10:04:34 +02:00
parent 87d6737a10
commit 19356026fe
3 changed files with 18 additions and 10 deletions

View File

@@ -6,10 +6,11 @@ entry :: ()
euler3()
// @todo: Add more stats in the preview
// @todo: for 0..1000(implicit i) and for i in 0..1000
// @todo: Add blocks of stmts that you can simply define inside a function etc.
euler1 :: ()
end := 1000
result := 0
// @todo: for 0..1000(implicit i) and for i in 0..1000
for i := 0, i < end, i++
if i % 3 == 0
result += i
@@ -27,16 +28,16 @@ int_sqrt1 :: (s: S64): S64
x0 := s / 2
if x0 != 0
x1 := ( x0 + s / x0 ) / 2
x1 := (x0 + s / x0) / 2
for x1 < x0
x0 = x1
x1 = ( x0 + s / x0 ) / 2
x1 = (x0 + s / x0) / 2
return x0
else
return s
euler3 :: ()
n := 13195
n := 600851475143
results: [32]S64
results_len := 0
@@ -45,13 +46,15 @@ euler3 :: ()
results[results_len++] = 2
n /= 2
print_int(int_sqrt(n))
// Then search other primes, 3, 5, 7 etc.
for i := 3, i <= int_sqrt(n), i += 2
for i := 3, i <= int_sqrt1(n), i += 2
for n % i == 0
results[results_len++] = i
n /= i
if n > 2
results[results_len++] = n
printf("Euler3: ")
is_correct: S64 = 1
@@ -63,8 +66,6 @@ euler3 :: ()
print_int :: (i: S64)
printf("%lld ", i)