sourcelibs/Lists/demos/temperatures.xtl

1⍝!/usr/bin/env xetal 2⍝# A fortnight of temperatures: day-to-day changes, a 3-day moving 3⍝# mean, the longest warming streak, and where 20 degrees falls in the 4⍝# sorted readings. Run with "just demo Lists temperatures". 5 6"q:" u̲se< "Lists" 7t ← 14 15 17 16 18 19 21 22 20 19 21 23 24 22 8 9d ← q:d̲eltas t 10d ⍝ the change each day 113 q:m̲ovingMean t ⍝ smoothed 12 13⍝ Warming streaks: runs of days that rose. 14up ← d > 0 15'm̲ax r̲/ (q:r̲unValues up) × q:r̲unLengths up ⍝ the longest 16 17⍝ The two weeks side by side. 182 7 r̲eshape t 19 20⍝ How many readings are at most 20, by binary search in the sorted readings. 21(s̲ort t) q:b̲search 20