Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Rosetta: Range extraction

16 views
Skip to first unread message

Robert L.

unread,
Apr 24, 2017, 4:13:30 AM4/24/17
to
list = [0, 1, 2, 4, 6, 7, 8, 11, 12, 14,
15, 16, 17, 18, 19, 20, 21, 22, 23, 24,
25, 27, 28, 29, 30, 31, 32, 33, 35, 36,
37, 38, 39]

old = list[0]
list.slice_before{|n| [n-old>1,old=n][0]}.
map{|a| a.size<3 ? a.join(",") : [a[0],a[-1]].join("-")}.
join ","

===>
"0-2,4,6-8,11,12,14-25,27-33,35-39"

In Forth?


--
[A]n unholy alliance of leftists, capitalists, and Zionist supremacists has
schemed to promote immigration and miscegenation with the deliberate aim of
breeding us out of existence in our own homelands.... [T]he real aim stays the
same: the biggest genocide in human history.... --- Nick Griffin
(https://www.youtube.com/watch?v=K0hD7IffTJs)
0 new messages