Post History

Tuesday, May 28, 2013

Beginner Challenge #1: Python algorithm for prime numbers ~~Completed


With procrastination against me, I managed to finish this task. As simple as this is, I'm pretty proud of it. On the bottom you can see I am testing my Prime_finder function with a really large prime number (31,789,553) and the results came out as True.


How I completed it.

    The one special property of prime numbers is that it's a number that is only evenly divisible by itself and the number 1. In other words it has 2 divisors

   In the code I set up firstly that if the number handed was less than 2 then there's no way for it to be a prime number:
if x < 2:
return False

Then in the second part, the else statement, I set up the code so that it checks every number below  if it is divisible by that number. AND if it was, then I would count that.

for i in range(1, x + 1):
if x % i == 0:
count += 1

Lastly, at the end of the code, it checks to see how many counts there are for x. If x has more than 2 divisors, then it's not a prime number and returns False.

Could I have done this better?

Maybe.

This was a brute force attempt, and you'll notice that if you run really large numbers through this it can take up to half a minute which is quite some time in the mind of a programmer.

Thanks for reading, until next time!  

Monday, May 27, 2013

Beginner Programmer Challenge #1: Pyhton algorithm for prime numbers

An algorithm, in other words, is just a step by step procedure for producing a wanted outcome. This challenge is about finding a step by step procedure for a program to determine if a given number input is prime or not.

Now, I could search for the answer, but what fun would that be? I plan on finishing this within the day. It can't be too difficult...can it?

Sunday, May 26, 2013

The Code I Use: Python (mostly), JavaScript, HTML, CSS

The challenges I will be giving myself will probably be in Python most of the time, but I will also try to add a little more variety at times.

Just to give a background on myself, I am by no means very good so expect these first posts to take on very simple tasks. I've been practicing learning to code for about 3 months now (I started in February).

Motivational quote of the night: Let the challenges, and my road to success begin!

-Helen Hayes

How to Motivate yourself to code more.

Like any other chap in dire need of motivation, I googled "How to motivate yourself".  The first thing I found was some article on about.com listing it's theories. I have my doubts on these methods working, but that may just be my cynical side speaking. Anyhoo.

My two main methods I'll be keeping are the Incentive and Drive theories.

  • The incentive theory states that people will be motivated because of external rewards. 

I hereby proclaim that for every successful challenge I finish I will....I will...I don't know yet but surely it will be good.


  • The drive theory states that people are motivated to take actions in order to reduce the internal tension that is caused by unmet needs.

I've always hated leaving things unfinished so by making this blog public I would become even more ashamed. If I am lacking in consistency, feel free to heckle in the comments!

First Day, The beginning

Serving as a reminder

I've always wanted to learn to code something more advanced, but the motivation...it is lacking. This blog will serve as a reminder and self promise to keep practicing reading, writing, pondering code. I don't know what content I will post here, but for now it will be challenges I set for myself, its progress, and in the end I will publish my hard earned code here, for free.