Woburn Challenge 1999 - Suicidal

Good Ethan Hunt

The Impossible Mission Force had some cutbacks and Ethan Hunt was disavowed. His story is now told in the sequel to the popular Good Will Hunting, tentatively titled Good Ethan Hunt. Ethan needs to pay the bills in his currently unemployed state and has taken a job as a janitor at a local college. Here, his tasks include resetting the key combinations to several doors periodically. However, the man's a genius and choosing a random code would be beneath him and so he will reset the code in the following way: The code will involve all the numbers from 0 to n, where n ≤ 15000. The code will be a permutation of the numbers 0 to n such that no k-term subsequence (k ≥ 3) of these numbers forms an arithmetic sequence. Note that "subsequence" implies that the elements are in the same relative order as in the original code.

For example, if n = 4, you must use all the numbers from 0 to 4 and a valid code would be 3, 4, 1, 0, 2. Your task is to generate ONE such code given a value for n.


1st line: # of inputs = m, the number fo test cases.
Next m lines: Different values for n.


For each value of n, output ONE valid code (each code on a separate line)

Sample Input


Sample Output

3 4 1 0 2

All Submissions
Best Solutions

Point Value: 25
Time Limit: 2.00s
Memory Limit: 256M
Added: Sep 30, 2008

Languages Allowed:

Comments (Search)

With a for loop and the "write" command?
I don't understand your question. If you're referring to the fact that the Pascal output screen has a limited width, that doesn't matter here, because your program will actually be outputting to a text file.

I think the problem was that you had "uses crt;" in your program, which in its initialization code sets the maximum line length to 80 characters. It should be fine now that you've removed it, provided that your algorithm actually works.

so if the input was 9, would 0 3 6 9 2 4 8 1 5 7 work???

0 3 6 9
3 5 7
9 8 7
... etc

are all arithmetic sequences.