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 Answer

improved test code
Source Link
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! 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, which gives (modulo 7):
 // (i,j) = (1,3), (2,6), (4,5)
 ), // end of map()
 u // start with p[] = u[] (but the content of p[]
 // is cleared on the first iteration)
) // end of reduce()

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, which gives (modulo 7):
 // (i,j) = (1,3), (2,6), (4,5)
 ), // end of map()
 u // start with p[] = u[] (but the content of p[]
 // is cleared on the first iteration)
) // end of reduce()

JavaScript (ES6), 83 bytes

Expects (u)(v).

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, which gives (modulo 7):
 // (i,j) = (1,3), (2,6), (4,5)
 ), // end of map()
 u // start with p[] = u[] (but the content of p[]
 // is cleared on the first iteration)
) // end of reduce()
minor clarification
Source Link
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, which gives (modulo 7):
 // (i,j) = (1,3), (2,6), (4,5)
 ), // end of map()
 u // start with p[] = u[] (but the content of p[]
 // is cleared on the first iteration)
) // end of reduce()

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()

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, which gives (modulo 7):
 // (i,j) = (1,3), (2,6), (4,5)
 ), // end of map()
 u // start with p[] = u[] (but the content of p[]
 // is cleared on the first iteration)
) // end of reduce()
added a commented version
Source Link
Arnauld
  • 205.5k
  • 21
  • 187
  • 670

JavaScript (ES6), 83 bytes

Expects (u)(v).

Disclaimer: Either that's correct, or I completely misunderstood the challenge.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()

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!

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()
improved test code
Source Link
Arnauld
  • 205.5k
  • 21
  • 187
  • 670
Loading
saved 1 byte
Source Link
Arnauld
  • 205.5k
  • 21
  • 187
  • 670
Loading
saved 4 bytes
Source Link
Arnauld
  • 205.5k
  • 21
  • 187
  • 670
Loading
saved 20 bytes
Source Link
Arnauld
  • 205.5k
  • 21
  • 187
  • 670
Loading
Source Link
Arnauld
  • 205.5k
  • 21
  • 187
  • 670
Loading

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