12
Challenge
In this task you have to write a program that will take input an integer N (-1e9 <= N < 0 && 0 < N <= +1e9), then compute T = (abs(N) % M+1),if N is positive then output the T-th character from the beginning else output the T-th character from the end of your source.
M is the size of your source in bytes.
Example: If your source is: abcd efg/hi
Input:
2
Output:
c
Input:
-3
Output:
g
Input:
-9249678
Output:
b
Input:
-11
Output:
i
Constraints
- Don't use any FILE operation
- You can use any language of your choice
- Try to avoid or rather don't use 1 byte submissions, since it spoils all fun.
- Shortest solution wins!
EDIT: Problem statement have been modified so that the solutions could be judged using a random test-data (and same data for all solutions) hence please update your solution accordingly,sorry for the inconvenience (if any).
1I guess the
&&
in the first sentence is meant to be a||
? – Paŭlo Ebermann – 2015-10-25T16:17:31.163In the give example test case if the input is 5 or -7 the output should be a single space : " " (without quotation). – Quixotic – 2011-03-09T19:11:39.127
What if N is 0? – aaaaaaaaaaaa – 2011-03-09T21:16:55.090
@eBusiness:Thanks for pointing that out, I have changed the problem statement,I don't think $0$ can occur now :-) – Quixotic – 2011-03-09T23:01:57.450
@Debanjan: your edit makes the case where N=M+1 a little weird. – J B – 2011-03-09T23:04:47.100
Opertor precedence
%M
will be executed first before addition ;-) – Quixotic – 2011-03-09T23:11:15.407@Debanjan: oh I see. The spacing got me. – J B – 2011-03-09T23:15:15.580
Your examples don't match your challenge description, if I'm not completely mistaken. First example:
N=2
, soT=3
. The 3rd character isc
, notb
. – Ventero – 2011-03-09T23:42:08.080@Ventero:Yes,thanks for pointing,I fixed it now. – Quixotic – 2011-03-10T06:30:56.897
3It sorta keeps on being a strange mapping, now a character is skipped at the jump from 0 to 1:
-2 -> /
-1 -> h
0 -> i
1 -> b
2 -> c
. But at least the mapping is now unanimous. – aaaaaaaaaaaa – 2011-03-10T12:27:14.033