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

Golfed 1 byte
Source Link
DLosc
  • 40.7k
  • 6
  • 87
  • 142

BQN, 6(削除) 6 (削除ここまで) 5 bytes

-1 byte by porting emanresu A's Vyxal answer

=◶⌈‿+ ̈×ばつ1+=

Anonymous tacit function that takes equal-length lists as left and right arguments. Try it at BQN online! Try it at BQN online!

Explanation

×ばつ1+=
 = Compare the two lists itemwise (1 for equal, 0 for not equal)
 1+ Add 1 to each (2 for equal, 1 for not equal)
⌈ Get the itemwise maximums of the two lists
 ×ばつ Multiply (itemwise)

Original solution

BQN happens to have builtins that allow a direct implementation of theThe spec can be implemented very literally in 6 bytes:

=◶⌈‿+ ̈
 ̈ Apply this function to corresponding pairs of elements from the arguments:
= Test if the elements are equal (1 if so, 0 if not)
 ◶ Use that result to pick a function from this list and apply it:
 ⌈ If 0 (not equal), then max
 ‿+ If 1 (equal), then add

BQN, 6 bytes

=◶⌈‿+ ̈

Anonymous tacit function that takes equal-length lists as left and right arguments. Try it at BQN online!

Explanation

BQN happens to have builtins that allow a direct implementation of the spec:

=◶⌈‿+ ̈
 ̈ Apply this function to corresponding pairs of elements from the arguments:
= Test if the elements are equal (1 if so, 0 if not)
 ◶ Use that result to pick a function from this list and apply it:
 ⌈ If 0 (not equal), then max
 ‿+ If 1 (equal), then add

BQN, (削除) 6 (削除ここまで) 5 bytes

-1 byte by porting emanresu A's Vyxal answer

×ばつ1+=

Anonymous tacit function that takes equal-length lists as left and right arguments. Try it at BQN online!

Explanation

×ばつ1+=
 = Compare the two lists itemwise (1 for equal, 0 for not equal)
 1+ Add 1 to each (2 for equal, 1 for not equal)
⌈ Get the itemwise maximums of the two lists
 ×ばつ Multiply (itemwise)

Original solution

The spec can be implemented very literally in 6 bytes:

=◶⌈‿+ ̈
 ̈ Apply this function to corresponding pairs of elements from the arguments:
= Test if the elements are equal (1 if so, 0 if not)
 ◶ Use that result to pick a function from this list and apply it:
 ⌈ If 0 (not equal), then max
 ‿+ If 1 (equal), then add
Source Link
DLosc
  • 40.7k
  • 6
  • 87
  • 142

BQN, 6 bytes

=◶⌈‿+ ̈

Anonymous tacit function that takes equal-length lists as left and right arguments. Try it at BQN online!

Explanation

BQN happens to have builtins that allow a direct implementation of the spec:

=◶⌈‿+ ̈
 ̈ Apply this function to corresponding pairs of elements from the arguments:
= Test if the elements are equal (1 if so, 0 if not)
 ◶ Use that result to pick a function from this list and apply it:
 ⌈ If 0 (not equal), then max
 ‿+ If 1 (equal), then add

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