Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- List := StrSplit(FileOpen("day14_input.txt","R").Read(),"`r`n")
- memory := []
- for k, v in List {
- if InStr(v,"mask")
- mask := StrSplit(SubStr(v,8))
- else {
- s := ""
- RegexMatch(v,"O)mem\[(\d+)\] = (\d+)$",o)
- for location, bit in StrSplit(Format("{:036}",Bin(o[1]))) {
- t := mask[location]
- s .= (t == "X")?"X":(bit || t)
- }
- ;memory[o[1]] := s
- GetAddresses(L := [],s)
- for a, b in L
- memory[Dec(b)] := o[2]
- }
- }
- sum := 0
- for k, v in memory
- sum += v
- msgbox % clipboard := sum
- GetAddresses(List, address) {
- if !InStr(address,"X")
- List.push(address)
- else {
- GetAddresses(List,StrReplace(address, "X", 1,, 1))
- GetAddresses(List,StrReplace(address, "X", 0,, 1))
- }
- }
- Bin(x) {
- while x
- r:=1&x r,x>>=1
- return r
- }
- Dec(x) {
- b:=StrLen(x),r:=0
- loop,parse,x
- r|=A_LoopField<<--b
- return r
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement