33
Amrish
8y

Let's see the coder in you.
If I give input: 1 output: 2
If I give input: 2 output:1
Only these two test cases needed.
You should not use control structures such as if,else,for,while,switch etc. (The answer is simple) (Don't cheat)

int number;
cin>>number; //get number
cout<<??????; //Your code

Comments
  • 1
    There are even multiple solutions
  • 0
    So how do we go about this? If i do t comment my answer how will you see the coder in me?
  • 13
    @fox8091 Answer here
    https://docs.google.com/forms/d/...

    Upvote this comment so that everyone can know where to answer
  • 0
    Everyone knows the answer but when I give the link to the form to answer no one answers.

    ¯\_(ʘ_ʘ)_/¯
  • 1
    @Artemix I don't know how you did it. it's great Congo. Give your answers at form and comment on the rant. I will +1 your comment if answer was correct.
  • 0
    @Artemix I saw your answer, it's correct :) . The later part of my previous comment was for others who still have not answered.
  • 1
    Easy. Done!
  • 0
    @varundey It's correct, great! I get very different solutions. The solution can be still made neat. I will post my solution and all other solutions posted tomorrow.
  • 1
    @Amrish it's O(1) time and constant space. How can you make it more neat?
  • 0
    @varundey My bad, after all Xor seems to be faster than addition/subtraction.
    ¯\_(ツ)_/¯
  • 1
    Everyone is thinking too complex, the answer is extremely short
  • 0
    Variable - - ;
  • 2
    Did it ;)
  • 2
    Throwing my bit of a solution in...
  • 8
    @dfox how about the possibility to do some little code challenges?
  • 18
    @aul12 we definitely like that idea and we've been looking at some possible features along those lines.
  • 2
    submitted !
  • 1
  • 1
    Done, but I feel like that my answer is cheap :D
  • 4
    Solved with 2 chars (excluding variable name). Couldn't find shorter answer ¯\_(ツ)_/¯
  • 1
    Solved, I think? Mine was only one line, no extra variables...
  • 1
  • 1
    I got this after 5 minutes fiddling with [The binary operator used has been redacted].
  • 1
    I almost didn't go to sleep because of this task. Nice challenge.

    I look forward to new ones :D
  • 1
    Done
  • 0
    The hardest part was remembering the syntax as I don't use it ever in actual code :)
  • 1
    @Amrish when do you publish the submissions, interessted on different solutions
  • 2
    Commenting for notifications. Submitted
  • 1
  • 1
    (Nombers%2)+1
  • 0
    Outpur = Input BIT-NAND 3 (Dec 3, binary 11)
  • 2
  • 6
    cout<<3-number;
  • 1
  • 3
    I'll post mine, only because I doubt anyone went this route lol:

    #include <iostream>
    #include <math.h>
    using namespace std;

    int main()
    {
    int number;
    cin >> number;
    cout << floor(abs(tan(number)+.5)) << endl;
    return 0;
    }
  • 5
    Hi everyone. That was an overwhelming response. To my surprise I found more than 10 different correct solutions submitted!! Great!
    I will post all the solutions within 5 hours. It's different time here (India), I just woke up.
    I have not upvoted some comments cause I need a compiler to check them out. I have not upvoted if you had directly commented the answer.
  • 1
    This was fun -- more please?
    And I thought I had a good solution...that 2 character solution is the best lol!
  • 0
    ^ ?
  • 0
    @filthyranter heh, I meant XOR operator.
  • 3
    Hi everyone, follow the link to get all unique solutions given. I have attached repeated solutions too. Great work!

    https://drive.google.com/open/...

    I had no time to put a proper formatting
    ¯\_(ツ)_/¯ . Certain solutions were impressive 😎
  • 4
    Congo @Artemix @Varundey @aul12 @leriaz @TheSilent @cuboidcat @ste26054 @bukovles @W3D3 @vzqzac @Thaon @Gprabhat @asdf 😎 Thanks @dfox.Lets use #devcode tag for more of these :D
  • 0
    @alexanderholman you had to fill the answers in the form link I had given in my previous comments. :)
  • 4
    Top different solutions (filtered by timestamp for repetitive solutions)
  • 2
    @Artemix that was actually the solution I thought of first, but I decided there's a shorter way so I XORed with 3 because how often do you get a chance to use XOR? :)
  • 0
  • 0
    @Artemix my second solution is more or less your solution
  • 1
    @filthyranter Sorry bro, I had missed out your solution, I scrutinized the results so fast (10 mins).

    Solution: 1+(number != 2)
    This solution is correct and unique 😎.

    This makes 16 unique solutions 😎. Great work people!!
  • 1
    A simple 2/(input) should work.
Add Comment