# Re: histogram question

```
"Bill B." <billb@attinet.com> wrote in message
> > how can you turn the former into the latter without a loop?  This is
> > somewhat similar to Pavel's running chunk index problem earlier in the
> > year.  Finding an answer is not trivial.  It would apply directly to
> > this problem, where the pairs are adjacent elements in the reverse
> > indices vector.   Any takers?
> >
>
> I've encountered a few areas where certain logic problems cannot be
> solved without a loop in IDL.  Usually, this always points to the fact
> that there are certain IDL functions that (logically) insist upon
> scalar parameters.
>
> -Bill B.
>

Okay, here's an effort using two histograms instead of one, just to
get some interest going.  No visible loops, but not the sort of
stuff you put in production code.  With this as a head start, let's
see the single-histogram approach.

A = [-1,3,7,12,15,18,20,20] ;The solution must work with negative and
repeating numbers
NPair = N_Elements(A)/2
MaxA = Max(A, Min = MinA)
D = MaxA - MinA
P = Lindgen(NPair)*2
H1 = Histogram(A[P], Max = MaxA, Min = MinA, R = R1)
H2 = Histogram(A[P + 1], Max = MaxA, Min = MinA, R = R2)
x1 = (R1 - MaxA)[0:D]
x2 = (R2 - MaxA)[0:D]
C = [A, ((x1 ne x2)*(Lindgen(D + 1) + MinA) > MinA) < MaxA]
C = C[Sort(C)]
C = C[Uniq(C)]
Print, C

; Loop version

B = Indgen(NPair)*2
For I = 0L, NPair - 1 Do Print, A[B[I]] + Lindgen(A[B[I] + 1]- A[B[I]] + 1)

Extra credit for minimal use of "[]" notation.

Jim P.

```