Advertisement
musifter

AoC 2022, day 3, part 2 (smalltalk)

Dec 3rd, 2022 (edited)
2,701
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Smalltalk 0.59 KB | Source Code | 0 0
  1. #!/usr/local/bin/gst -q
  2.  
  3. Collection extend [
  4.     apply: method [ ^self collect: [:x | x perform: method] ]
  5. ]
  6.  
  7. Character extend [
  8.     " XXX: assuming only letters "
  9.     priority [
  10.         ^self isLowercase ifTrue:  [ self asInteger - 96 ]
  11.                           ifFalse: [ self asInteger - 38 ]  " - 64 + 26 "
  12.     ]
  13. ]
  14.  
  15. "
  16. | Mainline
  17. "
  18. part2 := 0.
  19.  
  20. sacks := ReadStream on: (stdin contents lines apply: #asSet).
  21.  
  22. [ sacks atEnd ] whileFalse: [
  23.     badge := (sacks next: 3) fold: [:a :b | a & b].
  24.     part2 := part2 + badge anyOne priority
  25. ].
  26.  
  27. ('Part 2: %1' % {part2}) displayNl.
  28.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement