Guest User

Untitled

a guest
Oct 16th, 2018
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.85 KB | None | 0 0
  1. object test {
  2.  
  3. @JvmStatic
  4. fun main(args: Array<String>) {
  5. println(from10to43(123))
  6. println(from43to10("2ъ"))
  7. }
  8.  
  9.  
  10. private fun from10to43(number: Int): String {
  11.  
  12. var value = number
  13.  
  14. val result = StringBuilder()
  15.  
  16. while (value % 43 > 0) {
  17. val p = value / 43
  18. val q = mapping[value % 43]
  19.  
  20. result.insert(0, q)
  21.  
  22. if (p < 43) {
  23. result.insert(0, mapping[p])
  24. break
  25. } else value = p
  26. }
  27. return result.toString()
  28. }
  29.  
  30. private fun from43to10(number: String): Int {
  31. var result = 0
  32. for (i in 0 until number.length) {
  33. val digit = mapping.entries.first { it.value == number[i].toString() }.key
  34. result *= 43
  35. result -= digit
  36. }
  37. return -result
  38. }
  39.  
  40. val mapping = mapOf(0 to "0",
  41. 1 to "1",
  42. 2 to "2",
  43. 3 to "3",
  44. 4 to "4",
  45. 5 to "5",
  46. 6 to "6",
  47. 7 to "7",
  48. 8 to "8",
  49. 9 to "9",
  50. 10 to "а",
  51. 11 to "б",
  52. 12 to "в",
  53. 13 to "г",
  54. 14 to "д",
  55. 15 to "е",
  56. 16 to "ё",
  57. 17 to "ж",
  58. 18 to "з",
  59. 19 to "и",
  60. 20 to "й",
  61. 21 to "к",
  62. 22 to "л",
  63. 23 to "м",
  64. 24 to "н",
  65. 25 to "о",
  66. 26 to "п",
  67. 27 to "р",
  68. 28 to "с",
  69. 29 to "т",
  70. 30 to "у",
  71. 31 to "ф",
  72. 32 to "х",
  73. 33 to "ц",
  74. 34 to "ч",
  75. 35 to "ш",
  76. 36 to "щ",
  77. 37 to "ъ",
  78. 38 to "ы",
  79. 39 to "ь",
  80. 40 to "э",
  81. 41 to "ю",
  82. 42 to "я")
  83. }
Add Comment
Please, Sign In to add comment