6 kyu

bit "Wise" #1: XOR-cism

748 of 774bkimmel
Description
Loading description...
Algorithms
  • Please sign in or sign up to leave a comment.
  • cliffstamp Avatar

    This comment has been hidden.

  • xcthulhu Avatar

    It's a little late, but wouldn't it be better if the exercise took an object x = {a: 1, b: 2}, changed x.a and x.b and was called for effect? That would get rid of a lot of the troll solutions.

  • kalisjoshua Avatar

    This comment has been hidden.

    • bkimmel Avatar

      Yeah, see the comments above... originally, I made it so you only had access to the bitwise operators through a machine... but it felt a bit contrived, so I just left it as DIY with some encouragement to use the bitwise ops.

    • jsoverson Avatar

      This comment has been hidden.

    • delfuego Avatar

      I agree with jsoverson -- I actually didn't understand what you wanted from the description, and the simple return statement is certainly the easiest way to achieve what turns out to be what you wanted. This kata should definitely have a goal that's more than just that if you want to teach the bitwise operators.

  • jhoffner Avatar

    I'm thinking 5 kyu for this just because bitwise operators are an obscurely used language feature.

  • bkimmel Avatar

    Thanks for the suggestions, but I think both of those throw false positives and/or are easily hacked around in a "source-scanning arms race". I'm enjoying this site because people are generally cool and just follow the code...at the end of the day, if someone wants to cheat the kata, they are just cheating themselves.

  • bkimmel Avatar

    If you like this, drop a comment here and I'll continue making some more in this bit "Wise" series.

    • constablebrew Avatar

      Seems a bit contrived and the framework you create hides away the actual bitwise operators, which works against what you are trying to teach here. I think a better approach would be to find problems that are naturally best solved by bitwise operations and then make a kata for that problem, giving a hint in the description that the bitwise operator could be useful.

    • jhoffner Avatar

      I agree with constablebrew's comments. I also wasn't really sure what needed to be done. I do like where you are going with this though and think that this could be a good series of kata.

      Also I took the liberty of updating the description so that it uses syntax highlighting.

    • bkimmel Avatar

      This comment has been hidden.

    • ineiti Avatar

      Would it be possible instead of undefining some functions, defining allowed functions? Well, that's a bit what you did, but it DOES look awkward, even though I do like the principle...

    • bkimmel Avatar

      OK, I changed it to an honor code - based kata. No more contrived object thing-y. Does this work better?

    • constablebrew Avatar

      Maybe you could parse the user's function source to look for any var statements, preventing them from using the store-and-stop technique.

      Here is a quick example. (Probably not very effective, but a decent starting point for what I am thinking.) if(JSON.Stringify(solution).indexOf('var ') > -1) throw 'Sorry, "var" is disabled.';

      One problem I thought of that would almost require a bitwise operation would be to take two strings as input and then return a single string that is the xor of each character of the two strings.

    • jhoffner Avatar

      Since this is a JavaScript only kata you could check the solution code and see if it contains any required characters.

      for example:

      Test.expect(swapper.toString().indexOf('~') > -1, 'You did not use the correct bitwise operator')
      
    • jhoffner Avatar

      Just saw the latest version. I feel like the whole honor system thing will just A: invite people to cheat even more, B: it makes the experience a bit odd because your not really able to code within the comfort of your own coding style.

      I actually think its ok if some users don't use the bitwise operators. For me the spirit of Codewars is to allow users to solve a problem in the way that they feel comfortable with and represents their style of solving problems. After they solve a kata they see the other solutions and often have an ah hah moment where they see how much better/easier/succinct/etc it could have been solved. So IMO, the fact that you are emphasising bitwise so much within the kata name & description means that most will probably take it upon themselves to try to use bitwise operators, and those who don't - that's ok - they will still probably learn something anyway.

    • bkimmel Avatar

      "most will probably take it upon themselves to try to use bitwise operators, and those who don't - that's ok - they will still probably learn something anyway."

      Yeah, and that's the whole point anyways... a couple comments isn't going to stop someone from doing whatever they want to do, so I'll probably just leave this one as is..

    • bkimmel Avatar

      .. took out the "honor code" stuff, so people don't feel bad if they can't figure out how to do it bitwise.

    • jhoffner Avatar

      Looks good. BTW very clever idea with the HINTS approach.