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 1073 characters in body
Source Link
tsh
  • 36.2k
  • 2
  • 36
  • 133

JavaScript (SpiderMonkey), 69 bytes

a=>a.map((q,i)=>a.map(l=(p,j)=>a[j]=j>i&&(t=p%q)?p/t*l(q,j,q=t):p)|q)

Try it online!

  • Function l assign lcm(p,q) to a[j], and assign gcd(p, q) to q if j > i, otherwise keeps everything unchanged.
    • lcm(p,q) = if p%q=0 then p else p*lcm(q,p%q)/(p%q)

Old answer:

JavaScript (SpiderMonkey) , 73 bytes

a=>a.map((u,i)=>a.map((v,j)=>i<j?a[j]*=u/(g=p=>p%u?g(u,u=p%u):u)(v):0)|u)

Try it online!

  • Function g calculate gcd(u, v) and assign return value to u.

JavaScript (SpiderMonkey), 73 bytes

a=>a.map((u,i)=>a.map((v,j)=>i<j?a[j]*=u/(g=p=>p%u?g(u,u=p%u):u)(v):0)|u)

Try it online!

JavaScript (SpiderMonkey), 69 bytes

a=>a.map((q,i)=>a.map(l=(p,j)=>a[j]=j>i&&(t=p%q)?p/t*l(q,j,q=t):p)|q)

Try it online!

  • Function l assign lcm(p,q) to a[j], and assign gcd(p, q) to q if j > i, otherwise keeps everything unchanged.
    • lcm(p,q) = if p%q=0 then p else p*lcm(q,p%q)/(p%q)

Old answer:

JavaScript (SpiderMonkey) , 73 bytes

a=>a.map((u,i)=>a.map((v,j)=>i<j?a[j]*=u/(g=p=>p%u?g(u,u=p%u):u)(v):0)|u)

Try it online!

  • Function g calculate gcd(u, v) and assign return value to u.
Source Link
tsh
  • 36.2k
  • 2
  • 36
  • 133

JavaScript (SpiderMonkey), 73 bytes

a=>a.map((u,i)=>a.map((v,j)=>i<j?a[j]*=u/(g=p=>p%u?g(u,u=p%u):u)(v):0)|u)

Try it online!

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