Guest User

Untitled

a guest
Dec 25th, 2022
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.49 KB | Source Code | 0 0
  1. import numpy as np
  2.  
  3. puzzle_input = """11-00
  4. 2--2==212=12
  5. 1=0110121=2
  6. 1=012-21-=121
  7. 1==0-1121-=200=2212
  8. 1=1210===00=
  9. 11210021-0001010-
  10. 12=1-10-1-
  11. 212-2==221-210-21
  12. 1=-01=0-02-2-=-222=
  13. 1=022000===-22010
  14. 1=01=12202
  15. 11=
  16. 202-1
  17. 2-12-2=--1
  18. 10-=-00=101=-0-=-0
  19. 1112-1
  20. 2--1201
  21. 1=1==-020=1-
  22. 1--0-=2-0022-
  23. 1=-1-21-200-102=
  24. 11=100021210
  25. 1=2=01=2-=01-=
  26. 1=0120-11-0-=-2=-2
  27. 1=-20221=2=-2=
  28. 1-0
  29. 1=00=-=11100--=2
  30. 22122
  31. 1=102222
  32. 1210=1=001-=000
  33. 1--200102022-=
  34. 102=12=-1==
  35. 100=
  36. 20-02
  37. 10
  38. 10==-102
  39. 11=020-0210-1-2012=
  40. 12-11=0-1-=
  41. 20=-
  42. 212=1-1-10
  43. 1=20=1-=2-11=0
  44. 1=22
  45. 120=2202=12200
  46. 1-0-1
  47. 211011-11=
  48. 2=120=--==0==--0-0
  49. 110-0-=-10-1-112
  50. 1=2=1-=1-2
  51. 1=12==10
  52. 10=2110
  53. 22222-1=01-1
  54. 111-=2=22-==-00
  55. 10===2-2=21100-1=
  56. 100-21-0-1=021
  57. 2-21=0
  58. 1===002012=2=-1121
  59. 122222-101=1-==2-2=
  60. 112=0
  61. 2--212=0
  62. 110--2-0022--01=-
  63. 1-0-0=0-1011-2-=0--2
  64. 1=--0-2=1
  65. 2=
  66. 1=1
  67. 1022=1--2---120
  68. 2-1=2-22--21=1-212
  69. 22=-11-0=-1
  70. 2==210022=
  71. 11=000=002-2002-1=
  72. 2-2=02=0
  73. 1=00-=----=
  74. 1=121-2
  75. 12-2=2-=2=2022
  76. 2=110=1=2=02
  77. 2
  78. 1=0--02-121
  79. 1200-2000=0
  80. 1==--021--2=-
  81. 12-1=22=-02--2-
  82. 1=1=1--121-1221
  83. 2-0212=
  84. 21-==0-201-
  85. 20212=1
  86. 111--
  87. 22-2=-1
  88. 112
  89. 2=2-==101
  90. 1-=1
  91. 12211=010=-=10--
  92. 2211
  93. 21-110-1-22==-10
  94. 121-1-
  95. 22000=-=2-0=012
  96. 212-02
  97. 102
  98. 2-110=11=--
  99. 11=11===0
  100. 1=210-0120
  101. 1=--1011
  102. 2=00022==21-1=-2
  103. 21=1-==2---2=0-2
  104. 1220-11=022122
  105. 21210=01
  106. 1==1-2
  107. 2=2
  108. 11-11122=-
  109. 200-0=21202-=
  110. 2=-11
  111. 2==2=0=1120221
  112. 101010
  113. 1=2=-=--=-2-0=
  114. 111=0=--
  115. 1=0121-=2
  116. 1==1=1
  117. 2-0222=2=-
  118. 12=
  119. 10-=0-2"""
  120.  
  121. puzzle_input_example = """1=-0-2
  122. 12111
  123. 2=0=
  124. 21
  125. 2=01
  126. 111
  127. 20012
  128. 112
  129. 1=-1=
  130. 1-12
  131. 12
  132. 1=
  133. 122"""
  134.  
  135. char_decoded = {"=" : -2, "-" : -1, "0" : 0, "1" : 1, "2" : 2}
  136. char_encoded = {-2 : "=", -1 : "-", 0 : "0", 1 : "1", 2 : "2"}
  137.  
  138. def decode_string(string):
  139.     result = 0
  140.     string = string[::-1]
  141.     for index in range(len(string)):
  142.         result += char_decoded[string[index]] * 5 ** index
  143.     return result
  144.  
  145. def encode_int(value):
  146.     result = ""
  147.     if value == 0:
  148.         result = "0"
  149.     else:
  150.         while value > 0:
  151.             remainder = value % 5
  152.             if remainder > 2:
  153.                 remainder -= 5
  154.             result = char_encoded[remainder] + result
  155.             value = (value - remainder) // 5
  156.     return result
  157.  
  158. lines = puzzle_input.split("\n")
  159. decoded_values = []
  160. for line in lines:
  161.     decoded_values.append(decode_string(line))
  162.  
  163. print("Decoded values:",decoded_values)
  164. print("Sum of decoded values:",sum(decoded_values))
  165. print("Encoded sum:",encode_int(sum(decoded_values)))
  166.  
Advertisement
Add Comment
Please, Sign In to add comment