Find and Filter Data in Adjacent Intervals

The adjacent interval refers to the interval formed by other members around a member.

Examples

Example1

There is a sequence of numbers, and the task is to find the first odd number after the number 10.

 

Write SPL script:


A

1

[10,2,4,3,10,3,8,7,10,8,3,10,6,4,7]

2

=A1.(if(~==10,~[1:].select@1(~%2==1)))

3

=A2.select(~)

 

A1 Number sequence

 

A2 Loop through each number of A1 and calculate: if the current number is 10, select the first odd number from the numbers after it. Among them, ~[1:] represents the sequence consisting of the next of the current number to the last number, and the @1 option means to select the first number that meets the condition. If the current number is not 10, then return null

 

A3 Select the number that is not null in A2

 

Example2

There is a sequence of numbers 1 and 2. The task is to count how many 2s there are after the first 1.

 

Write SPL script:


A

1

[2,2,1,1,2,1,1,2,2]

2

=A1.to(A1.pselect(~==1),).count(~==2)

 

A1 Number sequence

 

A2 Count the number of 2 after the first 1. A1.pselect (~==1) is used to select the sequence number of the first 1, and the to function selects the numbers from this sequence number to the end of the A1 sequence.