Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Encoding rules #1

Open
ghost opened this issue Jan 5, 2020 · 3 comments
Open

Encoding rules #1

ghost opened this issue Jan 5, 2020 · 3 comments

Comments

@ghost
Copy link

ghost commented Jan 5, 2020

Is there any description on the encoding rules? To put more clearly, why do -1 corresponds to xabi, hayu to 2592, and so on?

Also, I see that you made this library to study Rust. Good luck on your journey learning Rust!

@nieltg
Copy link
Owner

nieltg commented Jan 6, 2020

Oh, I missed this one. The encoding rule is simple. As you can see, we have constants here:

  • NEGATIVE_SYLLABLE: syllable to represent a negative number.
  • SYLLABLES: an array of syllables, corresponding to each number.

Every negative number will be encoded into a word that starts with xa, then the rest will be treated as a positive number.
The positive number itself will be encoded using division and modulo operation. I'll use 2592 as an example:

  • Modulo of 2592 by 100 (length of SYLLABLES array) is 92. If we use this as an index for looking up a value in SYLLABLES array, we'll found yu syllable.
  • The number is divided by 100, resulting in 25, which will be processed again.
  • Modulo of 25 by 100 is 25, which is ha on SYLLABLES array.
  • Conclusion: the number is encoded as hayu.

If the number is negative, it'll be xahayu. Simple, huh?

Anyway, thanks for that! It's one in my learning-list that I hadn't ever learned until now, I forced myself by writing this crate. 😅

@ghost
Copy link
Author

ghost commented Jan 6, 2020

I see, interesting. Did you make the rule yourself, or are you inspired by something?

Cool, working on a project is definitely one of the better ways to learn a language!

@nieltg
Copy link
Owner

nieltg commented Jan 9, 2020

No, it's based on munemo Ruby gem which is stated here and as you can see, munemo Ruby gem itself is also based on mnemo library, which is written on C.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant