Calculate the characters from a combination












1












$begingroup$


Given a table with position - 2 character combination pairs like this:



1. aa
2. ab
3. ac
4. ad
...
27. ba
28. bb
29. bc
30. bd


Assuming there are unique combinations with two characters from the alphabet following the same pattern.



How do I calculate what is the first and second character of the combination, if I know the position. That is, how do I find position 28 holds bb?





EDIT:



The answer that also describes how to do the reverse, i.e find the position of a combination based on the pair is going to be the most useful answer.










share|cite|improve this question











$endgroup$








  • 1




    $begingroup$
    should ba be $27$ if you are starting from $1$ and including aa?
    $endgroup$
    – gt6989b
    Dec 10 '18 at 14:03










  • $begingroup$
    @gt6989b Oh, I missed one character when counting. (Missed to write it). Sorry.
    $endgroup$
    – Edenia
    Dec 10 '18 at 14:05


















1












$begingroup$


Given a table with position - 2 character combination pairs like this:



1. aa
2. ab
3. ac
4. ad
...
27. ba
28. bb
29. bc
30. bd


Assuming there are unique combinations with two characters from the alphabet following the same pattern.



How do I calculate what is the first and second character of the combination, if I know the position. That is, how do I find position 28 holds bb?





EDIT:



The answer that also describes how to do the reverse, i.e find the position of a combination based on the pair is going to be the most useful answer.










share|cite|improve this question











$endgroup$








  • 1




    $begingroup$
    should ba be $27$ if you are starting from $1$ and including aa?
    $endgroup$
    – gt6989b
    Dec 10 '18 at 14:03










  • $begingroup$
    @gt6989b Oh, I missed one character when counting. (Missed to write it). Sorry.
    $endgroup$
    – Edenia
    Dec 10 '18 at 14:05
















1












1








1





$begingroup$


Given a table with position - 2 character combination pairs like this:



1. aa
2. ab
3. ac
4. ad
...
27. ba
28. bb
29. bc
30. bd


Assuming there are unique combinations with two characters from the alphabet following the same pattern.



How do I calculate what is the first and second character of the combination, if I know the position. That is, how do I find position 28 holds bb?





EDIT:



The answer that also describes how to do the reverse, i.e find the position of a combination based on the pair is going to be the most useful answer.










share|cite|improve this question











$endgroup$




Given a table with position - 2 character combination pairs like this:



1. aa
2. ab
3. ac
4. ad
...
27. ba
28. bb
29. bc
30. bd


Assuming there are unique combinations with two characters from the alphabet following the same pattern.



How do I calculate what is the first and second character of the combination, if I know the position. That is, how do I find position 28 holds bb?





EDIT:



The answer that also describes how to do the reverse, i.e find the position of a combination based on the pair is going to be the most useful answer.







arithmetic index-notation






share|cite|improve this question















share|cite|improve this question













share|cite|improve this question




share|cite|improve this question








edited Dec 11 '18 at 0:10







Edenia

















asked Dec 10 '18 at 14:00









EdeniaEdenia

1085




1085








  • 1




    $begingroup$
    should ba be $27$ if you are starting from $1$ and including aa?
    $endgroup$
    – gt6989b
    Dec 10 '18 at 14:03










  • $begingroup$
    @gt6989b Oh, I missed one character when counting. (Missed to write it). Sorry.
    $endgroup$
    – Edenia
    Dec 10 '18 at 14:05
















  • 1




    $begingroup$
    should ba be $27$ if you are starting from $1$ and including aa?
    $endgroup$
    – gt6989b
    Dec 10 '18 at 14:03










  • $begingroup$
    @gt6989b Oh, I missed one character when counting. (Missed to write it). Sorry.
    $endgroup$
    – Edenia
    Dec 10 '18 at 14:05










1




1




$begingroup$
should ba be $27$ if you are starting from $1$ and including aa?
$endgroup$
– gt6989b
Dec 10 '18 at 14:03




$begingroup$
should ba be $27$ if you are starting from $1$ and including aa?
$endgroup$
– gt6989b
Dec 10 '18 at 14:03












$begingroup$
@gt6989b Oh, I missed one character when counting. (Missed to write it). Sorry.
$endgroup$
– Edenia
Dec 10 '18 at 14:05






$begingroup$
@gt6989b Oh, I missed one character when counting. (Missed to write it). Sorry.
$endgroup$
– Edenia
Dec 10 '18 at 14:05












2 Answers
2






active

oldest

