Created
April 5, 2022 03:09
-
-
Save 0racle/53101975f0974a2664c2ddbfd4b6a96f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
my %ops = (AND => &[+&], OR => &[+|], LSHIFT => &[+<], RSHIFT => &[+>]); | |
my (%cct, %mem); | |
my &get = -> \val { %mem{val} //= +val // %cct{val}() } | |
for $=finish.lines { | |
given .words { | |
when 3 { %cct{.[2]} = { get(.[0]) } } | |
when 4 { %cct{.[3]} = { +^get(.[1]) +& 0xFFFF } } | |
when 5 { %cct{.[4]} = { %ops{.[1]}(get(.[0]), get(.[2])) } } | |
} | |
} | |
put %cct<d>(); | |
=finish | |
123 -> x | |
456 -> y | |
x AND y -> d | |
x OR y -> e | |
x LSHIFT 2 -> f | |
y RSHIFT 2 -> g | |
NOT x -> h | |
NOT y -> i |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment