Skip to content

Instantly share code, notes, and snippets.

@russelnickson
russelnickson / projecteuler_prob_3.py
Created December 1, 2009 19:40
The prime factors of 13195 are 5, 7, 13 and 29. What is the largest prime factor of the number 600851475143 ?
a=600851475143
i=2
while i<a :
if a%i==0:
a1=a/i
else :
i+=1
continue
n=2
@russelnickson
russelnickson / projecteuler_prob_16.py
Created December 1, 2009 19:43
2^15 = 32768 and the sum of its digits is 3 + 2 + 7 + 6 + 8 = 26. What is the sum of the digits of the number 2^1000??
a=2**1000
b=0
while a:
b=b+a%10
a/=10
print b
@russelnickson
russelnickson / projecteuler_prob_20.py
Created December 1, 2009 19:49
n! means n (n 1) ... 3 2 1 Find the sum of the digits in the number 100! ??
a=100
b=0
f1=1
while a>1:
f1=a*f1
a-=1
f=f1
while f:
b=b+f%10
f/=10
import sys
from string import split
f=open(sys.argv[1])
content=f.read()
print content
print 'the no.of lines in file = '+ str(len(split(content,'\n')))
import sys
from string import split
f=open(sys.argv[1])
content=f.read()
print content
print 'the no.of sentences in file = '+ str(len(split(content,'.'))-1)
# we sub 1 is because split creates a null element after the last '.'
@russelnickson
russelnickson / Find the Longest Sentence
Created January 14, 2010 10:28
Find the Longest Sentence
import sys
from string import split
f=open(sys.argv[1])
content=f.read()
#print content
sentence=split(content,'.')
largest=smallest=len(sentence[0])
total=0
@russelnickson
russelnickson / count words
Created January 14, 2010 20:23
count words
import sys
import shlex
f=open(sys.argv[1])
content=f.read()
words=shlex.split(content)
print 'word count = '+ str(len(words))
@russelnickson
russelnickson / parse words... my creation... yea..
Created January 14, 2010 20:46
parse words... my creation... yea..
import sys
import shlex
import string
f=open(sys.argv[1])
content=f.read()
sen=string.split(content,'.')
print sen
words=[]
@russelnickson
russelnickson / Count Word Frequency
Created January 14, 2010 21:43
Count Word Frequency
import string,sys
f=open(sys.argv[1])
content= string.lower(f.read())
workinglist =string.split(content)
cleanlist =[]
for item in workinglist:
temp=item.strip(string.punctuation)
cleanlist=cleanlist+[temp,]
@russelnickson
russelnickson / word frequency with noise removed
Created January 14, 2010 21:57
Count Word Frequency2 (Eliminate Noise Words)
import string,sys
f1=open(sys.argv[1])
f2=open(sys.argv[2])
content= string.lower(f1.read())
noisecontent= string.lower(f2.read())
workinglist =string.split(content)
cleanlist =[]
for item in workinglist: