Advertisement
musifter

AoC 2021 day 6 (smalltalk)

Dec 5th, 2021
1,878
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/usr/local/bin/gst -q
  2.  
  3. Collection extend [
  4.     apply: method  [ ^self collect: [:x | x perform: method] ]
  5. ]
  6.  
  7. fish := Bag from: ((stdin nextLine substrings: $,) apply: #asNumber).
  8.  
  9. (1 to: 256) do: [ :t |
  10.     next := Bag new.
  11.  
  12.     fish contents associations do: [ :group |
  13.        | age |
  14.         age := group key.
  15.         (age = 0) ifTrue: [
  16.             age := 7.
  17.             next add: 8 withOccurrences: group value.
  18.         ].
  19.  
  20.         next add: (age - 1) withOccurrences: group value.
  21.     ].
  22.  
  23.     fish := next.
  24.     (t = 80) ifTrue: [ ('Part 1: %1' % {fish size}) displayNl ]
  25. ].
  26.  
  27. ('Part 2: %1' % {fish size}) displayNl.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement