Well,  here's a fairly inelegant, simplistic, and probably inefficient attempt,  which does match
Henry Rich's on the data as originally sorted.
HOWEVER, your remark about the intervals starting 1732, namely 1732 1733 and 1732 1803, led me to wonder whether the data should be reordered so that 1732 1733 follows 1732 1803,
ie should the second column be decreasing withing increasing first column?
If I reorder the data with this requirement,  my approach removes five more intervals than Henry's! Perhaps that is because I retabulate the interval-comparisons after each round of removals:

NB. (re)sort so that finish-weeks decrease within equal start-weeks
   std =: (|@/:~@:(1 _1 *"1 ])) td

   std (-.@-:"1 # ,.) td   NB. note where these two lists differ
1732 1803 1732 1733
1732 1733 1732 1803

slef =: (<:/ * >/~@:(i.@#)@])   NB. tabulate week-starts less than equal previous week-finishes ctslef =: +/"1@slef             NB. count number of overlaps with previous intervals


richdelete =: 3 : 0    NB. Rich's approach rendered as a function
NB. ensure sorted
NB. td       =. /:~ y          NB. NOT SORTING HERE FOR COMPARISON PURPOSES
NB. compact the labeling (not required)
canonize =. (i.~ ~.@(/:~)@,) td
NB. One row per event/input pair
events   =. (i.#canonize) ;@:(<@(,.~ ([ + i.@>:@(-~))/)"_1) canonize
NB. For each event, remove previous deletes, accum new ones
deletions=. (] , 4 }. -.)&.>/ a: ,~ |. </./ |: events
NB. remove supernumeraries
deletions; (<<deletions) { td
)
   # ntd  =: (#~"1 -.@(</\)@:(3 < ctslef /))^:_ &.:|: td NB. number of kept rows, original input
53
   #nstd  =: (#~"1 -.@(</\)@:(3 < ctslef /))^:_ &.:|:std NB. size for (re)sorted input
48
' deletions  remains' =:  richdelete  td     NB. H Rich on un(re)sorted
'sdeletions sremains' =:  richdelete std   NB. H Rich on (re)sorted input
   remains -: ntd  NB. same results on unREsorted data
1
   sremains (-.; -.~) nstd  NB. BUT different for the (re)sorted data ....
+---------+---------+
|1732 1733|1732 1803|
|1734 1742|1807 1811|
|1744 1746|1813 1816|
|1749 1750|1820 1911|
|1803 1820|         |
|1824 1838|         |
|1841 1842|         |
|1843 1846|         |
|1848 1907|         |
+---------+---------+

I don't know which you prefer as input - it seems either would be acceptable - and wonder why my results differ from Henry's when the data are sorted descending/ascending on the two columns ...
Mike


On 02/04/2019 19:30, R.E. Boss wrote:
Your solution is the only one which is correct.
Miller and I did not discover the two intervals starting in the same week 
(1732).
If I amended my verb 'check' to
check=: [:> (4 :('t=.4<: 1+/@:>: y I."1 {.x';'if. t do. y else. x,y end.'))&.>/    
NB. with >:  instead of =
I get
    (((<<deletions) { ]) -: check@init&.|.)td
1
Thanks for the different approach, but I should have discovered the error myself, or better still, prevented it.


R.E. Boss


-----Oorspronkelijk bericht-----
Van: Programming <[email protected]>
Namens Henry Rich
Verzonden: dinsdag 2 april 2019 09:41
Aan: [email protected]
Onderwerp: Re: [Jprogramming] Max 4 overlapping intervals.

td =: /:~ td   NB. ensure sorted

canonize =. (i.~ ~.@(/:~)@,) td  NB. compact the labeling (not required)

events =. (i.#canonize) ;@:(<@(,.~ ([ + i.@>:@(-~))/)"_1) canonize   NB.
One row per event/input pair

deletions =. (] , 4 }. -.)&.>/ a: ,~ |. </./ |: events  NB. For each event, 
remove
previous deletes, accum new ones

(<<deletions) { td  NB. remove supernumeraries

1643 1646

1644 1646

1645 1650

1646 1650

...


Henry Rich

On 4/1/2019 1:41 PM, R.E. Boss wrote:
Yes, because in the result 1650 1711 was omitted first, so 1701 1707 could
stay.
BTW, the remark of Mike Day was correct.


R.E. Boss


-----Oorspronkelijk bericht-----
Van: Programming <[email protected]>
Namens Henry Rich
Verzonden: maandag 1 april 2019 18:41
Aan: [email protected]
Onderwerp: Re: [Jprogramming] Max 4 overlapping intervals.

Wait a minute... 1701 1707 overlaps 4 previous intervals, but you
left it in your result.

Henry Rich

On 4/1/2019 6:18 AM, R.E. Boss wrote:
Given a series of intervals of weeks, given by the begin week up to
and
including the end week, each week denoted by yyww, with yy last two
digits of year and ww the weeknumber.
+---------+---------+---------+---------+---------+
|1643 1646|1715 1720|1743 1750|1814 1824|1840 1907|
|1644 1646|1716 1720|1744 1746|1815 1816|1841 1842|
|1645 1650|1718 1724|1745 1750|1816 1820|1842 1846|
|1646 1650|1719 1724|1746 1749|1817 1820|1843 1846|
|1648 1703|1721 1737|1748 1803|1818 1824|1844 1846|
|1649 1729|1724 1729|1749 1750|1820 1911|1845 1846|
|1650 1711|1725 1737|1750 1820|1821 1824|1846 1851|
|1651 1707|1726 1729|1751 1803|1824 1838|1848 1907|
|1701 1707|1727 1729|1801 1803|1825 1829|1851 1903|
|1702 1707|1729 1742|1803 1820|1826 1829|1901 1903|
|1703 1707|1730 1737|1804 1816|1827 1829|1902 1903|
|1706 1711|1732 1733|1805 1824|1828 1838|1907 1911|
|1707 1711|1732 1803|1806 1807|1829 1833|1908 1911|
|1708 1711|1733 1746|1807 1811|1830 1833|1911 1916|
|1709 1720|1734 1742|1808 1811|1831 1833|         |
|1710 1737|1736 1746|1809 1811|1832 1833|         |
|1711 1724|1737 1742|1810 1811|1833 1838|         |
|1712 1720|1738 1742|1811 1911|1834 1838|         |
|1713 1724|1741 1746|1812 1816|1838 1907|         |
|1714 1716|1742 1750|1813 1816|1839 1907|         |
+---------+---------+---------+---------+---------+

Question: starting with the first interval I want all intervals
removed which
overlap 4 or more previous intervals, like the 7th interval 1650 1711 does.
Looplessness required, elegance preferred.

My solution, which I hope is correct, is
+---------+---------+---------+
|1643 1646|1741 1746|1830 1833|
|1644 1646|1742 1750|1831 1833|
|1645 1650|1743 1750|1832 1833|
|1646 1650|1748 1803|1834 1838|
|1648 1703|1751 1803|1838 1907|
|1649 1729|1801 1803|1839 1907|
|1651 1707|1804 1816|1840 1907|
|1701 1707|1805 1824|1908 1911|
|1706 1711|1806 1807|1911 1916|
|1708 1711|1807 1811|         |
|1709 1720|1808 1811|         |
|1712 1720|1812 1816|         |
|1713 1724|1813 1816|         |
|1721 1737|1817 1820|         |
|1724 1729|1818 1824|         |
|1725 1737|1820 1911|         |
|1730 1737|1821 1824|         |
|1732 1733|1825 1829|         |
|1732 1803|1826 1829|         |
|1738 1742|1827 1829|         |
+---------+---------+---------+


R.E. Boss
--------------------------------------------------------------------
--
For information about J forums see
http://www.jsoftware.com/forums.htm


---
This email has been checked for viruses by AVG.
https://www.avg.com

---------------------------------------------------------------------
- For information about J forums see
http://www.jsoftware.com/forums.htm
----------------------------------------------------------------------
For information about J forums see
http://www.jsoftware.com/forums.htm

----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

---
This email has been checked for viruses by Avast antivirus software.
https://www.avast.com/antivirus

----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to