Reputation: 500
My goal is to guess alphanumeric strings for Bitcoin mining to match leading zeros. For this, I have to increment the encoded string and check whether the string produces the expected Nonce.
For example in scala, we can use base36 binary to text encoding:- BigInt(someAlphaNumString, 36) and increment it by adding BigInt(1, 36) to our string.
What is the better way to do same in elixir?
Upvotes: 0
Views: 278
Reputation: 222428
Integers in Elixir are arbitrary precision integers, so there's no need for any special BigInt data type. You can convert a base-36 string to and from integer using String.to_integer/2
and Integer.to_string/2
like this:
iex(1)> a = String.to_integer("DOGBERT", 36)
29776764809
iex(2)> b = a + 1
29776764810
iex(3)> Integer.to_string(b, 36)
"DOGBERU"
Upvotes: 5