Skip to content

Instantly share code, notes, and snippets.

@0racle
Created April 5, 2022 03:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save 0racle/53101975f0974a2664c2ddbfd4b6a96f to your computer and use it in GitHub Desktop.
Save 0racle/53101975f0974a2664c2ddbfd4b6a96f to your computer and use it in GitHub Desktop.
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