For my comeback to PerlMonks forum, I have an intriguing math problem. I am looking for an efficient way to partition my coordinate system (x,y) into squares. Example:
Let the square be annotated as a tuple (x,y,s) where x and y are the start coordinates and s is its length. So the first one would be (1,1,3). The thing is that x in the above coordinate marks the beginning of another square so the initiall one cannot be extended over it. The squares cannot overlap and cannot include the next "x" point (in the above graph). Furthermore, the one starting at x=1, y=4 is (1,4,1) and the one at x=3, y=4 is (3,4,2). Also the one starting at x=8, y=7 is (8,7,1) -> the point itself.0 1 2 3 4 5 6 7 8 9 0 1 2 1 2 x 3 x 4 x 5 x 6 x 7 x x 8 x 9 x x 0 x 1 x x 2
Am I making any sense ?
I need to know how many of these squares are in the space and all their coordinates (tuples). Initially I thought this would be an easy task but it seams it is not... any help on how to compute this would be much appreciated.
Thank you !! :)
PS
Code is not so relevant as i will code it once the key ingredient is there and we can optimize it later. But what bugs me is the wrapping my head around the partitioning of the space. UPDATE:
I just hope i did not missfilled.... so any square that had an x initially now is a starting point to be filled. filling is done left to right and up -> down (sorry for being unclear ) and sorry for reusing the letters when fillingOriginal 0 1 2 3 4 5 6 7 8 9 0 1 2 1 2 x 3 x 4 x 5 x 6 x 7 x x 8 x 9 x x 0 x 1 x x 2 filled (almost) 0 1 2 3 4 5 6 7 8 9 0 1 2 1 o o o i i i u u g t a k 2 o o o i i i u u z m m m 3 o o o i i i p p p m m m 4 a b j j l l p p p m m m 5 n h j j l l p p p w w b 6 k k s s y y y h k w w c 7 k k s s y y y l n n q q 8 d d u f y y y v n n q q 9 d d p x 0 g u j ... 1 o i i x 2 z i i result: (1,1,3) (4,1,3) (7,1,2) (9,1,1) (10,1,1) (11,1,1) (12,1,1) (7,3,3) (9,2,1) (10,2,3) ...
In reply to Tricky math problem ... by baxy77bax
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |