Timeline for Interview Question
Current License: CC BY-SA 2.5
10 events
when toggle format | what | by | license | comment | |
---|---|---|---|---|---|
Apr 26, 2010 at 18:59 | comment | added | Quixotic |
@ Anton Geraschenko : The problem statement says that x is real input but that solution luckily passed the given test cases :) Probably the judges didn't used any real numbers for checking.
|
|
Apr 26, 2010 at 18:43 | comment | added | Anton Geraschenko | @Debanjan: I thought you said the function took real number arguments ... your solution only works for integers. | |
Apr 26, 2010 at 18:31 | comment | added | Quixotic | After reading out this explanation the solution I compacted the entire idea into f(n) = sgn(n) - (-1)^n * n | |
Apr 26, 2010 at 18:26 | vote | accept | Quixotic | ||
Apr 26, 2010 at 17:47 | comment | added | Anton Geraschenko | What Mariano said, but you should take one of the bits to be the sign bit so that each number has its negative in the same set of four. | |
Apr 26, 2010 at 15:58 | comment | added | Mariano Suárez-Álvarez | Or, more simply, just look at the two least significant bits in the number, and pick the four groups using them. | |
Apr 26, 2010 at 15:39 | comment | added | Sergei Ivanov |
You can split $\mathbb R_+$ into pairs $\{x,y\}$ of the form y=x+1 where $x\in(2k,2k+1]$. The program will look like this. If x>0 and ceil(x) is odd, map x to x+1. If x>0 and ceil(x) is even, map x to -(x-1). If x<0 and ceil(-x) is odd, map x to x-1. If x<0 and ceil(-x) is even, map x to -x-1.
|
|
Apr 26, 2010 at 15:34 | comment | added | Joel David Hamkins | If you intend integers, then use the sets {2n,2n+1,-2n,-(2n+1)} as the sets. That is, you map positive evens to the odd above, odds to the opposite of the previous even, negative evens to the odd below, and negative odds to the positive version of the even above. | |
Apr 26, 2010 at 15:31 | comment | added | Quixotic | umm, sadly I can't figure out how to convert this into a programmable solution :) May be this was not intended by the interviewer. | |
Apr 26, 2010 at 15:27 | history | answered | Joel David Hamkins | CC BY-SA 2.5 |