I am solving AoC 2015 and I came across this task: Day 7 - Advent of Code 2015
After implementing token parsing and evaluation I realized that the these operations are not in order. It looks like I need something like a lazy hashtable. Here's what I mean:
--- FIND `b`:---
/* (`->` means "assign to")
!a -> b
table[b] = !table[a] // table[a] isn't defined yet
c || d -> e
table[e] = table[c] & table[d]
e << 2 -> a
table[a] = table[e] << 2
10 -> e
table[e] = 10 // now since table[e] is defined, I can find table[a] and thus the value of b
If I use a HashTable<&str, i32>
, it'll immidiately complain that the value of table[a]
wasn't defined yet. If I use a HashTable<&str, Option<i32>>
and None
, when I change the value of e
, the HashTable should transitively change the value of a
thus b
.
How should I approach this?