votes


















1












$begingroup$

Assuming you have an alphabet A = ['a','b',...'z'] and a permutation list L = ['aa', 'ab', ..., 'az', 'ba', ... , 'zz'], with the first index starting from 1. (BTW the arithmetic would be much cleaner if you start indexing from $0$, like in the C language, for example.)



Then, the permutations come in groups of $26$, so if you are given an index $k$, then




  • the second letter is given by the offset of $k$ in the current 26-long block, so it is $A[(k-1)pmod{26} + 1]$ and

  • the first letter is given by $Aleft[lfloor(k-1)/26rfloor+1right]$.




If you were to number starting with $0$, the formulae become




  • the second letter is given by $A[k pmod{26}]$ and

  • the first letter is given by $Aleft[lfloor k/26rfloorright]$.




Another free update you get with C, for example, is that if you declare int k, d = 26; then k/d computes $lfloor k/d rfloor$ automatically, no extra flooring is needed.





UPDATE



The inversion is simple. If first letter has index $F$ and last has index $L$, the offset is given by





  • $26F + L$ for $0$-based indexing (like C)


  • $26(F+1) + (L+1) = 26F + L + 27$ for $1$-based indexing






share|cite|improve this answer











$endgroup$









  • 1




    $begingroup$
    Haha, I am implementing algorithms in C, bt dubs.
    $endgroup$
    – Edenia
    Dec 10 '18 at 14:17










  • $begingroup$
    @Edenia see updates
    $endgroup$
    – gt6989b
    Dec 10 '18 at 14:20










  • $begingroup$
    Hmm A[pos % 26] doesn't return the correct first character. Afirst[(pos / sz) - 1] and Asecond[pos % sz] works though
    $endgroup$
    – Edenia
    Dec 10 '18 at 14:32












  • $begingroup$
    sz being the 26.
    $endgroup$
    – Edenia
    Dec 10 '18 at 14:38










  • $begingroup$
    @gt6989b I think you wrote the reverse: the first letter is given by $A[lfloor k/26rfloor]$
    $endgroup$
    – Shubham Johri
    Dec 10 '18 at 14:46



















2












$begingroup$

For the index $n$, the $(lfloor frac{n-1}{26}rfloor+1)^{th}$ letter of the alphabet is the first character, $(nmod26)^{th}$ letter of the alphabet is the second character.






share|cite|improve this answer









$endgroup$













  • $begingroup$
    so for the second, index's reminder of the length of the alphabet. Got it. Really useful, thank you. What is this called though? Didn't know what to search for.
    $endgroup$
    – Edenia
    Dec 10 '18 at 14:12












  • $begingroup$
    It's even nicer with 0-based numbering (and doesn't require the unusual interpretation of $26 bmod 26$ as 26).
    $endgroup$
    – LSpice
    Dec 10 '18 at 14:13











Your Answer





StackExchange.ifUsing("editor", function () {
return StackExchange.using("mathjaxEditing", function () {
StackExchange.MarkdownEditor.creationCallbacks.add(function (editor, postfix) {
StackExchange.mathjaxEditing.prepareWmdForMathJax(editor, postfix, [["$", "$"], ["\\(","\\)"]]);
});
});
}, "mathjax-editing");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "69"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
noCode: true, onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmath.stackexchange.com%2fquestions%2f3033946%2fcalculate-the-characters-from-a-combination%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























2 Answers
2






active

oldest

votes








2 Answers
2






active

oldest

votes









active

oldest

votes






active

oldest

votes









1












$begingroup$

Assuming you have an alphabet A = ['a','b',...'z'] and a permutation list L = ['aa', 'ab', ..., 'az', 'ba', ... , 'zz'], with the first index starting from 1. (BTW the arithmetic would be much cleaner if you start indexing from $0$, like in the C language, for example.)



Then, the permutations come in groups of $26$, so if you are given an index $k$, then




  • the second letter is given by the offset of $k$ in the current 26-long block, so it is $A[(k-1)pmod{26} + 1]$ and

  • the first letter is given by $Aleft[lfloor(k-1)/26rfloor+1right]$.




If you were to number starting with $0$, the formulae become




  • the second letter is given by $A[k pmod{26}]$ and

  • the first letter is given by $Aleft[lfloor k/26rfloorright]$.




Another free update you get with C, for example, is that if you declare int k, d = 26; then k/d computes $lfloor k/d rfloor$ automatically, no extra flooring is needed.





UPDATE



