Ad
  • Custom User Avatar

    This is not my solution - my solution (submitted) is somewhat different. I found it online as a model solution and merely wanted to see whether it would pass the tests. As it happens, the first test returned an error, and I pressed 'submit' by mistake. It is very frustrating not to be able to delete a solution that has been submitted inadvertently. If a moderator could remove this solution, that'd be helpful.

  • Custom User Avatar
  • Custom User Avatar

    This code may work incorrectlly on some inputs.
    For example:

    str = "12345678912345"
    ~~str // 1942903641
    

    This happens because bitwise operations convert it arguments to 32-bit integers. In this example binary representation of number in str is more than 32 bit, therefore it is truncated.

    So you should use this code only, if you are sure, that all numbers that you pass in your function fit 32-bit.

  • Custom User Avatar

    Why make programing so difficult ?? Have fun have your life