Maximum difference between adjacent elements of list: Difference between revisions
Content added Content deleted
(→OCaml: add) |
|||
Line 1,056: | Line 1,056: | ||
10,3 ==> 7 |
10,3 ==> 7 |
||
done... |
done... |
||
</pre> |
|||
=={{header|RPL}}== |
|||
{{works with|Halcyon Calc|4.2.7}} |
|||
{| class="wikitable" |
|||
! Code |
|||
! Comments |
|||
|- |
|||
| |
|||
≪ DUP SIZE 0 → list len max |
|||
≪ 2 len '''FOR''' j |
|||
list j 1 - GET list j GET - ABS |
|||
'''IF''' max OVER < '''THEN''' 'max' STO |
|||
'''ELSE''' DROP '''END''' |
|||
'''NEXT''' |
|||
{} max + |
|||
2 len '''FOR''' j |
|||
list j 1 - GET list j GET |
|||
'''IF''' DUP2 - ABS max == '''THEN''' R→C + |
|||
'''ELSE''' DROP2 '''END''' |
|||
'''NEXT''' |
|||
≫ ≫ 'ADJMAX' STO |
|||
| |
|||
( {list} -- { max ( adjacent couples) } |
|||
Scan input list... |
|||
... calculate adjacent gap |
|||
... and store max value |
|||
Initialize output list |
|||
Scan input list... |
|||
Get 2 adjacent elements |
|||
If gap = max, add the 2 elements as a complex to the output list |
|||
|} |
|||
The following line of code delivers what is required: |
|||
[1 8 2 -3 0 1 1 -2.3 0 5.5 8 6 2 9 11 10 3] ADJMAX |
|||
{{out}} |
|||
<pre> |
|||
1: { 7 (1,8) (2,9) (10,3) } |
|||
</pre> |
</pre> |
||