Answer the question
In order to leave comments, you need to log in
How to sort through all possible combinations of three characters in order?
The bottom line is:
There is a hash code of three characters, the initial value is 000, for example.
You need to write a function that, knowing only the previous hash, will create the next one, something like: the
previous one is 000 - then the next 001,
the next 002 and so on until 00z,
then 011, 012, 013 and so on up to 0zz
How can such a function be written, maybe there are already similar implementations?
Answer the question
In order to leave comments, you need to log in
> incHash = (h) => ('00' + (parseInt(h, 36) + 1).toString(36)).slice(-3)
[Function]
> incHash('000')
'001'
> incHash('00z')
'010'
> incHash('12z')
'130'
> incHash('1sz')
'1t0'
function pad(num, size) {
var s = (num+1)+"";
while (s.length < size) s = "0" + s;
return s;
}
pad(004, 3);
pad(005, 3)
erlang:
Code = [ 1,2,3 ].
[{A,B,C} || A <- Code, B <- Code, C <- Code ].
12> F = fun(A) -> integer_to_binary(binary_to_integer(A, 3) + 1, 3) end.
#Fun
13> F(<<"000">>).
<<"1">>
14> F(<<"001">>).
<<"2">>
15> F(<<"002">>).
<<"10">>
16> F(<<"010">>).
<<"11">>
17> F(<<"210">>).
<<"211">>
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question