Skip to content

Instantly share code, notes, and snippets.

@0x8badf00d
Created May 16, 2014 14:41
Show Gist options
  • Save 0x8badf00d/9f01194af1c36ebc1f3a to your computer and use it in GitHub Desktop.
Save 0x8badf00d/9f01194af1c36ebc1f3a to your computer and use it in GitHub Desktop.
Write function if the input number is 2 return 1, if the input number is 1 then return 2
int usingSubtraction(int x)
{
return 3-x;
}
int usingDivision(int x)
{
return 2/x;
}
int usingPercentile(int x)
{
return (x%2)+1;
}
int usingBitwiseOperation(int x)
{
return x^0x3; // input xor 0011
}
int usingConditional(int x)
{
return x==2?1:2;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment