Hello,
For adventofCode I had to write some code that calculates the
overlap that multiple rectangles have.
Fo far I have it working for 1 rectangle but I do not like the code
because of the nested loops.
Can I make this more the pharo way
Code so far :
| item coordinates area overlap regexp line beginX endX beginY endY|
area := OrderedCollection new.
overlap := OrderedCollection new.
regexp := '\#(\d+) @ (\d+),(\d+)\: (\d+)x(\d+)' asRegex.
line := '#1 @ 1,3: 4x4'.
(regexp matches: line)
ifTrue: [
beginX := (regexp subexpression: 2) asInteger + 1.
endX := (regexp subexpression: 5) asInteger + beginX .
beginY := (regexp subexpression: 4) asInteger + 1.
endY := (regexp subexpression: 6) asInteger + beginY.
beginX to: (endX - 1) do: [:a |
beginY to: (endY -1) do: [:b |
item := a asString , '*' , b asString .
(area includes: item)
ifTrue: [ overlap add: item ]
ifFalse: [ area add: item ]]]] .
^ area.
Thanks,
Roelof