G
gteddy923
I had a written test of a company the other day, there's an
interesting problem. it's as below:
Write a function with input parameters i and n, then use only one line
of statement to produce the formatted results as below:
i
i+1
....
n
n-1
....
i
For example, let i = 1, n = 4, then the output should be:
1
2
3
4
3
2
1
The trickest thing is that you should USE ONLY ONE STATEMENT to
accomplish that.
The problem is 10 points, if you use one loop, 4 points will be
minused, if you use one other statement, 2 points will be minused.
Can anybody figure out if it's feasible without loosing any points?
Thanks,
interesting problem. it's as below:
Write a function with input parameters i and n, then use only one line
of statement to produce the formatted results as below:
i
i+1
....
n
n-1
....
i
For example, let i = 1, n = 4, then the output should be:
1
2
3
4
3
2
1
The trickest thing is that you should USE ONLY ONE STATEMENT to
accomplish that.
The problem is 10 points, if you use one loop, 4 points will be
minused, if you use one other statement, 2 points will be minused.
Can anybody figure out if it's feasible without loosing any points?
Thanks,