This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import abc | |
import collections | |
class BasePrime(collections.Sequence): | |
'''Base class for any primes number sequence | |
''' | |
__metaclass__ = abc.ABCMeta | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def get_primes(start, end, primes=[]): | |
'''Get the numbers starting from start with the count based on primes | |
''' | |
sieve = range(start, end) | |
for prime in primes: | |
# Get the start value for primes striking | |
start_value = prime ** 2 | |
if start_value > end: | |
break | |
if start_value < start: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
syntax on | |
set tabstop=4 | |
set shiftwidth=4 | |
set si | |
set nu | |
set showmatch | |
set hlsearch | |
set incsearch | |
set lz | |
set listchars=tab:.. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
from random import randint, random | |
from time import sleep | |
import soy | |
client = soy.Client() | |
tex = soy.textures.Texture() | |
tex.size = soy.atoms.Size((16, 16)) | |
tex.smooth = False | |
can = soy.widgets.Canvas(client.window, tex) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
getDivisors num | |
| num < 1 = [] | |
| otherwise = [x | x <- [n | n <- primeNumbers (num - 1), n <= ((floor.sqrt.fromIntegral) (num + 1))], num `mod` x == 0 ] | |
primeNumbers :: Integer -> [Integer] | |
primeNumbers 2 = [2] | |
primeNumbers num = | |
if getDivisors num == [] | |
then primeNumbers (num - 1) ++ [num] | |
else primeNumbers (num - 1) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def prime(num): | |
primes = [] | |
def is_prime(n): | |
limit = int(n**0.5) + 1 | |
for i in primes: | |
if i > limit: | |
return True | |
elif n % i == 0: | |
return False | |
return True |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def primes(num): | |
def is_prime(n): | |
limit = int(n**0.5) + 1 | |
for i in range(2, limit): | |
if n % i == 0: | |
return False | |
return True | |
return [n for n in range(2, num) if is_prime(n)] | |
print primes(1000000) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <list> | |
#include <iostream> | |
#include "math.h" | |
using namespace std; | |
bool isPrime(int n) { | |
for (int i = 2; i < (int) pow(n*1., 0.5) + 1; i++) | |
if (n % i == 0) | |
return false; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <list> | |
#include <iostream> | |
#include "math.h" | |
using namespace std; | |
bool isPrime(int n, list<int> &primes) { | |
for (list<int>::iterator iter = primes.begin(); iter != primes.end(); ++iter) | |
if (*iter > (int) pow(n*1., 0.5) + 1) | |
return true; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from collections import namedtuple | |
class Enum(tuple): | |
def __new__(cls, *sequential, **named): | |
new_cls = namedtuple(cls.__name__, sequential + tuple(named.keys())) | |
return new_cls._make(range(len(sequential))+named.values()) | |
class ChoicedEnum(tuple): |