The inversion is simple. If first letter has index $F$ and last has index $L$, the offset is given by





  • $26F + L$ for $0$-based indexing (like C)


  • $26(F+1) + (L+1) = 26F + L + 27$ for $1$-based indexing






share|cite|improve this answer











$endgroup$









  • 1




    $begingroup$
    Haha, I am implementing algorithms in C, bt dubs.
    $endgroup$
    – Edenia
    Dec 10 '18 at 14:17










  • $begingroup$
    @Edenia see updates
    $endgroup$
    – gt6989b
    Dec 10 '18 at 14:20










  • $begingroup$
    Hmm A[pos % 26] doesn't return the correct first character. Afirst[(pos / sz) - 1] and Asecond[pos % sz] works though
    $endgroup$
    – Edenia
    Dec 10 '18 at 14:32












  • $begingroup$
    sz being the 26.
    $endgroup$
    – Edenia
    Dec 10 '18 at 14:38










  • $begingroup$
    @gt6989b I think you wrote the reverse: the first letter is given by $A[lfloor k/26rfloor]$
    $endgroup$
    – Shubham Johri
    Dec 10 '18 at 14:46
















1












$begingroup$

Assuming you have an alphabet A = ['a','b',...'z'] and a permutation list L = ['aa', 'ab', ..., 'az', 'ba', ... , 'zz'], with the first index starting from 1. (BTW the arithmetic would be much cleaner if you start indexing from $0$, like in the C language, for example.)



Then, the permutations come in groups of $26$, so if you are given an index $k$, then




  • the second letter is given by the offset of $k$ in the current 26-long block, so it is $A[(k-1)pmod{26} + 1]$ and

  • the first letter is given by $Aleft[lfloor(k-1)/26rfloor+1right]$.




If you were to number starting with $0$, the formulae become




  • the second letter is given by $A[k pmod{26}]$ and

  • the first letter is given by $Aleft[lfloor k/26rfloorright]$.




Another free update you get with C, for example, is that if you declare int k, d = 26; then k/d computes $lfloor k/d rfloor$ automatically, no extra flooring is needed.





UPDATE



The inversion is simple. If first letter has index $F$ and last has index $L$, the offset is given by





  • $26F + L$ for $0$-based indexing (like C)


  • $26(F+1) + (L+1) = 26F + L + 27$ for $1$-based indexing






share|cite|improve this answer











$endgroup$









  • 1




    $begingroup$
    Haha, I am implementing algorithms in C, bt dubs.
    $endgroup$
    – Edenia
    Dec 10 '18 at 14:17










  • $begingroup$
    @Edenia see updates
    $endgroup$
    – gt6989b
    Dec 10 '18 at 14:20










  • $begingroup$
    Hmm A[pos % 26] doesn't return the correct first character. Afirst[(pos / sz) - 1] and Asecond[pos % sz] works though
    $endgroup$
    – Edenia
    Dec 10 '18 at 14:32












  • $begingroup$
    sz being the 26.
    $endgroup$
    – Edenia
    Dec 10 '18 at 14:38










  • $begingroup$
    @gt6989b I think you wrote the reverse: the first letter is given by $A[lfloor k/26rfloor]$
    $endgroup$
    – Shubham Johri
    Dec 10 '18 at 14:46














1












1








1





$begingroup$

Assuming you have an alphabet A = ['a','b',...'z'] and a permutation list L = ['aa', 'ab', ..., 'az', 'ba', ... , 'zz'], with the first index starting from 1. (BTW the arithmetic would be much cleaner if you start indexing from $0$, like in the C language, for example.)



Then, the permutations come in groups of $26$, so if you are given an index $k$, then




  • the second letter is given by the offset of $k$ in the current 26-long block, so it is $A[(k-1)pmod{26} + 1]$ and

  • the first letter is given by $Aleft[lfloor(k-1)/26rfloor+1right]$.




If you were to number starting with $0$, the formulae become




  • the second letter is given by $A[k pmod{26}]$ and

  • the first letter is given by $Aleft[lfloor k/26rfloorright]$.




Another free update you get with C, for example, is that if you declare int k, d = 26; then k/d computes $lfloor k/d rfloor$ automatically, no extra flooring is needed.





UPDATE



The inversion is simple. If first letter has index $F$ and last has index $L$, the offset is given by





  • $26F + L$ for $0$-based indexing (like C)


  • $26(F+1) + (L+1) = 26F + L + 27$ for $1$-based indexing






share|cite|improve this answer











