Skip to main content
We’ve updated our Terms of Service. A new AI Addendum clarifies how Stack Overflow utilizes AI interactions.
Code Golf

Return to Revisions

6 of 8
added a commented version
Arnauld
  • 205.5k
  • 21
  • 187
  • 670

JavaScript (ES6), 83 bytes

Expects (u)(v).

Disclaimer: Either that's correct, or I completely misunderstood the challenge.

u=>v=>[0,1,2,4].reduce((p,i)=>p.map(n=>i&&n+u[i%=7]*v[j%=7]-u[j++]*v[i++],j=i*3),u)

Try it online!

Commented

u => // u[] = first vector
v => // v[] = second vector
[0, 1, 2, 4] // lookup list
.reduce((p, i) => // for each value i with p[] as the accumulator:
 p.map(n => // for each value n in p[]:
 i && // force to zero if i = 0
 n + // otherwise, take the current value n
 u[i %= 7] * // and add u[i] * v[j] - u[j] * v[i]
 v[j %= 7] - // where both i and j are reduced modulo 7
 u[j++] * // and incremented afterwards
 v[i++], //
 j = i * 3 // start with j = i * 3
 ), // end of map()
 u // start with p[] = u[] (but the content of p[]
 // is cleared on the first iteration)
) // end of reduce()
Arnauld
  • 205.5k
  • 21
  • 187
  • 670

AltStyle によって変換されたページ (->オリジナル) /