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

2 of 3
added 639 characters in body
Giuseppe
  • 29.4k
  • 3
  • 33
  • 106

R, (削除) 31 (削除ここまで) 29 bytes

function(a,b)pmax(a,b)+a*!a-b

pmax takes the parallel maximum of the two (or more) arrays (recycling the shorter as needed).

I was looking at Luis Mendo's comment and obviously I realized the approach could work for R as well. That got me to 30 bytes, but then I started playing around with different ways of getting indices instead to improve my original answer, and stumbled upon !a-b as TRUE where a==b and FALSE otherwise, equivalent to a==b. However, for whatever reason, R doesn't require parentheses around !a-b as it does for a==b, which saved me two bytes.

Try it online! (new version)

Try it online! (original)

Giuseppe
  • 29.4k
  • 3
  • 33
  • 106

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