Subscribe to Novice#

## I'm going to start chowing down the Martyr2 Mega Project list.

Hi guys!

Starting today I'm going to start making the applications listed here:

I'm mainly a C# programmer, but I'm really scared recently. Why? Because I feel I'm getting extremely rusty. I can read a million books, but I'll never be truly good at what I do until I actually do it.

Martyr2's thread is a great resource for new programmers and even novices who are rusty. Since I'm having trouble coming up with programs to try to make, I've decided this.

I'm going to make the program using C# and Python 2.6. I really hope people follow the examples and try to do the same thing because his thread is a real gem.

Tomorrow, I update the blog with solutions to the first three problems.

Quote

Find PI to the Nth Digit – Enter a number and have the program generate PI up to that many decimal places. Keep a limit to how far the program will go.

Fibonacci Sequence – Enter a number and have the program generate the Fibonacci sequence to that number or to the Nth number.

Prime Factorization – Have the user enter a number and find all Prime Factors (if there are any) and display them.

Wish me luck.

### 1 Comments On This Entry

Page 1 of 1

#### Ferencn

10 February 2010 - 08:23 AM
Hey!
Inspired by your quest I wrote a first python script as well!
It's the prime factor finder... After some thinking i came up with the following, recursive algorithm, in pseudocode:
Edit: woke up and realized that the check for prime is unnecessary!

consider the candidate:
if candidate >=4 (2 and 3 are primes, 1 cannot be factorized)
if candidate is even
then 2 is a factor.
else
is any odd number from 3 to the root of the candidate a divisor of candidate?
and the divisor is a prime? then that number is a factor!

factor found?
print it and then consider (candidate/factor).
else
print the candidate and done!

and this is what it looks like when i implemented it in python:
```from math import *

def findfactors(intarget):
factor = -1
if intarget >= 4:    # 2 and 3 are primes!
if (intarget % 2)==0:
factor = 2
else:
checkto = int(sqrt(intarget))
for candidate in range(3,checkto+1,2):
if intarget%candidate == 0:
factor = candidate
break
if factor != -1:
print factor, ' ',
findfactors(intarget/factor)
else:
print intarget

```

I think it can be optimized a bit by passing the last found factor as the value to

looking forward to seeing what you came up with!
1
Page 1 of 1

There are no Trackbacks for this entry

S M T W T F S
12
3456789
10111213141516
17181920212223
2425262728 29 30
31