A claim is a claim ID + a rectangle.

"If the Elves all proceed with their own plans, none of them will have
enough fabric.

How many square inches of fabric are within two or more claims?" <---
actual question.

units are inches.

So, question translates to:

"What is the total area of rectangle intersections?"

Now you can see it as rectangles or as all measurements are integers,
are cells in a matrix (rasterizing the geometry).

That's the approach I took and it worked well enough.


HTH

Phil






On Tue, Dec 4, 2018 at 11:05 PM Roelof Wobben <r.wob...@home.nl> wrote:

> Thanks I found that out already.
>
> Now trying to understand what they mean with this exactly
>
> If the Elves all proceed with their own plans, none of them will have enough 
> fabric. How many square inches of fabric are within two or more claims?
>
>
> They give some 13000 plans
>
>
> Roelof
>
>
>
>
>
> Op 4-12-2018 om 22:55 schreef Ben Coman:
>
>
>
> On Wed, 5 Dec 2018 at 00:45, Roelof Wobben <r.wob...@home.nl> wrote:
>
>> so like this ?
>>
>> so first the intersect between rectangle1 and rectangle2
>> store it
>> and then the intersection between the stored one and rectangle3
>> and so on
>> then its time to look how I must define a rectangle when I know the
>> starting point and the length and width
>>
>> then it time to figure out how I can define a Rectangle with the starting
>> point the length and the width
>>
>
> Use Spotter to bring up the System Browser on the Rectangle class.
> Then right-click >> Class-refs
> to look at how the class is used directly to create new instances.
>
> cheers -ben
>
>
>
>>
>> Roelof
>>
>>
>>
>> Op 4-12-2018 om 17:27 schreef p...@highoctane.be:
>>
>> Use Rectangle class and intersect: method?
>>
>>
>>
>>
>> On Tue, Dec 4, 2018 at 5:07 PM Roelof Wobben <r.wob...@home.nl> wrote:
>>
>>> 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
>>>
>>>
>>>
>>
>

Reply via email to