Quantcast
Channel: Double-reduce a sequence of integers - Code Golf Stack Exchange
Viewing all articles
Browse latest Browse all 6

Answer by Arnauld for Double-reduce a sequence of integers

$
0
0

JavaScript (ES6), 61 bytes

a=>a.map(v=>a=[0,...b].map(k=>1/a&&b.push(v-a-k))&&v,b=[])&&b

Try it online!

Commented

a =>              // a[] = inputa.map(v =>        // for each value v in a[]:  a =             //   update a:    [0, ...b]     //     for 0 and each value in b[]    .map(k =>     //     loaded in k:      1 / a       //       do nothing if this is the 1st iteration&&          //       (i.e. a is still the input array)      b.push(     //       otherwise, push in b[]:        v - a - k //         the current value, minus the previous one,      )           //         minus k    )             //     end of inner map()&& v,         //     save v in a  b = []          //   start with b[] = empty array)                 // end of outer map()&& b              // return b[]

JavaScript (V8), 92 bytes

This was an attempt at implementing the definition literally.

L=>{for(n=1;L[-~(g=Math.log2)(n)];)print((r=k=>~(k-=2**(i=~~g(k)))&&L[i+1]-L[i]-r(k))(n++))}

Try it online!


Viewing all articles
Browse latest Browse all 6

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>