Archive
Python : Curious Number
Python: Curious Number
Problem No.34 in ProjectEuler
Definition: A number is Curious Number if the factorial of their digits equal to the number itself.
Example: 145 is a curious number, as 1! + 4! + 5! = 1 + 24 + 120 = 145.
Our Task: We will write two functions, first one will get (return) all digits in the number, then another function to get the factorial of each digits in that number then with If statement we will examine the result.Enhancement: We will ask the user to enter a number and we will check if it is a Curious Number.
We will reuse some of our functions that we wrote in previous posts.
The Code:
digs=[]
print(‘\nEnter a number to see if it is a Curious Number or not.’)
num=input (‘\nEnter a number: ‘)
num=input (‘Enter a number: ‘)
tot=0
# To get the digits In a number
def digits_in_num (num):
for each in str(num):
digs.append(each)
# To get the Factorial of a number
def Factorial_digit_sum(num):
if (num == 0) :
return 1
else:
return num * Factorial_digit_sum(num-1)
for each in digs:
print(‘factorial :’,each,’ is ‘,Factorial_digit_sum(int(each)))
tot = tot + Factorial_digit_sum(int(each))
print(‘\nTotal sum of the Factorial of each digits is: ‘,tot)
if int(num) == tot:
print(num ,’Is a Curious Number.’)
else:
print(num ,’Is NOT Curious Number.’)
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=’7316717653133062491922511967442657474235534919493496983520312774506326239578318016984801869478851843858615607891129494954595017379583319528532088055111254069874715852386305071569329096329522744304355766896648950445244523161731856403098711121722383113622298934233803081353362766142828064444866452387493035890729629049156044077239071381051585930796086670172427121883998797908792274921901699720888093776657273330010533678812202354218097512545405947522435258490771167055601360483958644670632441572215539753697817977846174064955149290862569321978468622482839722413756570560574902614079729686524145351004748216637048440319989000889524345065854122758866688116427171479924442928230863465674813919123162824586178664583591245665294765456828489128831426076900422421902267105562632111110937054421750694165896040807198403850962455444362981230987879927244284909188845801561660979191338754992005240636899125607176060588611646710940507754100225698315520005593572972571636269561882670428252483600823257530420752963450
‘
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 NdefinitionThe 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 == 0) :
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 Factors
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,

Follow me on Twitter..






