3 ms·
K does a thing (like J I think?) where it's scan/reduce returns each subsequence/intermediate-value as it goes which is what makes that problem so trivial in K.
by Avshalom 10y ago
K does a thing (like J I think?) where it's scan/reduce returns each subsequence/intermediate-value as it goes which is what makes that problem so trivial in K.
- RodgerTheGreat 10y agoThe K "over" adverb (/) is like a conventional reduce/accumulate/fold. The K "scan" adverb (\) produces a list of the intermediate results. Having both is extremely handy. If the verb argument of over/scan takes a single argument (rather than two), the adverbs will iterate to a fixed point. As before, "/" will return the final result and "\" returns all the intermediates. For example: +/1 2 3 6 +\1 2 3 1 3 6 *:/,,,0 0 *:\,,,0 (,,,0 ,,0 ,0 0)
- arcfide 10y agoOh wait, so you're not preserving the subsequence, you just preserving the sum. So it's a standard scan. So my original translation is correct, my subsequence preserving version is doing a bit more than this by preserving the subarray as well as the sum.
- arcfide 10y agoAh, if we have to preserve the sequence: ((⊃∘⍒0⌷⍉)⌷⊢)(+\,∘⍪,\)