mirror of
https://github.com/Dummi26/mers.git
synced 2025-03-10 14:13:52 +01:00
34 lines
750 B
Plaintext
34 lines
750 B
Plaintext
![]() |
is_prime := n -> {
|
||
|
0.1.sleep // wow, what an inefficient algorithm, oh no
|
||
|
d := 1
|
||
|
().loop(() -> {
|
||
|
&d = (d, 1).sum
|
||
|
if d.lt(n) {
|
||
|
if n.modulo(d).eq(0) (false)
|
||
|
} else (true)
|
||
|
})
|
||
|
}
|
||
|
|
||
|
find_primes := start_at -> {
|
||
|
() -> (().loop(() -> {
|
||
|
out := if start_at.is_prime (start_at)
|
||
|
&start_at = (start_at, 1).sum
|
||
|
out
|
||
|
}))
|
||
|
}
|
||
|
|
||
|
primes_count := 0
|
||
|
|
||
|
background_thread := {() ->
|
||
|
2.find_primes.take(20).map(p -> { &primes_count = (primes_count, 1).sum, p }).as_list
|
||
|
}.thread
|
||
|
|
||
|
// Show status to the user while the background thread works
|
||
|
().loop(() -> {
|
||
|
0.2.sleep
|
||
|
(" Found ", primes_count, " primes...\r").concat.print
|
||
|
if background_thread.thread_finished (())
|
||
|
})
|
||
|
|
||
|
("\nPrimes: ", background_thread.thread_await).concat.println
|