Skip to content

Instantly share code, notes, and snippets.

@jzakiya
jzakiya / primes_ssoz.rs
Last active Oct 10, 2022
Primes generator, multi-threaded using rayon, using SSoZ (Segmented Sieve of Zakiya), written in Rust
View primes_ssoz.rs
// This Rust source file is a multiple threaded implementation to perform an
// extremely fast Segmented Sieve of Zakiya (SSoZ) to find Primes <= N.
// Inputs are single values N, or ranges N1 and N2, of 64-bits, 0 -- 2^64 - 1.
// Output is the number of twin primes <= N, or in range N1 to N2; the last
// twin prime value for the range; and the total time of execution.
// This code was developed on a System76 laptop with an Intel I7 6700HQ cpu,
// 2.6-3.5 GHz clock, with 8 threads, and 16GB of memory. Parameter tuning
// probably needed to optimize for other hardware systems (ARM, PowerPC, etc).
@jzakiya
jzakiya / cousinprimes_ssoz.nim
Last active Oct 7, 2022
Cousin Primes generator, multi-threaded, using SSoZ (Segmented Sieve of Zakiya), written in Nim
View cousinprimes_ssoz.nim
#[
This Nim source file is a multiple threaded implementation to perform an
extremely fast Segmented Sieve of Zakiya (SSoZ) to find Cousin Primes <= N.
Inputs are single values N, or ranges N1 and N2, of 64-bits, 0 -- 2^64 - 1.
Output is the number of cousin primes <= N, or in range N1 to N2; the last
cousin prime value for the range; and the total time of execution.
This code was developed on a System76 laptop with an Intel I7 6700HQ cpu,
2.6-3.5 GHz clock, with 8 threads, and 16GB of memory. Parameter tuning
@jzakiya
jzakiya / cousinprimes_ssoz.rs
Last active Oct 13, 2022
Cousin Primes generator, multi-threaded, using SSoZ (Segmented Sieve of Zakiya), written in Rust
View cousinprimes_ssoz.rs
// This Rust source file is a multiple threaded implementation to perform an
// extremely fast Segmented Sieve of Zakiya (SSoZ) to find Cousin Primes <= N.
// Inputs are single values N, or ranges N1 and N2, of 64-bits, 0 -- 2^64 - 1.
// Output is the number of cousin primes <= N, or in range N1 to N2; the last
// cousin prime value for the range; and the total time of execution.
// This code was developed on a System76 laptop with an Intel I7 6700HQ cpu,
// 2.6-3.5 GHz clock, with 8 threads, and 16GB of memory. Parameter tuning
// probably needed to optimize for other hardware systems (ARM, PowerPC, etc).
@jzakiya
jzakiya / cousinprimes_ssoz.d
Last active Oct 7, 2022
Cousin Primes generator, multi-threaded, using SSoZ (Segmented Sieve of Zakiya), written in D
View cousinprimes_ssoz.d
/* This D source file is a multiple threaded implementation to perform an
* extremely fast Segmented Sieve of Zakiya (SSoZ) to find Cousin Primes <= N.
*
* Inputs are single values N, or ranges N1 and N2, of 64-bits, 0 -- 2^64 - 1.
* Output is the number of cousin primes <= N, or in range N1 to N2; the last
* cousin prime value for the range; and the total time of execution.
*
* This code was developed on a System76 laptop with an Intel I7 6700HQ cpu,
* 2.6-3.5 GHz clock, with 8 threads, and 16GB of memory. Parameter tuning
* would be needed to optimize for other hadware systems (ARM, PowerPC, etc).
@jzakiya
jzakiya / cousinprimes_ssoz.go
Last active Oct 7, 2022
Cousin Primes generator, multi-threaded, using SSoZ (Segmented Sieve of Zakiya), written in Go
View cousinprimes_ssoz.go
// This Go source file is a multiple threaded implementation to perform an
// extremely fast Segmented Sieve of Zakiya (SSoZ) to find Cousin Primes <= N.
// Inputs are single values N, or ranges N1 and N2, of 64-bits, 0 -- 2^64 - 1.
// Output is the number of cousiin primes <= N, or in range N1 to N2; the last
// cousin prime value for the range; and the total time of execution.
// This code was developed on a System76 laptop with an Intel I7 6700HQ cpu,
// 2.6-3.5 GHz clock, with 8 threads, and 16GB of memory. Parameter tuning
// probably needed to optimize for other hardware systems (ARM, PowerPC, etc).
@jzakiya
jzakiya / cousinprimes_ssoz.cpp
Last active Oct 7, 2022
Cousin Primes generator, multi-threaded, using SSoZ (Segmented Sieve of Zakiya), written in C++
View cousinprimes_ssoz.cpp
/*
This C++ source file is a multiple threaded implementation to perform an
extremely fast Segmented Sieve of Zakiya (SSoZ) to find Cousin Primes <= N.
Inputs are single values N, or ranges N1 and N2, of 64-bits, 0 -- 2^64 - 1.
Output is the number of cousin primes <= N, or in range N1 to N2; the last
cousin prime value for the range; and the total time of execution.
This code was developed on a System76 laptop with an Intel I7 6700HQ cpu,
2.6-3.5 GHz clock, with 8 threads, and 16GB of memory. Parameter tuning
@jzakiya
jzakiya / cousinprimes_ssoz.cr
Last active Oct 7, 2022
Cousin Primes generator, multi-threaded, using SSoZ (Segmented Sieve of Zakiya), written in Crystal
View cousinprimes_ssoz.cr
# This Crystal source file is a multiple threaded implementation to perform an
# extremely fast Segmented Sieve of Zakiya (SSoZ) to find Cousin Primes <= N.
# Inputs are single values N, or ranges N1 and N2, of 64-bits, 0 -- 2^64 - 1.
# Output is the number of cousin primes <= N, or in range N1 to N2; the last
# cousin prime value for the range; and the total time of execution.
# This code was developed on a System76 laptop with an Intel I7 6700HQ cpu,
# 2.6-3.5 GHz clock, with 8 threads, and 16GB of memory. Parameter tuning
# probably needed to optimize for other hardware systems (ARM, PowerPC, etc).
View irootstest.cr
require "big"
module IntRoots
def irootn(n : Int32)
raise ArgumentError.new "Can't take even root of negative input" if self < 0 && n.even?
raise ArgumentError.new "Root must be an Integer >= 2" unless n.is_a?(Int) && n > 1
num = self.abs
one = typeof(self).new(1) # value 1 of type self
root = bitn_mask = one << (num.bit_length - 1) // n
until (bitn_mask >>= 1) == 0
@jzakiya
jzakiya / twinprimes_ssoz.cpp
Last active Oct 7, 2022
Twinprimes generator, multi-threaded, using SSoZ (Segmented Sieve of Zakiya), written in C++.
View twinprimes_ssoz.cpp
/*
This C++ source file is a multiple threaded implementation to perform an
extremely fast Segmented Sieve of Zakiya (SSoZ) to find Twin Primes <= N.
Inputs are single values N, or ranges N1 and N2, of 64-bits, 0 -- 2^64 - 1.
Output is the number of twin primes <= N, or in range N1 to N2; the last
twin prime value for the range; and the total time of execution.
This code was developed on a System76 laptop with an Intel I7 6700HQ cpu,
2.6-3.5 GHz clock, with 8 threads, and 16GB of memory. Parameter tuning
@jzakiya
jzakiya / twinprimes_ssoz.go
Last active Oct 7, 2022
Twinprimes generator, multi-threaded, using SSoZ (Segmented Sieve of Zakiya), written in Go.
View twinprimes_ssoz.go
// This Go source file is a multiple threaded implementation to perform an
// extremely fast Segmented Sieve of Zakiya (SSoZ) to find Twin Primes <= N.
// Inputs are single values N, or ranges N1 and N2, of 64-bits, 0 -- 2^64 - 1.
// Output is the number of twin primes <= N, or in range N1 to N2; the last
// twin prime value for the range; and the total time of execution.
// This code was developed on a System76 laptop with an Intel I7 6700HQ cpu,
// 2.6-3.5 GHz clock, with 8 threads, and 16GB of memory. Parameter tuning
// probably needed to optimize for other hardware systems (ARM, PowerPC, etc).