[Ruby] 3 lines. Intuitive + math solution with system of linear equations
Algorithm\n\nSearch an answer in a form aa...aa[LETTER]zz...zz\nNumeric Value of that string is a number of a chars * 1 + number of z chars * 26 + value of LETT
# Algorithm\n\nSearch an answer in a form `aa...aa[LETTER]zz...zz`\nNumeric Value of that string is a number of `a` chars * 1 + number of `z` chars * 26 + value of `LETTER`.\n\nMin value of a string of len `n`  is `n` for string `aa...aaa`.\nAfter decreasing needed sum (value of string result) by n count of `z` is `s / 25` (how many times 25 points fits in remaining value).\n\n```ruby\nCHARS = (1..26).zip(\'a\'..\'z\').to_h\ndef get_smallest_string(n, s) # k is a sum\n  s -= n\n  z, r = s.divmod(25) # s = 25*z + r\n  return \'z\'*z if z == n\n  \'a\'*(n-z-1) + CHARS[r+1] + \'z\'*z\nend\n```\n\n# Explicit math way to obtain the same solution\nSearch an answer in a form `aa...aa[LETTER]zz...zz` . `LETTER` is a character in a range `a..z`.\nNumeric Value of that string is a number of `a` chars * 1 + number of `z` chars * 26 + value of `LETTER`.\nLet `a` is a number of letters `a`, `z` is a number of letters `z`.\nCompose a system of linear equations:\n\n**\u23B0 a + z = n - 1** *(1)* , where `a >= 0`, `z >= 0`\n**\u23B1 a + l + 26z = s** *(2)*, where`1 \u2264 l \u2264 26`.\n\nfrom *(1)*:  **a = n - z - 1**, where `z <= n - 1`\nthen put this into *(2)*: &nbsp;**n-z-1+l+26z = s** &nbsp;&nbsp;&nbsp;*=>*&nbsp;&nbsp;&nbsp; **l-1+25z = s-n**  &nbsp;&nbsp;&nbsp;*=>*&nbsp;&nbsp;&nbsp;   **l-1 = (s-n)%25**, &nbsp;**z = (s-n)/25** (unless z == n)\n\n```\ndef get_smallest_string(n, s)\n  z, r = (s-n).divmod(25)\n  return \'z\'*z if z == n\n  \'a\'*(n-z-1) + (97+r).chr + \'z\'*z\nend\n```
['Math', 'Ruby']