July 30th, 2013, 10:20 AM
Understanding the mathematical concept of a inter-school programming problem?
I went to a inter-school competition and there was one programming question i was not able to get my head around.The question was:-
A newbie programmer created the following encryption algorithm:Assign each digit a unique prime number,find the harmonic mean of adjacent numbers, multiply each numerator with the corresponding denominator and store half of the resultant numbers in a file.
For example, if the sequence of primes was 3,5,23,11 the output will be 120,1940,8602
However he accidently encrypted his entire semester's work before he created the decryption program.help him out by creating a decryption program.
=>The program will ask for the number of terms, not more than 10
=>Input the terms
=>Output the sequence of primes in a single line
=> Assume that the prime numbers are sufficiently small such that the product is less that
Sample output from the program
Enter the number of terms : 3
Enter the terms separated by a space : 120 2940 8502
The original sequence of primes was : 3,5,23,11
July 30th, 2013, 03:23 PM
So which part of the maths are you having a problem with?
This is a programming site not a mathematics site. If it is the maths you are having a problem with, then a maths related site would seem to make sense.
The only problem I had with it was the meaning of harmonic mean, but googling that resolved that quickly enough. From Wolfram MathWorld for two values:
H = (G * G) / A
where G is the geometric mean, and A is the arithmetic mean. Furthermore the geometric mean of two values is:
sqrt( a * b )
So given the first two primes in the sequence(3, 5):
The numerator N = (G * G) is 3 * 5 = 15 (G=sqrt(a*b), so G * G is just a * b)
The denominator D = A = (3+5)/2 = 4.
So N * D = 15 * 4 = 60.
In your example you have 120 which is twice 60, so either the question is incorrect or perhaps I am misunderstanding it. Certainly the phrase "half the resultant numbers" is ambiguous, "resultant" has a certain mathematical meaning that does not seem to apply here, perhaps they just meant "half the value of each result"; but that would be thirty in this case.
Moreover the input terms in the example decrypt program output differ from those in the encrypt program output example, yet the final output matches the original input, so we cannot really trust your transcription of the question.
July 30th, 2013, 11:55 PM
Looks like you need to solve these 3 equations for the 4 unknowns given the additional clue that A through D are small prime numbers. But, as Clifford points out, the unclear problem statement makes any additional effort silly.
[/code] are essential for python code and Makefiles!
July 31st, 2013, 01:26 AM
harmonic mean of 3 and 5 = 2*(3*5)/3+5 = 30/8
multiplication of denominator and numerator is 30*8=240
so half of result means 240/2=120 is stored.
by same method i am getting last value 8602 but middle one(2940 or 1940) i am not getting it.
August 1st, 2013, 09:47 AM
You mean 2*(3*5)/(3+5).
Originally Posted by eramit2010
Nonetheless 30/8 == 15/4, which makes a nonsense of the entire exercise since the value of the numerator and denominator depend entirely on which otherwise equivalent formula you have used and whether you choose to simplify the fraction.
It is a poorly constructed exercise that requires domain specific knowledge (i.e. mathematics) making it as much a mathematics problem as a programming one. Even then the maths is flawed.