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

added 1186 characters in body
Source Link
Neil
  • 184.4k
  • 12
  • 76
  • 290

Charcoal, 63(削除) 63 (削除ここまで) 35 bytes

×ばつ§θι§ηκε≔⊗%−κι7δ¿=δ&δ±δ≦+κδ«≦−ιδ≦±ε»§≔ζδ+§ζδε»Iζ×ばつ⎇&λ⊖λ§θ−ιλ±§θ+μλ§ημ

Try it online! Try it online! Link is to verbose version of code. No test suite because that requires renaming the variables. Explanation: Uses the C(+) octonion multiplication table that I found here (warning: no SSL available). Also, this algorithm is probably suboptimal but I'll come back to it later.

×ばつθ0ζ 7 Literal integer `7`

Start with an empty result array.

F7FΦ7−κι« E Map over implicit range

Loop over the pairs of basis vectors.

×ばつ§θι§ηκε 7 Literal integer `7`

Get the product of the coefficients.

≔⊗%−κι7δ E Map over implicit range

Get the difference (modulo 7) of the indices, then double it.

¿=δ&δ±δ μ Inner index

If this is a power of 2, then...

≦+κδ − Subtract

... the result basis vector is the second index plus the doubled difference.

«≦−ιδ ι Outer value

Otherwise, the result basis vector is the first index minus the doubled difference, and...

≦±ε % Modulo

... the coefficient product needs to be negated.

»§≔ζδ+§ζδε 7 Literal integer `7`

Add the coefficient product to the result basis vector coefficient.

»Iζ ⊗ Doubled
 E Map over values
 λ Inner value
 ∧ Logical And
 λ Inner value
 & Bitwise And
 λ Inner value
 ⊖ Decremented
 ⎇ If true then
 θ First input
 § Cyclically indexed by
 ι Outer value
 − Subtract
 λ Inner value
 θ Else first input
 § Cyclically indexed by
 μ Inner index
 + Plus
 λ Inner value
 ± Negated
 ×ばつ Multiplied by
 η Second input
 § Indexed by
 μ Inner index
 Σ Take the sum
I Cast to string
 Implicitly print

Output the final coefficients.

Charcoal, 63 bytes

×ばつ§θι§ηκε≔⊗%−κι7δ¿=δ&δ±δ≦+κδ«≦−ιδ≦±ε»§≔ζδ+§ζδε»Iζ

Try it online! Link is to verbose version of code. No test suite because that requires renaming the variables. Explanation: Uses the C(+) octonion multiplication table that I found here (warning: no SSL available). Also, this algorithm is probably suboptimal but I'll come back to it later.

×ばつθ0ζ

Start with an empty result array.

F7FΦ7−κι«

Loop over the pairs of basis vectors.

×ばつ§θι§ηκε

Get the product of the coefficients.

≔⊗%−κι7δ

Get the difference (modulo 7) of the indices, then double it.

¿=δ&δ±δ

If this is a power of 2, then...

≦+κδ

... the result basis vector is the second index plus the doubled difference.

«≦−ιδ

Otherwise, the result basis vector is the first index minus the doubled difference, and...

≦±ε

... the coefficient product needs to be negated.

»§≔ζδ+§ζδε

Add the coefficient product to the result basis vector coefficient.

»Iζ

Output the final coefficients.

Charcoal, (削除) 63 (削除ここまで) 35 bytes

×ばつ⎇&λ⊖λ§θ−ιλ±§θ+μλ§ημ

Try it online! Link is to verbose version of code. No test suite because that requires renaming the variables. Explanation: Uses the C(+) octonion multiplication table that I found here (warning: no SSL available).

 7 Literal integer `7`
 E Map over implicit range
 7 Literal integer `7`
 E Map over implicit range
 μ Inner index
 − Subtract
 ι Outer value
 % Modulo
 7 Literal integer `7`
 ⊗ Doubled
 E Map over values
 λ Inner value
 ∧ Logical And
 λ Inner value
 & Bitwise And
 λ Inner value
 ⊖ Decremented
 ⎇ If true then
 θ First input
 § Cyclically indexed by
 ι Outer value
 − Subtract
 λ Inner value
 θ Else first input
 § Cyclically indexed by
 μ Inner index
 + Plus
 λ Inner value
 ± Negated
 ×ばつ Multiplied by
 η Second input
 § Indexed by
 μ Inner index
 Σ Take the sum
I Cast to string
 Implicitly print
Source Link
Neil
  • 184.4k
  • 12
  • 76
  • 290

Charcoal, 63 bytes

×ばつ§θι§ηκε≔⊗%−κι7δ¿=δ&δ±δ≦+κδ«≦−ιδ≦±ε»§≔ζδ+§ζδε»Iζ

Try it online! Link is to verbose version of code. No test suite because that requires renaming the variables. Explanation: Uses the C(+) octonion multiplication table that I found here (warning: no SSL available). Also, this algorithm is probably suboptimal but I'll come back to it later.

×ばつθ0ζ

Start with an empty result array.

F7FΦ7−κι«

Loop over the pairs of basis vectors.

×ばつ§θι§ηκε

Get the product of the coefficients.

≔⊗%−κι7δ

Get the difference (modulo 7) of the indices, then double it.

¿=δ&δ±δ

If this is a power of 2, then...

≦+κδ

... the result basis vector is the second index plus the doubled difference.

«≦−ιδ

Otherwise, the result basis vector is the first index minus the doubled difference, and...

≦±ε

... the coefficient product needs to be negated.

»§≔ζδ+§ζδε

Add the coefficient product to the result basis vector coefficient.

»Iζ

Output the final coefficients.

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