Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- f(f(n)) == -n
- def f(n):
- if n == 0: return 0
- if n >= 0:
- if n % 2 == 1:
- return n + 1
- else:
- return -1 * (n - 1)
- else:
- if n % 2 == 1:
- return n - 1
- else:
- return -1 * (n + 1)
- static double F(double n)
- {
- if (n == 0) return 0;
- if (n < 0)
- return ((long)Math.Ceiling(n) % 2 == 0) ? (n + 1) : (-1 * (n - 1));
- else
- return ((long)Math.Floor(n) % 2 == 0) ? (n - 1) : (-1 * (n + 1));
- }
- f(n) = sgn(n) - (-1)^n * n
- f :: Int -> Int
- f x | (testBit x 30 /= testBit x 31) = negate $ complementBit x 30
- | otherwise = complementBit x 30
- def f(x):
- if isinstance(x,int):
- return (lambda: -x)
- else:
- return x()
- int sign(int n)
- {
- if(n>0)
- return 1;
- else
- return -1;
- }
- int f(int n)
- {
- if(n==0) return 0;
- switch(abs(n)%2)
- {
- case 1:
- return sign(n)*(abs(n)+1);
- case 0:
- return -sign(n)*(abs(n)-1);
- }
- }
- #define f(n) (f##n)
- #define ff(n) -n
- int main()
- {
- int n = -42;
- cout << "f(f(" << n << ")) = " << f(f(n)) << endl;
- }
- double f(int var)
- {
- return double(var);
- }
- int f(double var)
- {
- return -int(var);
- }
- int main(){
- int n(42);
- std::cout<<f(f(n));
- }
- f(n) = abs(n)
- public static Int32 f(Int32 n)
- {
- return 2 * n * (Math.Abs(n) % 2) - n + Math.Sign(n);
- }
- public static Int32 f(Int32 n)
- {
- return 2 * n * (Math.Abs(n) % 2) - n + Math.Sign(n);
- }
- f(f(n)) = -n
- x = f(n)
- +1 => -2 => -1 => +2 => +1
- +1 => -2 => -1 => +2 => +1
- +4
- +3
- Function f(ByVal n As Integer) As Integer
- Static flag As Integer = -1
- flag *= -1
- Return n * flag
- End Function
- int f(int n)
- {
- int sign = n>=0?1:-1;
- if (abs(n)%2 == 0)
- return ((abs(n)+1)*sign * -1;
- else
- return (abs(n)-1)*sign;
- }
- Int64 f(Int64 n)
- {
- return(n > Int32.MaxValue ?
- -(n - 4L * Int32.MaxValue):
- n + 4L * Int32.MaxValue);
- }
- function f(n) {
- if (n.passed) {
- return -n.val;
- } else {
- return {val:n, passed:1};
- }
- }
- js> f(f(10))
- -10
- js> f(f(-10))
- 10
- int f(long n) {
- return n;
- }
- long f(int n) {
- return -n;
- }
- template <class T>
- struct f_result
- {
- T value;
- };
- template <class T>
- f_result <T> f (T n)
- {
- f_result <T> result = {n};
- return result;
- }
- template <class T>
- T f (f_result <T> n)
- {
- return -n.value;
- }
- void main (void)
- {
- int n = 45;
- cout << "f(f(" << n << ")) = " << f(f(n)) << endl;
- float p = 3.14f;
- cout << "f(f(" << p << ")) = " << f(f(p)) << endl;
- }
- int rotate(int x)
- {
- static const int split = INT_MAX / 2 + 1;
- static const int negativeSplit = INT_MIN / 2 + 1;
- if (x == INT_MAX)
- return INT_MIN;
- if (x == INT_MIN)
- return x + 1;
- if (x >= split)
- return x + 1 - INT_MIN;
- if (x >= 0)
- return INT_MAX - x;
- if (x >= negativeSplit)
- return INT_MIN - x + 1;
- return split -(negativeSplit - x);
- }
- 0 => 7 => -8 => -7 => 0
- 1 => 6 => -1 => -6 => 1
- 2 => 5 => -2 => -5 => 2
- 3 => 4 => -3 => -4 => 3
- bool done = false
- f(int n)
- {
- int out = n;
- if(!done)
- {
- out = n * -1;
- done = true;
- }
- return out;
- }
- sub f {
- my $n = shift;
- return ref($n) ? -$$n : $n;
- }
- print $_, ' ', f(f($_)), "n" for -2, 0, 1, 1.1, -3.3, 'foo' '-bar';
- -2 2
- 0 0
- 1 -1
- 1.1 -1.1
- -3.3 3.3
- foo -foo
- -bar +bar
- Func<int, int> f = n =>
- n < 0
- ? (n & (1 << 30)) == (1 << 30) ? (n ^ (1 << 30)) : - (n | (1 << 30))
- : (n & (1 << 30)) == (1 << 30) ? -(n ^ (1 << 30)) : (n | (1 << 30));
- Console.WriteLine(f(f(Int32.MinValue + 1))); // -2147483648 + 1
- for (int i = -3; i <= 3 ; i++)
- Console.WriteLine(f(f(i)));
- Console.WriteLine(f(f(Int32.MaxValue))); // 2147483647
- 2147483647
- 3
- 2
- 1
- 0
- -1
- -2
- -3
- -2147483647
- def f(x):
- if type(x) == list:
- return -x[0]
- return [x]
- f(2) => [2]
- f(f(2)) => -2
- int f(int n):
- if n == 0 or n == MIN_INT or n == MAX_INT: return n
- return ((Math.abs(n) mod 2) * 2 - 1) * n + Math.sign(n)
- int32 f(int32 x) {
- static bool idempotent = false;
- if (!idempotent) {
- idempotent = true;
- return -x;
- } else {
- return x;
- }
- }
- int32 f (int32 x) {
- static int32 answer = -x;
- return answer;
- }
- ; input %edi
- ; output %eax
- ; clobbered regs: %ecx, %edx
- f:
- testl %edi, %edi
- je .zero
- movl %edi, %eax
- movl $1, %ecx
- movl %edi, %edx
- andl $1, %eax
- addl %eax, %eax
- subl %eax, %ecx
- xorl %eax, %eax
- testl %edi, %edi
- setg %al
- shrl $31, %edx
- subl %edx, %eax
- imull %ecx, %eax
- subl %eax, %edi
- movl %edi, %eax
- imull %ecx, %eax
- .zero:
- xorl %eax, %eax
- ret
- def mods(x, n):
- y = x % n
- if y > n/2: y-= n
- return y
- def f(x):
- return mods(x*1849436465, 2**32-3)
- int f(int n) {
- if (n & (1 << 31)) // highest bit set?
- return -(n & ~(1 << 31)); // return negative of original n
- else
- return n | (1 << 31); // return n with highest bit set
- }
- boolean inner = true;
- int f(int input) {
- if(inner) {
- inner = false;
- return input;
- } else {
- inner = true;
- return -input;
- }
- }
- function f($n) {
- if(is_int($n)) {
- return (string)$n;
- }
- else {
- return (int)$n * (-1);
- }
- }
- return x ^ ((x%2) ? 1 : -INT_MAX);
- 1. take n, which is a signed 32-bit integer.
- 2. swap the first bit and the second bit.
- 3. flip the first bit.
- 4. return the result.
- int32_t f(int32_t x)
- {
- return (((x & 0xFFFFU) << 16) | ((x & 0xFFFF0000U) >> 16)) ^ 0xFFFFU;
- }
- Pass | x
- -----+-------------------
- 0 | 00000001 (+1)
- 1 | 0001FFFF (+131071)
- 2 | FFFFFFFE (-1)
- 3 | FFFE0000 (-131071)
- 4 | 00000001 (+1)
- Pass | x
- -----+-------------------
- 0 | 00000000 (+0)
- 1 | 0000FFFF (+65535)
- 2 | FFFFFFFF (-0)
- 3 | FFFF0000 (-65535)
- 4 | 00000000 (+0)
- public static int f(int x)
- {
- if (x == 0) return 0;
- if ((x % 2) != 0)
- return x * -1 + (-1 *x) / (Math.Abs(x));
- else
- return x - x / (Math.Abs(x));
- }
Add Comment
Please, Sign In to add comment