Primes Problem in Python

السلام عليكم و رحمة الله و بركاته

Lately I decided to give SPOJ website a try ..
And my first problem after the TEST problem was the “PRIME1” problem..
Which is basically finding the prime numbers between 2 given numbers ..

Yesterday, regardless the fact of being truly ill and I hardly could open my eyes ..
I decided to solve the problem ..

and after I think 1 hour It started to output relatively right solution ..

here is my code in python:

times = input()
while times > 0:
    times -= 1
    limits = raw_input()
    limits = limits.split(" ")
    downLimit = int(limits[0])
    upLimit = int(limits[1])
    numsList = []
    numsList = [i for i in range(downLimit,upLimit) if (i%2 or i==2) and i != 1 and i!=0]
    primesList = list(numsList)
    for oddNumber in numsList:
        primeNumber = True;
        for number in range( 2 , oddNumber / 2):
            if oddNumber % number == 0:
                primeNumber = False;
                break;

        if not primeNumber:
            primesList.remove( oddNumber )

    for primeNumber in primesList:
        print primeNumber

Notes:
1-in line 9, I used list() to assign the numsList value to the primesList list .. not the numsList as python-strangely- assigns the old list reference to the new list and that caused +1 hour of debug .. :@
2-As shown in page title after submitting the problem they replied that solution exceed the time limit .. so any help will be appreciated ..
3-Python version 2.6.2 on Mac

TDD using PHPUnit, NetBeans

السلام عليكم و رحمة الله وبركاته

This post is more than month on my drafts ..

It’s about using NetBeans 6.7.1 PHP IDE with PHPUnit I wanted to show how easy is it to make a test and run it ..

so I’ll share the experiment ..
As shown in the following slideshow:

1-I created a PHP Class file:

2-I created empty file with a class and couple of methods

3-I generated a test for the class and it prompted me to choose the folder where I’ll put the tests

4-Finally(My favorite part) I right click the test file to run it and I get the result in green and red … obviously
green is test passed or pending and red if it’s failed ..

Note: I used to use simple test , still can’t find equivalent test method to test the HTML interface … and it always required me to view the test results in the browser ..
PHPUnit is more fun now and it’s integrated to NetBeans, the IDE I recently love at most specially on Mac

testing syntax highlighting

testing ..

echo "hello, highlighting .. ";

Shutting my babies down ..

Shutting my babies down .. and now ..
They started ..

أذكار الصباح المساء

أذكار الصباح  و المساء  بصوت الشيخ مشاري بن راشد العفاسي

Idiot and rude ..

So far it’s 2:30 PM when I’m writing ..

Today was not a nice day .. I looked Idiot and felt that .. then while thinking about the results of looking like that I acted so rude ..!!
and I’m now feeling less confident and I also noticed that my self-confident is actually dependent on how people evaluate me ..
which isn’t right ..
Anyway ..

Today I lost I admit it .. and I’ll be trying the rest of my life .. and may be I’ll -even for one day- enjoy the victory ..

يا رب قويني يا رب …


Get Adobe Flash playerPlugin by wpburn.com wordpress themes