Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- SetWorkingDir %A_ScriptDir%
- FileRead, instStr, % A_ScriptDir "\d14.txt"
- instA := StrSplit(instStr, "mask = ")
- instA.RemoveAt(1)
- for i, j in instA {
- instA[i] := StrSplit(j, "`r`n")
- for k, l in instA[i] {
- if (SubStr(l, 1, 3) = "mem") and (l != "") {
- ta := StrSplit(l, "] = ")
- instA[i][k] := [SubStr(ta[1], 5), ta[2]]
- }
- }
- instA[i].Pop()
- }
- memory := {}
- for i, j in instA {
- for k, l in j {
- if (k = 1)
- Continue
- binAddress := Bin(l[1])
- outStr := ApplyMask(j[1], binAddress)
- AddressA := process([outStr])
- for m, n in AddressA {
- memory[Dec(n)] := l[2]
- }
- }
- }
- sum := 0
- for i, j in memory {
- sum += j
- }
- Clipboard := sum
- process(a) {
- noX := 0
- b := []
- for i, j in a {
- if !InStr(j, "X") {
- noX += 1
- }
- if (noX = a.MaxIndex())
- Return a
- arr := StrSplit(j, "X",, 2)
- b.Push(arr[1] 0 arr[2])
- b.Push(arr[1] 1 arr[2])
- }
- Return process(b)
- }
- ApplyMask(mask, bin) {
- maskA := StrSplit(mask)
- Loop, % maskA.MaxIndex() - StrLen(bin)
- {
- bin := "0" bin
- }
- valA := StrSplit(bin)
- for m, n in valA {
- if (maskA[m] = 1)
- valA[m] := 1
- else if (maskA[m] = "X") {
- valA[m] := "X"
- }
- }
- outStr := ""
- for m, n in valA {
- outStr .= n
- }
- Return outStr
- }
- Bin(x){
- return (x>>1 ? Bin(x>>1):"")x&1
- }
- Dec(x){
- return (StrLen(x)>1 ? Dec(SubStr(x,1,-1))<<1:0)|SubStr(x,0)
- }
Add Comment
Please, Sign In to add comment