The best one. Same algorithm as mine.
this is very fast and efficient in my benchmark. I love it!
This comment is hidden because it contains spoiler information about the solution
Nice one, I think this will give the best performance.
Computationally, yes. I prefer spending computer cycles over brain cycles though, to a certain extent of course.
You cast the result to string anyway, isn't using modulo (6 times) more expensive in this case?
There's a couple of nice things about this solution:
It's tidy, each if statement has one line and the result at the end.
if
The if statements are mutually exclusive, so no need for if else.
if else
The default is just set.
The modulo % operator was used for finding the last digit(s), so no casting to string was necessary
%
Loading collection data...
The best one. Same algorithm as mine.
this is very fast and efficient in my benchmark. I love it!
This comment is hidden because it contains spoiler information about the solution
Nice one, I think this will give the best performance.
Computationally, yes.
I prefer spending computer cycles over brain cycles though, to a certain extent of course.
You cast the result to string anyway, isn't using modulo (6 times) more expensive in this case?
There's a couple of nice things about this solution:
It's tidy, each
if
statement has one line and the result at the end.The if statements are mutually exclusive, so no need for
if else
.The default is just set.
The modulo
%
operator was used for finding the last digit(s), so no casting to string was necessary