Guest User

Untitled

a guest
Dec 14th, 2020
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. List := StrSplit(FileOpen("day14_input.txt","R").Read(),"`r`n")
  2.  
  3. memory := []
  4. for k, v in List {
  5.     if InStr(v,"mask")
  6.         mask := StrSplit(SubStr(v,8))
  7.     else {
  8.         s := ""
  9.         RegexMatch(v,"O)mem\[(\d+)\] = (\d+)$",o)
  10.         for location, bit in StrSplit(Format("{:036}",Bin(o[2]))) {
  11.             t := mask[location]
  12.             s .= (bit != t && t != "X")?(t):(bit)
  13.         }
  14.         memory[o[1]] := s
  15.     }
  16. }
  17.  
  18. sum := 0
  19. for k, v in memory
  20.     sum += Dec(v)
  21.  
  22. msgbox % clipboard := sum
  23.  
  24. Bin(x) {
  25.     while x
  26.         r:=1&x r,x>>=1
  27.     return r
  28. }
  29.  
  30. Dec(x) {
  31.     b:=StrLen(x),r:=0
  32.     loop,parse,x
  33.         r|=A_LoopField<<--b
  34.     return r
  35. }
Advertisement
Add Comment
Please, Sign In to add comment