$endgroup$



Assuming you have an alphabet A = ['a','b',...'z'] and a permutation list L = ['aa', 'ab', ..., 'az', 'ba', ... , 'zz'], with the first index starting from 1. (BTW the arithmetic would be much cleaner if you start indexing from $0$, like in the C language, for example.)



Then, the permutations come in groups of $26$, so if you are given an index $k$, then




  • the second letter is given by the offset of $k$ in the current 26-long block, so it is $A[(k-1)pmod{26} + 1]$ and

  • the first letter is given by $Aleft[lfloor(k-1)/26rfloor+1right]$.




If you were to number starting with $0$, the formulae become




  • the second letter is given by $A[k pmod{26}]$ and

  • the first letter is given by $Aleft[lfloor k/26rfloorright]$.




Another free update you get with C, for example, is that if you declare int k, d = 26; then k/d computes $lfloor k/d rfloor$ automatically, no extra flooring is needed.





UPDATE



The inversion is simple. If first letter has index $F$ and last has index $L$, the offset is given by





  • $26F + L$ for $0$-based indexing (like C)


  • $26(F+1) + (L+1) = 26F + L + 27$ for $1$-based indexing







share|cite|improve this answer














share|cite|improve this answer



share|cite|improve this answer








edited Dec 11 '18 at 4:13

























answered Dec 10 '18 at 14:16









gt6989bgt6989b

33.9k22455




33.9k22455








  • 1




    $begingroup$
    Haha, I am implementing algorithms in C, bt dubs.
    $endgroup$
    – Edenia
    Dec 10 '18 at 14:17










  • $begingroup$
    @Edenia see updates
    $endgroup$
    – gt6989b
    Dec 10 '18 at 14:20










  • $begingroup$
    Hmm A[pos % 26] doesn't return the correct first character. Afirst[(pos / sz) - 1] and Asecond[pos % sz] works though
    $endgroup$
    – Edenia
    Dec 10 '18 at 14:32












  • $begingroup$
    sz being the 26.
    $endgroup$
    – Edenia
    Dec 10 '18 at 14:38










  • $begingroup$
    @gt6989b I think you wrote the reverse: the first letter is given by $A[lfloor k/26rfloor]$
    $endgroup$
    – Shubham Johri
    Dec 10 '18 at 14:46














  • 1




    $begingroup$
    Haha, I am implementing algorithms in C, bt dubs.
    $endgroup$
    – Edenia
    Dec 10 '18 at 14:17










  • $begingroup$
    @Edenia see updates
    $endgroup$
    – gt6989b
    Dec 10 '18 at 14:20










  • $begingroup$
    Hmm A[pos % 26] doesn't return the correct first character. Afirst[(pos / sz) - 1] and Asecond[pos % sz] works though
    $endgroup$
    – Edenia
    Dec 10 '18 at 14:32












  • $begingroup$
    sz being the 26.
    $endgroup$
    – Edenia
    Dec 10 '18 at 14:38










  • $begingroup$
    @gt6989b I think you wrote the reverse: the first letter is given by $A[lfloor k/26rfloor]$
    $endgroup$
    – Shubham Johri
    Dec 10 '18 at 14:46








1




1




$begingroup$
Haha, I am implementing algorithms in C, bt dubs.
$endgroup$
– Edenia
Dec 10 '18 at 14:17




$begingroup$
Haha, I am implementing algorithms in C, bt dubs.
$endgroup$
– Edenia
Dec 10 '18 at 14:17












$begingroup$
@Edenia see updates
$endgroup$
– gt6989b
Dec 10 '18 at 14:20




$begingroup$
@Edenia see updates
$endgroup$
– gt6989b
Dec 10 '18 at 14:20












$begingroup$
Hmm A[pos % 26] doesn't return the correct first character. Afirst[(pos / sz) - 1] and Asecond[pos % sz] works though
$endgroup$
– Edenia
Dec 10 '18 at 14:32






$begingroup$
Hmm A[pos % 26] doesn't return the correct first character. Afirst[(pos / sz) - 1] and Asecond[pos % sz] works though
$endgroup$
– Edenia
Dec 10 '18 at 14:32














$begingroup$
sz being the 26.
$endgroup$
– Edenia
Dec 10 '18 at 14:38




$begingroup$
sz being the 26.
$endgroup$
– Edenia
Dec 10 '18 at 14:38












$begingroup$
@gt6989b I think you wrote the reverse: the first letter is given by $A[lfloor k/26rfloor]$
$endgroup$
– Shubham Johri
Dec 10 '18 at 14:46




