Alright, I think I have it working pretty well, now! My arbitrary length positive integer codec for arbitrary ascii encoding is "finished"!

I can convert numeric (dec, bin, ter, quad, etc.), alphabetical, alphanumeric (case sensitive and non-sensitive, like hex, bech32, base58), other non-alphanumeric like base64 (includes a '+' and a '/'), and any arbitrary encoding that can be expressed as a non-repeating sequence of characters (can be expressed as a Vec) from values 0 to 255 or fewer.

I took a base64 integer of length 8161 digits (the max length the command line would allow me to enter) and converted to alphabetical, hex, and decimal, and it only took a couple seconds.

There are a few optimizations I could make, like checking for bases of powers of two and using shifts rather than multiplications and divides, doing more bulk operations of the Vec, and going up from Vec to Vec to reduce the number of operations, but still, it works!

I think I might also be able to create a few new large-integer types that would act like u256, u512, u2048, etc., using arrays rather than vectors, and that might unlock more optimizations. However, this was only a challenge I gave myself so I could learn Rust, so I might not so I can move on to learn more and start on other projects.

What do I do with it now?

#learnRust #rust #ask Nostr

Reply to this note

Please Login to reply.

Discussion

Ooh! I have a great idea! ... no, no more side projects 😭 why must I be plagued by interesting ideas that I ought not pursue?

...

Okay, I'll at least share. I could create a new number system type with arbitrary (or just really big) precision and mixed base with support for complex numbers and common irrational numbers. For example, a PreciseFloat would be something like...

type PreciseComplexFloatingPoint = (

[u32; 64], // real mantissa, 2048 bit precision

[u32; 64], // imaginary mantissa, 2048 bit precision

[i16; 64], // prime factors, first 64 primes, raised to the power

[i16; 32], // common irrational factors, such as pi, e, etc., raised to the power

i32, // binary exponent

);

This could be really interesting for niche mathematical research type applications. The idea would be to make rounding errors basically impossible.

This would be such an interesting problem to work on ...

#rust #rustLang #learnRust