#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2013
    Posts
    3
    Rep Power
    0

    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
    4294967295

    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
  2. #2
  3. Contributing User

    Join Date
    Aug 2003
    Location
    UK
    Posts
    5,074
    Rep Power
    1802
    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.
  4. #3
  5. Contributing User
    Devshed Demi-God (4500 - 4999 posts)

    Join Date
    Aug 2011
    Posts
    4,708
    Rep Power
    480
    A*B*(A+B)=120/2
    B*C*(B+C)=2940/2
    C*D*(C+D)=8502/2

    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]Code tags[/code] are essential for python code and Makefiles!
  6. #4
  7. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2013
    Location
    India
    Posts
    95
    Rep Power
    4
    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.
  8. #5
  9. Contributing User

    Join Date
    Aug 2003
    Location
    UK
    Posts
    5,074
    Rep Power
    1802
    Originally Posted by eramit2010
    harmonic mean of 3 and 5 = 2*(3*5)/3+5 = 30/8
    You mean 2*(3*5)/(3+5).

    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.

IMN logo majestic logo threadwatch logo seochat tools logo