<repo_name>vgovilkar/EulerChallange<file_sep>/README.md
EulerChallange
==============

Python solutions to Euler Challange
<file_sep>/NthPrime.py
#!/usr/local/bin/python2.7
import sys
import math
def NthPrime(num):
	pnos=[2]
	piter=1
	i=3
	while(len(pnos)<num):
		prime=True
		for x in pnos:
			if(x>math.sqrt(i)):
				break;
			if(i%x==0):
				prime=False;
		if(prime):
			pnos.append(i)
		i+=2
	return pnos[-1]
if(__name__=='__main__'):
	print NthPrime(int((sys.argv)[1]))
<file_sep>/lcm.py
#!/usr/local/bin/python2.7

pnos = {2:0,3:0,5:0,7:0,11:0,13:0,17:0,19:0};

def maxprimeFactorization(num):
  for i in pnos.keys():
    times=0;
    while(num%i==0):
      times+=1;
      num=num/i;
    if(pnos[i]<times):
      pnos[i]=times;

for i in range(2,20):
  maxprimeFactorization(i);
print pnos;

product = 1;
for x in pnos.keys():
  while(pnos[x]!=0):
    product*=x;
    pnos[x]-=1;

print product;
    
<file_sep>/prime sieve.py
#!/usr/local/bin/python2.7
    
import math;

numcap=2000000;

def multremover(i):
  def innerremover(x):
    if(x!=i):
      return x % i != 0;
    else:
      return True;
  return innerremover

#Eurotothenes sieve
def sieve(numlist):
  for i in numlist:
    if(i>math.trunc(math.sqrt(numcap))+1):
      break;
    numlist=filter(multremover(i), numlist);  
  return numlist;

numlist=range(2,numcap);

print "hi";
numlist=sieve(numlist);
def add(x,y): return x+y
print reduce(add, numlist);<file_sep>/prime_sieve_efficient.py
#!/usr/local/bin/python2.7
    
import math;    
num=2000000;

binArray= [True]*(num+1);

def wipeMultiples(myNum, myList):
  for i in range(myNum*2,num+1,myNum):
    myList[i]=False;

for i in range(2, math.trunc(math.sqrt(num))+1):
  wipeMultiples(i,binArray);

def add(x,y): return x+y
print reduce(add, [x for x in range(2,num+1) if binArray[x]]);<file_sep>/pythagoreantriplets.py
#!/usr/local/bin/python2.7
    
for i in range(1,998):
  for j in range(1,999-i):
    k=1000-i-j;
    if(i*i+j*j==k*k):
      print i,j,k
      print i*j*k;<file_sep>/largestPrimeFactor.py
#!/usr/local/bin/python2.7
import sys
import math

def LargestPrimeFactor(num):
	pnos = [2];
	upper = math.trunc(math.sqrt(num))
	for i in range (3, upper, 2):
		prime=True;
		for x in pnos:
			if(i%x==0):
				prime=False;
		if(prime):
			pnos.append(i);

	return (pnos[-1]);

if(__name__=='__main__'):
	print(LargestPrimeFactor(int((sys.argv)[1])))