Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import numpy as np
- puzzle_input = """11-00
- 2--2==212=12
- 1=0110121=2
- 1=012-21-=121
- 1==0-1121-=200=2212
- 1=1210===00=
- 11210021-0001010-
- 12=1-10-1-
- 212-2==221-210-21
- 1=-01=0-02-2-=-222=
- 1=022000===-22010
- 1=01=12202
- 11=
- 202-1
- 2-12-2=--1
- 10-=-00=101=-0-=-0
- 1112-1
- 2--1201
- 1=1==-020=1-
- 1--0-=2-0022-
- 1=-1-21-200-102=
- 11=100021210
- 1=2=01=2-=01-=
- 1=0120-11-0-=-2=-2
- 1=-20221=2=-2=
- 1-0
- 1=00=-=11100--=2
- 22122
- 1=102222
- 1210=1=001-=000
- 1--200102022-=
- 102=12=-1==
- 100=
- 20-02
- 10
- 10==-102
- 11=020-0210-1-2012=
- 12-11=0-1-=
- 20=-
- 212=1-1-10
- 1=20=1-=2-11=0
- 1=22
- 120=2202=12200
- 1-0-1
- 211011-11=
- 2=120=--==0==--0-0
- 110-0-=-10-1-112
- 1=2=1-=1-2
- 1=12==10
- 10=2110
- 22222-1=01-1
- 111-=2=22-==-00
- 10===2-2=21100-1=
- 100-21-0-1=021
- 2-21=0
- 1===002012=2=-1121
- 122222-101=1-==2-2=
- 112=0
- 2--212=0
- 110--2-0022--01=-
- 1-0-0=0-1011-2-=0--2
- 1=--0-2=1
- 2=
- 1=1
- 1022=1--2---120
- 2-1=2-22--21=1-212
- 22=-11-0=-1
- 2==210022=
- 11=000=002-2002-1=
- 2-2=02=0
- 1=00-=----=
- 1=121-2
- 12-2=2-=2=2022
- 2=110=1=2=02
- 2
- 1=0--02-121
- 1200-2000=0
- 1==--021--2=-
- 12-1=22=-02--2-
- 1=1=1--121-1221
- 2-0212=
- 21-==0-201-
- 20212=1
- 111--
- 22-2=-1
- 112
- 2=2-==101
- 1-=1
- 12211=010=-=10--
- 2211
- 21-110-1-22==-10
- 121-1-
- 22000=-=2-0=012
- 212-02
- 102
- 2-110=11=--
- 11=11===0
- 1=210-0120
- 1=--1011
- 2=00022==21-1=-2
- 21=1-==2---2=0-2
- 1220-11=022122
- 21210=01
- 1==1-2
- 2=2
- 11-11122=-
- 200-0=21202-=
- 2=-11
- 2==2=0=1120221
- 101010
- 1=2=-=--=-2-0=
- 111=0=--
- 1=0121-=2
- 1==1=1
- 2-0222=2=-
- 12=
- 10-=0-2"""
- puzzle_input_example = """1=-0-2
- 12111
- 2=0=
- 21
- 2=01
- 111
- 20012
- 112
- 1=-1=
- 1-12
- 12
- 1=
- 122"""
- char_decoded = {"=" : -2, "-" : -1, "0" : 0, "1" : 1, "2" : 2}
- char_encoded = {-2 : "=", -1 : "-", 0 : "0", 1 : "1", 2 : "2"}
- def decode_string(string):
- result = 0
- string = string[::-1]
- for index in range(len(string)):
- result += char_decoded[string[index]] * 5 ** index
- return result
- def encode_int(value):
- result = ""
- if value == 0:
- result = "0"
- else:
- while value > 0:
- remainder = value % 5
- if remainder > 2:
- remainder -= 5
- result = char_encoded[remainder] + result
- value = (value - remainder) // 5
- return result
- lines = puzzle_input.split("\n")
- decoded_values = []
- for line in lines:
- decoded_values.append(decode_string(line))
- print("Decoded values:",decoded_values)
- print("Sum of decoded values:",sum(decoded_values))
- print("Encoded sum:",encode_int(sum(decoded_values)))
Advertisement
Add Comment
Please, Sign In to add comment