$begingroup$
@gt6989b I think you wrote the reverse: the first letter is given by $A[lfloor k/26rfloor]$
$endgroup$
– Shubham Johri
Dec 10 '18 at 14:46











2












$begingroup$

For the index $n$, the $(lfloor frac{n-1}{26}rfloor+1)^{th}$ letter of the alphabet is the first character, $(nmod26)^{th}$ letter of the alphabet is the second character.






share|cite|improve this answer









$endgroup$













  • $begingroup$
    so for the second, index's reminder of the length of the alphabet. Got it. Really useful, thank you. What is this called though? Didn't know what to search for.
    $endgroup$
    – Edenia
    Dec 10 '18 at 14:12












  • $begingroup$
    It's even nicer with 0-based numbering (and doesn't require the unusual interpretation of $26 bmod 26$ as 26).
    $endgroup$
    – LSpice
    Dec 10 '18 at 14:13
















2












$begingroup$

For the index $n$, the $(lfloor frac{n-1}{26}rfloor+1)^{th}$ letter of the alphabet is the first character, $(nmod26)^{th}$ letter of the alphabet is the second character.






share|cite|improve this answer









$endgroup$













  • $begingroup$
    so for the second, index's reminder of the length of the alphabet. Got it. Really useful, thank you. What is this called though? Didn't know what to search for.
    $endgroup$
    – Edenia
    Dec 10 '18 at 14:12












  • $begingroup$
    It's even nicer with 0-based numbering (and doesn't require the unusual interpretation of $26 bmod 26$ as 26).
    $endgroup$
    – LSpice
    Dec 10 '18 at 14:13














2












2








2





$begingroup$

For the index $n$, the $(lfloor frac{n-1}{26}rfloor+1)^{th}$ letter of the alphabet is the first character, $(nmod26)^{th}$ letter of the alphabet is the second character.






share|cite|improve this answer









$endgroup$



For the index $n$, the $(lfloor frac{n-1}{26}rfloor+1)^{th}$ letter of the alphabet is the first character, $(nmod26)^{th}$ letter of the alphabet is the second character.







share|cite|improve this answer












share|cite|improve this answer



share|cite|improve this answer










answered Dec 10 '18 at 14:08









Shubham JohriShubham Johri

4,992717




4,992717












  • $begingroup$
    so for the second, index's reminder of the length of the alphabet. Got it. Really useful, thank you. What is this called though? Didn't know what to search for.
    $endgroup$
    – Edenia
    Dec 10 '18 at 14:12












  • $begingroup$
    It's even nicer with 0-based numbering (and doesn't require the unusual interpretation of $26 bmod 26$ as 26).
    $endgroup$
    – LSpice
    Dec 10 '18 at 14:13


















  • $begingroup$
    so for the second, index's reminder of the length of the alphabet. Got it. Really useful, thank you. What is this called though? Didn't know what to search for.
    $endgroup$
    – Edenia
    Dec 10 '18 at 14:12












  • $begingroup$
    It's even nicer with 0-based numbering (and doesn't require the unusual interpretation of $26 bmod 26$ as 26).
    $endgroup$
    – LSpice
    Dec 10 '18 at 14:13
















$begingroup$
so for the second, index's reminder of the length of the alphabet. Got it. Really useful, thank you. What is this called though? Didn't know what to search for.
$endgroup$
– Edenia
Dec 10 '18 at 14:12






$begingroup$
so for the second, index's reminder of the length of the alphabet. Got it. Really useful, thank you. What is this called though? Didn't know what to search for.
$endgroup$
– Edenia
Dec 10 '18 at 14:12














$begingroup$
It's even nicer with 0-based numbering (and doesn't require the unusual interpretation of $26 bmod 26$ as 26).
$endgroup$
– LSpice
Dec 10 '18 at 14:13




$begingroup$
It's even nicer with 0-based numbering (and doesn't require the unusual interpretation of $26 bmod 26$ as 26).
$endgroup$
– LSpice
Dec 10 '18 at 14:13


















draft saved

draft discarded




















































Thanks for contributing an answer to Mathematics Stack Exchange!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


Use MathJax to format equations. MathJax reference.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmath.stackexchange.com%2fquestions%2f3033946%2fcalculate-the-characters-from-a-combination%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Berounka

Sphinx de Gizeh

Different font size/position of beamer's navigation symbols template's content depending on regular/plain...