<?xml version="1.0" encoding="UTF-8"?>
<!--Generated by Squarespace V5 Site Server v5.13.159 (http://www.squarespace.com) on Wed, 22 May 2013 20:14:59 GMT--><feed xmlns="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/"><title>Home</title><subtitle>Home</subtitle><id>http://andrewtubman.com/home/</id><link rel="alternate" type="application/xhtml+xml" href="http://andrewtubman.com/home/"/><link rel="self" type="application/atom+xml" href="http://andrewtubman.com/home/atom.xml"/><updated>2012-08-25T05:53:50Z</updated><generator uri="http://five.squarespace.com/" version="Squarespace V5 Site Server v5.13.159 (http://www.squarespace.com)">Squarespace</generator><entry><title>What happens when you play Cypress Hill through a squid’s fin</title><category term="Science"/><category term="cypress hill"/><category term="music"/><category term="squid"/><category term="video"/><id>http://andrewtubman.com/home/2012/8/24/what-happens-when-you-play-cypress-hill-through-a-squids-fin.html</id><link rel="alternate" type="text/html" href="http://andrewtubman.com/home/2012/8/24/what-happens-when-you-play-cypress-hill-through-a-squids-fin.html"/><author><name>Andrew Tubman</name></author><published>2012-08-24T20:34:54Z</published><updated>2012-08-24T20:34:54Z</updated><content type="html" xml:lang="en-US"><![CDATA[<p><iframe width="640" height="360" src="http://www.youtube.com/embed/G-OVrI9x8Zs" frameborder="0" allowfullscreen></iframe></p>]]></content></entry><entry><title>Reggie Watts</title><category term="Music"/><category term="connon"/><category term="music"/><category term="reggie watts"/><id>http://andrewtubman.com/home/2012/6/6/reggie-watts.html</id><link rel="alternate" type="text/html" href="http://andrewtubman.com/home/2012/6/6/reggie-watts.html"/><author><name>Andrew Tubman</name></author><published>2012-06-06T14:13:07Z</published><updated>2012-06-06T14:13:07Z</updated><content type="html" xml:lang="en-US"><![CDATA[<p><iframe width="560" height="315" src="http://www.youtube.com/embed/a2DXfKosT3s" frameborder="0" allowfullscreen></iframe></p>]]></content></entry><entry><title>Kodomo - Concept 1</title><category term="Music"/><category term="concept 1"/><category term="kodo"/><id>http://andrewtubman.com/home/2012/6/2/kodomo-concept-1.html</id><link rel="alternate" type="text/html" href="http://andrewtubman.com/home/2012/6/2/kodomo-concept-1.html"/><author><name>Andrew Tubman</name></author><published>2012-06-02T14:45:23Z</published><updated>2012-06-02T14:45:23Z</updated><content type="html" xml:lang="en-US"><![CDATA[<p><iframe width="560" height="315" src="http://www.youtube.com/embed/o3evFq3dDg8" frameborder="0" allowfullscreen></iframe></p>]]></content></entry><entry><title>Project Euler - Problem 5</title><category term="Problem 5"/><category term="Programming"/><category term="Programming"/><category term="Project Euler"/><category term="Python"/><id>http://andrewtubman.com/home/2012/5/9/project-euler-problem-5.html</id><link rel="alternate" type="text/html" href="http://andrewtubman.com/home/2012/5/9/project-euler-problem-5.html"/><author><name>Andrew Tubman</name></author><published>2012-05-09T21:06:32Z</published><updated>2012-05-09T21:06:32Z</updated><content type="html" xml:lang="en-US"><![CDATA[<h3><span>What is the smallest positive number that is&nbsp;</span><dfn title="divisible with no remainder">evenly divisible</dfn><span>&nbsp;by all of the numbers from 1 to 20?</span></h3>
<p>This was a neat question could be brute forced easily but that would be very slow. There is a table method which exploits the properties of prime numbers to find least common multiple of a set of numbers. The exact method can be found on the least common multiple <a href="http://en.wikipedia.org/wiki/Least_common_multiple">wikipedia page</a></p>
<p><script type="syntaxhighlighter" class="brush: py"><![CDATA[
import copy 

def dividable(x,divisor):
    if x%divisor==0:
        return x/divisor
    else:
        return x
    
def addRows(lis,multiple):
    prevRow=lis[len(lis)-1]
    newRow = [dividable(elem,multiple) for elem in prevRow]  
    while prevRow!=newRow:     
        lis.extend([newRow])
        prevRow = newRow
        newRow = [dividable(elem,multiple) for elem in prevRow]  
    return lis  

#inital values
factors = [[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20]]
primes = [2,3,5,7,11,13,17,19]
multipleCount = [0]*len(primes)

#use table to work out prime factor counts
table = copy.deepcopy(factors)
prevLen = 1
for i in range(0,len(primes)):
    table = addRows(table,primes[i])
    multipleCount[i] = len(table) - prevLen
    prevLen = len(table)

#compute solution using prime factors    
solution=1
for i in range(0,len(primes)):
    solution*=primes[i]**multipleCount[i]

print "Solution: The least common multiple of %s is: %d" % (factors,solution)
]]></script></p>]]></content></entry><entry><title>Project Euler - Problem 4</title><category term="Programming"/><category term="Project Euler"/><category term="Python"/><category term="problem 4"/><id>http://andrewtubman.com/home/2012/5/5/project-euler-problem-4.html</id><link rel="alternate" type="text/html" href="http://andrewtubman.com/home/2012/5/5/project-euler-problem-4.html"/><author><name>Andrew Tubman</name></author><published>2012-05-05T15:00:39Z</published><updated>2012-05-05T15:00:39Z</updated><content type="html" xml:lang="en-US"><![CDATA[<h3><span>Find the largest palindrome made from the product of two 3-digit numbers.</span></h3>
<p>A palindrome is a string which reads the same forwards and backwards for example 98789. The isPalinedrome(x) method checks if x is a palindrome by checking if x equals x in reverse. The n[::-1] call returns the reverse of n. The stride notation lets you filter in a interval of elements in a list. For example the call n[::2]&nbsp;for n = [1,2,3,4] &nbsp; would return [2,4]. Then a nested for loop is used to find the biggest palindrome made of the product 3 digit integers.</p>
<p><script type="syntaxhighlighter" class="brush: py"><![CDATA[
import math

def isPalindrome(x):
    n = str(x)
    if n==n[::-1]:
        return True
    else:
        return False
        
        
biggest = 0
for i in range(999,100,-1):
    for k in range(999,100,-1):
        if (i*k)>biggest and isPalindrome(i*k):
            biggest=i*k

print "Solution: %s " % biggest
]]></script></p><p></p>]]></content></entry><entry><title>RIP Adam 'MCA' Yauch of the Beastie Boys</title><category term="Adam Yauch"/><category term="Beastie Boys"/><category term="MCA"/><category term="Music"/><id>http://andrewtubman.com/home/2012/5/4/rip-adam-mca-yauch-of-the-beastie-boys.html</id><link rel="alternate" type="text/html" href="http://andrewtubman.com/home/2012/5/4/rip-adam-mca-yauch-of-the-beastie-boys.html"/><author><name>Andrew Tubman</name></author><published>2012-05-04T20:36:38Z</published><updated>2012-05-04T20:36:38Z</updated><content type="html" xml:lang="en-US"><![CDATA[<p>Pretty bummed about lossing MCA today. Been a fan for as long as I can remember. There's pretty much always been a Beastie Boys album in my rotation from Hello Nasty to the Mix Up. Here's a homage to sabotage that me and some friends made while finishing up highschool.</p>
<p><iframe src="http://player.vimeo.com/video/1115316" width="600" height="400" frameborder="0" webkitAllowFullScreen mozallowfullscreen allowFullScreen></iframe></p>]]></content></entry><entry><title>Project Euler - Problem 3</title><category term="Learning Python"/><category term="PProject Euler"/><category term="Problem 3"/><category term="Programming"/><category term="Python"/><id>http://andrewtubman.com/home/2012/5/2/project-euler-problem-3.html</id><link rel="alternate" type="text/html" href="http://andrewtubman.com/home/2012/5/2/project-euler-problem-3.html"/><author><name>Andrew Tubman</name></author><published>2012-05-02T12:52:38Z</published><updated>2012-05-02T12:52:38Z</updated><content type="html" xml:lang="en-US"><![CDATA[<h3><span>What is the largest prime factor of the number 600851475143 ?</span></h3>
<p>This problem is a little tricky the solution looks simple but there&nbsp;are a few key things that let it run quickly. First we take the square root of 600851475143 and start searching from that value to zero. We can look in this range because any factor greater than the square root would have a multiple below it and thus not be prime. The second thing to note is the if statement which checks if we have found a solution. We check if it is factor before checking if it is prime. This cuts down on the number of expensive prime checks because they are only done after confirming that a value is a factor of 600851475143. This is because the 'and' statement returns false after the first operand is checked and doesn't waste time computing the second one (the prime test)</p>
<p><script type="syntaxhighlighter" class="brush: py"><![CDATA[
import math
def isPrime(x):
    m=2
    while m<x:
        if x%m==0:
            return False
        m+=1
    return True

val = 600851475143
fact=int(math.floor(math.sqrt(val)))
while fact>0:
    fact-=1
    if val%fact==0 and isPrime(fact):
        break

print "Solution: %s" % fact
]]></script></p>]]></content></entry><entry><title>Project Euler - Problem 2</title><category term="Learning Python"/><category term="Problem 2"/><category term="Programming"/><category term="Project Euler"/><category term="Python"/><id>http://andrewtubman.com/home/2012/5/1/project-euler-problem-2.html</id><link rel="alternate" type="text/html" href="http://andrewtubman.com/home/2012/5/1/project-euler-problem-2.html"/><author><name>Andrew Tubman</name></author><published>2012-05-01T13:47:34Z</published><updated>2012-05-01T13:47:34Z</updated><content type="html" xml:lang="en-US"><![CDATA[<h3><span>By considering the terms in the Fibonacci sequence whose values do not exceed four million, find the sum of the even-valued terms.</span></h3>
<p><span>Problem 2 of project euler is another simple one. The next value in the fibonacci sequence is the sum of the previous 2 values. As we produce the next value in the fibonacci sequnece we sum up the even values.</span></p>
<p><script type="syntaxhighlighter" class="brush: py"><![CDATA[
x=1
y=1
cur=2
sum=0
while cur<=4000000:
    if cur%2==0:
        sum+=cur
    tmp=cur
    cur+=y
    x=y
    y=tmp
print "Solution: %s" % sum
]]></script></p>]]></content></entry><entry><title>Project Euler - Problem 1</title><category term="Learning Python"/><category term="Problem 1"/><category term="Programming"/><category term="Programming"/><category term="Project Euler"/><category term="Python"/><id>http://andrewtubman.com/home/2012/5/1/project-euler-problem-1.html</id><link rel="alternate" type="text/html" href="http://andrewtubman.com/home/2012/5/1/project-euler-problem-1.html"/><author><name>Andrew Tubman</name></author><published>2012-05-01T13:21:45Z</published><updated>2012-05-01T13:21:45Z</updated><content type="html" xml:lang="en-US"><![CDATA[<h3>Find the sum of all the multiples of 3 or 5 below 1000.</h3>
<p>First problem starts off pretty simple. For each of the numbers 1 through 1000 we check if they are divisable by 3 or 5 and sum up the values that are. Checking if a interger is divisable is done using the <a href="http://en.wikipedia.org/wiki/Modulo_operation">modulo</a> operator &nbsp;% which returns the remainder of a division. If the remainder is 0 then the two operands divide evenly.</p>
<p><script type="syntaxhighlighter" class="brush: py"><![CDATA[
sum=0
for i in range(1,1000):
    if i%3==0 or i%5==0:
        sum+=i
print "Solution: %s" % sum
]]></script></p>]]></content></entry><entry><title>Lets Blog About Code</title><category term="Aptana Studio"/><category term="Dive Into Python"/><category term="Eclipse"/><category term="Learn Python the Hard Way"/><category term="Programming"/><category term="Project Euler"/><category term="Python"/><category term="Syntax Highlighter"/><id>http://andrewtubman.com/home/2012/4/30/lets-blog-about-code.html</id><link rel="alternate" type="text/html" href="http://andrewtubman.com/home/2012/4/30/lets-blog-about-code.html"/><author><name>Andrew Tubman</name></author><published>2012-04-30T13:28:48Z</published><updated>2012-04-30T13:28:48Z</updated><content type="html" xml:lang="en-US"><![CDATA[<h3>Learning Python</h3>
<p>During my undergrad I spent a lot of time programming in Java, C and C++. I also played with Scheme and Prolog for a semester or 2. I've decided to branch out and learn Python a lanaguage whos passionate fanbase has lead me to believe it is made from unicorn farts and fairy dust. It seems like a very versitile language with a nice crisp syntax. I'm also looking to learn web development skills which makes Python a nice fit.</p>
<p>Since I have programming experience under my belt I've chosen <a href="http://www.diveintopython.net/">Dive Into Python</a>&nbsp;as my primary resource. I'm about 50 pages in and so far seems like the right book for me. It has a good pace and assumes readers have prior programming experience. I also looked into&nbsp;<a href="http://learnpythonthehardway.org/">Learn Python the Hard Way</a>&nbsp;which looks like a fantastic way for a beginer to get into programming and learn Python. Both these resources are free to view online.</p>
<p>The IDE I've gone with is&nbsp;<a href="http://www.aptana.com/">Aptana Studio</a>&nbsp;which is based off of Eclipse my favourite Java programming enviroment. It's geared towards web development and has the PyDev python plugin for eclipse built in. Worth checking out.</p>
<p>I'll be completing <a href="http://projecteuler.net">Project Euler</a>&nbsp;problems using Python and posting my solutions here as I go. Not aiming for the 100% most efficient solutions just trying to learn the Python syntax and its in and outs.</p>
<p>Lastly I've finally gotten around to adding <a href="http://alexgorbatchev.com/SyntaxHighlighter/">SyntaxHighlighter</a>&nbsp;to this blog so I can post nicely formated code snippits. Example with a little prime number generator I wrote earlier today below.</p>
<p><script type="syntaxhighlighter" class="brush: py"><![CDATA[
def genPrimes(max):
    """generates primes from 2 to max 
       using a sieve of eratosthenes
    """
    x = range(2,max+1)
    primes = []
    while len(x)>0:
        primes.append(x[0])
        x=removeMultiples(x,x[0])
    return primes
    
def removeMultiples(lis,x):
    for i in lis:
        if i%x==0:
            lis.remove(i)
    return lis  
print genPrimes(120)
]]></script></p>]]></content></entry></feed>