I feel exited every time I'm able to look at other people solutions on here, sometimes I spend hours testing other people code and mession around with it, such a grate opportunity.
I felt the exact same way! After submitting my solution (which had taken several hours) triumphantly, I stared in disbelief at the one-liner at the top. And as well as scrolling through all of the other simpler solutions.
Hah, every time I solve a kata I feel totally embarrassed when looking at the other solutions, especially in this case :) Man, I suck at these kind of problems...
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.
I feel exited every time I'm able to look at other people solutions on here, sometimes I spend hours testing other people code and mession around with it, such a grate opportunity.
I felt the exact same way! After submitting my solution (which had taken several hours) triumphantly, I stared in disbelief at the one-liner at the top. And as well as scrolling through all of the other simpler solutions.
Hah, every time I solve a kata I feel totally embarrassed when looking at the other solutions, especially in this case :) Man, I suck at these kind of problems...
Yeah, U are right
This code may work incorrectlly on some inputs.
For example:
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.
You're welcome.
Nice kata, I enjoyed, thank you :) Please more "Design Pattern" katas!