pharo-smalltalk icon indicating copy to clipboard operation
pharo-smalltalk copied to clipboard

Rectangles solution

Open macta opened this issue 6 years ago • 2 comments

This is quite an interesting problem

macta avatar May 30 '19 23:05 macta

Brute force is quite a valid approach and is the only one I could think of for a while. Then reviewing Array2D >> isLineAt: another concept came to mind...

  1. Generate horizontal line segments and validate pairs as possible rectangle sides
  2. Generate pairs of vertical line segments and validate pairs
  3. Combinatorially compare the two collections

(not advocating you change yours, just sharing)

bencoman avatar May 31 '19 01:05 bencoman

Your comment about generate line segment permutations is exactly what this solution is doing (maybe its a bit more obvious now) - it finds square permutations (based on the + corners), and then validates if they actually exist because they are correctly joined by "-" or "|" lines. (Probably worth saying this very text in the class comment actually)

macta avatar Jun 05 '19 23:06 macta

Solution moved and adopted for v3 in PR: https://github.com/exercism/pharo-smalltalk/pull/661

Bajger avatar Apr 12 '25 16:04 Bajger