## Python: Multiples of Numbers

**Python: Multiples of 3 and 5 **

** Problem No.1 in ProjectEuler **

**This** is very easy, very short task to work on, the task as is in **ProjectEuler **like this “Find the sum of all the multiples of 3 or 5 below 1000.”

**My way,** as i like to do open code works for any numbers, we will ask the user to enter three numbers, num1 and num2 will be as (3 and 5) in the task, my_range will be as the 1000. So the code can get the sum Multiples of any two numbers in a ranges from 1 to my_range.

**The Code:**

# Multiples of 3 and 5

# ProjectEuler: Problem 1

def Multiples_of_N (num1,num2,my_range):

tot=0

for t in range (1,my_range):

if t %num1==0 or t%num2 ==0 :

tot = tot + t

return tot

print ‘\nDescription: This function will take three variables, two numbers represint the what we want to get there Multiples, then we ask for a range so we will start from 1 to your range.\n’

num1=int(input(‘Enter the first number:’))

num2=int(input(‘Enter the second number:’))

my_range =int(input(‘Enter the range (1, ??):’))

total=Multiples_of_N (num1,num2,my_range)

print ‘\nYou entered ‘,num1,’,’, num2,’ So the sum of all multiples of those number in range (1-‘,my_range,’) = ‘,total

## Python: Largest product in series

**Python: Largest product in a series **

** Problem 8 @ projectEuler **

In Problem 8, ProjectEuler wants to find the thirteen adjacent digits in the 1000-digit number that have the greatest product.

In this task i use a for loop to check each 13-dig set, each time creating a set of 13 digits starting from (0,13) then (1,14)..(2,15)….. and so-on. for each set i get the product of its digits and store it in an a array of [set,total] each time if total of the new set is larger than what we have in the array[total] then we write the new values to the array, we call the array largest.

**The Code:**

# Largest product in a series

# ProjectEuler: Problem 8

num=’7316717653133062491922511967442657474235534919493496983520312774506326239578318016984

8018694788518438586156078911294949545950173795833195285320880551112540698747158523863050715

6932909632952274430435576689664895044524452316173185640309871112172238311362229893423380308

13533627661428280644448664523874930358907296290491560440772390713810515859307960866701724271

218839987979087922749219016997208880937766572733300105336788122023542180975125454059475224

3525849077116705560136048395864467063244157221553975369781797784617406495514929086256932197

8468622482839722413756570560574902614079729686524145351004748216637048440319989000889524345

0658541227588666881164271714799244429282308634656748139191231628245861786645835912456652947

6545682848912883142607690042242190226710556263211111093705442175069416589604080719840385096

2455444362981230987879927244284909188845801561660979191338754992005240636899125607176060588

6116467109405077541002256983155200055935729725716362695618826704282524836008232575304207529

63450

‘

v1=0

v2=13

set1=num[v1:v2]

largest =[0,0]

tot=1

for x in range((1000)):

set1=num[v1:v2]

for each in set1:

tot=tot * int(each)

if tot > largest [1]:

largest[0] = set1

largest[1] = tot

tot=1

tot =1

v1=v1+1

v2=v2+1

print’The thirteen adjacent digits are’,largest[1],’there product is ‘,largest[0]

## Python: Factorial Digit Sum

**Python: Factorial Digit Sum **

** Problem 20 @ projectEuler**

**The Task:** The task in projectEuler P20 is to get the sum of the digits in the number Factorial of 100!

**Factorial Ndefinition**The factorial of a positive integer n, denoted by n!, is the product of all positive integers less than or equal to n. For example, 10! = 10 × 9 × … × 3 × 2 × 1 = 3628800.

**Problem 20** is another easy problem in projectEuler, and we will write two functions to solve it. __First one__ is a Factorial_digit_sum this one will return the factorial of a number. __The second__ function will calculate the sum of all digits in a number N and we will call it sum_of_digits.

**Clarification** As long as i just start solving or posting my answers to projectEuler portal, i am selecting problems and not going through them in sequence, that’s way my posts are jumps between problems, so if i am posting the code to solve problem 144 *(for example)* that does’t meaning that i solve all problems before it.

print of solved screen:

**The Code:**

#Python: Factorial Digit Sum

#Problem No.20 on projectEuler

def Factorial_digit_sum(num):

if (num == 1) :

return 1

else:

return num * Factorial_digit_sum(num-1)

num=100

fact =Factorial_digit_sum(100)

print fact,’is the Factorial of {}.’.format(num)

def sum_of_digits(dig):

t = 0

for each in dig:

t = t + int(each)

print ‘\nThe sum of your number is’,t

sum_of_digits(str(tot1))

## Python: The Factorial

**Python: Factors of the Number N**

This is a short task to get the factors of a given number. The Definition of Factors of N is: The pairs of numbers you multiply to get the N number.

For instance, factors of 15 are 3 and 5, because 3×5 = 15. Some numbers have more than one factorization (more than one way of being factored). For instance, 12 can be factored as 1×12, 2×6, or 3×4

In this task we will write a Python code to ask the user for a number N then will get all the pairs number that if we multiply them will get that N number, we will store the pairs in a array ‘factors’.

**The Code:**

def factors_of_n(num):

a=1

factors=[]

while a <= num:

if num%a==0:

if (num/a,a) not in factors:

factors.append((a,int(num/a)))

a = a + 1

return factors

#Ask the user for a number

num=int(input(“Enter a number: “))

print(factors_of_n(num))

## My New iPhone 4, a stupid lock phone!!

I purchased this iPhone 4 from the internet (amazon.com) there was nothing saying that it’s **lock to AT&T** and can’t be used out side USA (__I wonder where is the customer rights to select a carrier__), once i received it i notes that it will not work on Qatar, i am waiting for the unlock solution for OS 4.2.1 BB 3.10.01… No thing till now. For now all i can do is jailbreak it and hope the unlock will be soon released..

## New Battery and Grip..

Last week I had a problem with my New Battery for the Nikon D90 [*Read the post*]. I went to the Nikon Agent – Qatar, they claimed that there where no warranty on the batteries and the chargers; so they can’t change it or re-fund, I decide to get new one and I ask for the price it increased from 41$ to 45$.. Why??

anyway ..

I search the net [*Amazon.com*] and I fond a battery grip + remote + 2x batteries for 64$, it takes 10 days to be delivered [*international transportation-Aramex*] I just received it and here it is.

It’s not bad, nice shape and material, Made In China 🙂 , and the remote was missed!! so no remote..

The batteries are without brand, no name on it I hope it will work fine with me.

[*Click the image to enlarge*]

## Problem with my D90 Battery

**I** have two Batteries(EN-EL3e) for my Nikon D90 (A and B), last time i get the empty signal for one of them (A) and i replace it with the other(B), but i forget to re-charge the empty one(A), i can’t remember for how long time. (15 day’s or more).

Yesterday i run out of charge(B) and then i realize that i did not charge my (A) battery so i pluged it and here is what happen:

When i charged it, the light on the charger started blinking 3 times then stops (no lights). i’d change the charger .. keep the battery in the charge for 6 hours..cleaned the connectors on the battery,,. no thing…

Some websites and posts suggest to Freeze it overnight, so I did 12hours in the freezer.. and no thing.. I think it’s dead.

I think the reason is that I let it to be empty without charges, I will get new one next week and make sure that it will not go to ZERO charge level.

[*New one cost $41 in Nikon Agent – Qatar*]

*Ali,*