Another translation of one of my Python snippets. This function will return a slice of consecutive prime numbers from 2 to a given value limit. In Go the 'int' type (int32) will go as high as 2147483647, but you can replace 'int' with 'uint64' and go as high as 18446744073709551615.

Member Avatar
+1 forum 0

Just a small mildly optimized function to check if an integer is a prime number. For very large numbers use the Miller-Rabin primality test. There have been questions why I used `not n & 1` to check for even integer n. The more tradional` n % 2 == 0` is about 30% slower. So I gained a tiny bit more speed.

Member Avatar
Member Avatar
+2 forum 4

Ok, so, this code snippet is a reply to this thread: http://www.daniweb.com/software-development/cpp/threads/425821/prime-number-c From what I understood form the OPs request, is that, he wanted an algorihm which would check for prime numbers in a given range, applying these conditions: a number is to be considered valid if: a. the number itself is a prime number. b. the digits composing the number are prime, like this: 37397 is a prime number: 3 is a prime number 37 is a prime number 373 is a prime number 3739 is a prime number I would not recommend this algorithm thou because it's slow, …

Member Avatar
Member Avatar
+0 forum 8

Blink and you will see them appear in a Console window. This is a translation to C# of a Modula-2 implementation by N.Wirth, the inventor of Pascal. The tested integers are obtained by incrementing alternatively by 2 and 4, thereby avoiding multiples of 2 and 3 in the first place. This list starts with 5, assuming 2 and 3 are already known primes. Divisibility needs to be tested for prime divisors only, which are obtained by storing previously computed results. This algorithm is a little bit hazier then the traditional "sieve" algorithm. But it is fun to play computer yourself …

Member Avatar
Member Avatar
+0 forum 2

The End.