Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/local/bin/gst -q
- String extend [
- asRadix: rad [
- ^Number readFrom: (ReadStream on: self) radix: rad.
- ]
- ]
- memory := LookupTable new.
- or_mask := 0.
- and_mask := 0.
- ((stdin contents tokenize: 'mask = ') reject: [:a | a size = 0]) do: [ :block |
- cmds := (block tokenize: '\n') asOrderedCollection.
- mask := cmds removeFirst.
- or_mask := (mask copyReplaceAll: 'X' with: '0') asRadix: 2.
- and_mask := (mask copyReplaceAll: 'X' with: '1') asRadix: 2.
- cmds do: [ :set |
- pair := set subStrings: 'mem[] ='.
- val := ((pair second) asNumber bitOr: or_mask) bitAnd: and_mask.
- memory at: (pair first) put: val.
- ].
- ].
- ('Part 1: ', (memory fold: [ :a :b | a + b ]) asString) displayNl.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement