Strange Sequences - Solve this Problem

Problem Statement
Ms. Anna is very naughty in her classes and due to this her teacher has given her a punishment. Her teacher asked her to create a program for a positive integer i , which can find all possible sequences of positive integers x1, x2, ..., xp such that the sum of all p elements of the above sequence is equal to i and for each r, 1 <= r < p we have x[sub]r+1[/sub]- x[sub]r[/sub] in {-2, 0, 3}. Please help her in creating this program.

Input/Output Specs
Input Specs
In the first line you're given i ( 0 < i ≤ 10 ).

Output Specs
You need to output result to variable output1 as string. Sequences must be given in the lexicographic order, with each sequence enclosed in { }. The numbers within each sequence enclosed in { } must be separated by comma.

Note: In case there is no possible solution, you need to return -999 as output.

Examples
Example 1
Input:
2
Output:
{1,1}{2}

Example 2
Input
3
Output
{1,1,1}{3}

Example 3
Input
4
Output
{1,1,1,1}{2,2}{3,1}{4}

Replies

  • PraveenKumar Purushothaman
    PraveenKumar Purushothaman
    Inviting all the computer geeky people...
    #-Link-Snipped-#, #-Link-Snipped-#, #-Link-Snipped-#, #-Link-Snipped-#, #-Link-Snipped-#
  • Anoop Kumar
    Anoop Kumar
    Example 2
    Input
    3
    Output
    {1,1,1}{3}
    I think it should be:
    {1,1,1}{1,2}{3}
    Am I right??

You are reading an archived discussion.

Related Posts

i want to build an ac-dc-ac inverter. ur ideas are welcome guys.
This is tale of a "CrazyEngineer", sad, one of us who died but lived to the religion called Engineering. Yes, please realize that engineering is a name of a religion....
Olubiyi Olamilekan Jolf is my name. Proudly Nigerian. Student of Electrical/Electronics Engineering, Olabisi Onabanjo University. I have Passion for electronics technology.
Which type of modulation technique is used in SMS and Explain?
Can Somebody please explain me the Concept of Two Gear Levers in Tractors ??