Nokia Tube

I cant wait for this phone to come out. Rumors state Oct 2nd and usually Nokia usually doesnt disappoint. If only the N96 was close to $1200

its been ages, but here goes another attempt

is anyone really surprised by the early iphone reviews ?? I mean when the phone was announced it was pretty clear that other than gps and 3g there wasnt a whole lot that you could call new in this phone. Still doesnt mean I wont go buy one, but the samsung and sony are really looking appealing πŸ™‚

I need to revive this thing again ….. need more ideas though

Project Euler 40

One more πŸ™‚

This one was really easy. Also learnt a thing or two about string concatenations in python when my original techinique of k += str(someInt) was taking way to long as the length of the string increased.

Apparently when wanting to a large number of concatenation, its fast to append to an array and then do a join.

Problem #4o states:-

An irrational decimal fraction is created by concatenating the positive integers:

0.123456789101112131415161718192021…

It can be seen that the 12th digit of the fractional part is 1.

If dn represents the nth digit of the fractional part, find the value of the following expression.

d1 Γ— d10 Γ— d100 Γ— d1000 Γ— d10000 Γ— d100000 Γ— d1000000

Solution:-

import time
w = time.time()
d = ''.join([`num` for num in xrange(1,190000)])
print int(d[0])*int(d[9])*int(d[99])*int(d[999])*int(d[9999])*int(d[99999])*int(d[999999])
print time.time() - w

Project Euler 39

After a long time , but here is another project euler problem that I worked on.

This one was quite fun.

Problem:-

The number 3797 has an interesting property. Being prime itself, it is possible to continuously remove digits from left to right, and remain prime at each stage: 3797, 797, 97, and 7. Similarly we can work from right to left: 3797, 379, 37, and 3.

Find the sum of the only eleven primes that are both truncatable from left to right and right to left.

NOTE: 2, 3, 5, and 7 are not considered to be truncatable primes.

Solution:-

Again its a brute force ( takes a while to get the last prime) ,

I use a generator I found online to get the list of primes and then check if it left and right truncatable.

import time
from itertools import ifilter, count

def isPrime(n):
    if n == 1:
        return False
    
    i = n - 1
    while i > 1:
        rem = n % i
        if rem == 0:
            return False
        else:
            i = i - 1
    return True

def truncateLeft(num):

    k = num

    while k != 0:
        k /= 10
        if not isPrime(k):
            return False
    return True


def truncateRight(num):
    k = num

    while k != 0:
        k %=(10**(len(str(k))-1))
        if not isPrime(k):
            return False
    return True

def sieve():
    g = count(2)
    while True:
        prime = g.next()
        yield prime
        g = ifilter(lambda x, prime=prime: x % prime,g)




candidates = []

t = time.time()

primes = sieve()
start = primes.next()

while len(candidates) != 11:
    if truncateLeft(start) and truncateRight(start) and start > 7:
        candidates.append(start)
        print str(start) + " has been added"
    start = primes.next()

print sum(candidates)   
print time.time() - t

Sony Ericsson has some of the best designs for phones, just have a look at this one:-

I dont even know what to post about anymore, but I will post more often …… in other news last week I was in New Orleans for company training and now I am a SCRUM Master πŸ™‚

Project Euler #39

This is my solution for Project Euler #39

its definitely brute force and im sure there is a better way to get the answer, but here we go

Problem:-

f p is the perimeter of a right angle triangle with integral length sides, {a,b,c}, there are exactly three solutions for p = 120.

{20,48,52}, {24,45,51}, {30,40,50}

For which value of p 1000, is the number of solutions maximised?

My Solution:-

import math, time

t = time.time()

maximum = {}

for a in xrange(1,500):
    for b in xrange(1,500):
        c = math.sqrt(pow(a,2)+pow(b,2))
        p = a+b+c
        if p == int(p) and p < 1000:
            if maximum.has_key(p):
                maximum[p] += 1
            else:
                maximum[p] = 1

e = maximum.keys()
e.sort(cmp = lambda a,b: cmp(maximum[a],maximum[b]))
print e[-1]
print time.time()-t

Project Euler

I am completely addicted to this site…its all about solving math problems using programming.

Here is the solution to one of the problems

How Many Lychrel Numbers are below 10,000 ? http://projecteuler.net/index.php?section=problems&id=55

my solution in python, which takes abt 39 seconds:-

def lychrel(x):
 i = 0
 while i < 50:
  x += int(str(x)[::-1])
  if str(x) == str(x)[::-1]:
   return False
  i += 1
 return True

print len ([x for x in range(1,10000) if lychrel(x)])
Previous page (7 / 37) Next page (9 / 37)