4 Reusable Code Snippet Topics

Remove Filter
Member Avatar for
Member Avatar for vegaseat

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.

1
1K
Member Avatar for vegaseat

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 …

Member Avatar for vegaseat
2
3K
Member Avatar for Lucaci Andrew

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 …

Member Avatar for RainbowMatrix
0
586
Member Avatar for ddanbe

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. …

Member Avatar for ddanbe
0
94

The End.