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 Question

Notice removed Reward existing answer by lyxal
Bounty Ended with tybocopperkettle's answer chosen by lyxal
Notice added Reward existing answer by lyxal
Bounty Started worth 100 reputation by lyxal
Commonmark migration
Source Link

You will be given two arrays of floating-point numbers. Your task is to pair the corresponding elements of the two arrays, and get the maximum of each pair. However, if the two corresponding elements are equal, you must take their sum instead.

For example, given the lists [1, 3, 3.2, 2.3] and [3, 1, 3.2, 2.6], you must do the following:

  • Pair the elements (or zip): [[1, 3], [3, 1], [3.2, 3.2], [2.3, 2.6]].

  • Go through each pair and apply the process above: [3, 3, 6.4, 2.6].


##Specs

Specs

  • The arrays / lists will always have equal length. They may however be empty.

  • The numbers they contain will always fit your language's capabilities, as long as you do not abuse that. They may be positive, zero or negative, you must handle all types.

  • If it helps you reduce your byte count, you may also take the length of the lists as input.

##Rules

Rules


#Test Cases

Test Cases

Array_1, Array_2 -> Output
[], [] -> []
[1, 2, 3], [1, 3, 2] -> [2, 3, 3]
[1, 3, 3.2, 2.3], [3, 1, 3.2, 2.6] -> [3, 3, 6.4, 2.6]
[1,2,3,4,5,5,7,8,9,10], [10,9,8,7,6,5,4,3,2,1] -> [10, 9, 8, 7, 6, 10, 7, 8, 9, 10]
[-3.2, -3.2, -2.4, 7, -10.1], [100, -3.2, 2.4, -7, -10.1] -> [100, -6.4, 2.4, 7, -20.2]

You will be given two arrays of floating-point numbers. Your task is to pair the corresponding elements of the two arrays, and get the maximum of each pair. However, if the two corresponding elements are equal, you must take their sum instead.

For example, given the lists [1, 3, 3.2, 2.3] and [3, 1, 3.2, 2.6], you must do the following:

  • Pair the elements (or zip): [[1, 3], [3, 1], [3.2, 3.2], [2.3, 2.6]].

  • Go through each pair and apply the process above: [3, 3, 6.4, 2.6].


##Specs

  • The arrays / lists will always have equal length. They may however be empty.

  • The numbers they contain will always fit your language's capabilities, as long as you do not abuse that. They may be positive, zero or negative, you must handle all types.

  • If it helps you reduce your byte count, you may also take the length of the lists as input.

##Rules


#Test Cases

Array_1, Array_2 -> Output
[], [] -> []
[1, 2, 3], [1, 3, 2] -> [2, 3, 3]
[1, 3, 3.2, 2.3], [3, 1, 3.2, 2.6] -> [3, 3, 6.4, 2.6]
[1,2,3,4,5,5,7,8,9,10], [10,9,8,7,6,5,4,3,2,1] -> [10, 9, 8, 7, 6, 10, 7, 8, 9, 10]
[-3.2, -3.2, -2.4, 7, -10.1], [100, -3.2, 2.4, -7, -10.1] -> [100, -6.4, 2.4, 7, -20.2]

You will be given two arrays of floating-point numbers. Your task is to pair the corresponding elements of the two arrays, and get the maximum of each pair. However, if the two corresponding elements are equal, you must take their sum instead.

For example, given the lists [1, 3, 3.2, 2.3] and [3, 1, 3.2, 2.6], you must do the following:

  • Pair the elements (or zip): [[1, 3], [3, 1], [3.2, 3.2], [2.3, 2.6]].

  • Go through each pair and apply the process above: [3, 3, 6.4, 2.6].


Specs

  • The arrays / lists will always have equal length. They may however be empty.

  • The numbers they contain will always fit your language's capabilities, as long as you do not abuse that. They may be positive, zero or negative, you must handle all types.

  • If it helps you reduce your byte count, you may also take the length of the lists as input.

Rules


Test Cases

Array_1, Array_2 -> Output
[], [] -> []
[1, 2, 3], [1, 3, 2] -> [2, 3, 3]
[1, 3, 3.2, 2.3], [3, 1, 3.2, 2.6] -> [3, 3, 6.4, 2.6]
[1,2,3,4,5,5,7,8,9,10], [10,9,8,7,6,5,4,3,2,1] -> [10, 9, 8, 7, 6, 10, 7, 8, 9, 10]
[-3.2, -3.2, -2.4, 7, -10.1], [100, -3.2, 2.4, -7, -10.1] -> [100, -6.4, 2.4, 7, -20.2]
Tweeted twitter.com/StackCodeGolf/status/902423569845669888
Source Link
user70974
user70974

Get the best of two Arrays

You will be given two arrays of floating-point numbers. Your task is to pair the corresponding elements of the two arrays, and get the maximum of each pair. However, if the two corresponding elements are equal, you must take their sum instead.

For example, given the lists [1, 3, 3.2, 2.3] and [3, 1, 3.2, 2.6], you must do the following:

  • Pair the elements (or zip): [[1, 3], [3, 1], [3.2, 3.2], [2.3, 2.6]].

  • Go through each pair and apply the process above: [3, 3, 6.4, 2.6].


##Specs

  • The arrays / lists will always have equal length. They may however be empty.

  • The numbers they contain will always fit your language's capabilities, as long as you do not abuse that. They may be positive, zero or negative, you must handle all types.

  • If it helps you reduce your byte count, you may also take the length of the lists as input.

##Rules


#Test Cases

Array_1, Array_2 -> Output
[], [] -> []
[1, 2, 3], [1, 3, 2] -> [2, 3, 3]
[1, 3, 3.2, 2.3], [3, 1, 3.2, 2.6] -> [3, 3, 6.4, 2.6]
[1,2,3,4,5,5,7,8,9,10], [10,9,8,7,6,5,4,3,2,1] -> [10, 9, 8, 7, 6, 10, 7, 8, 9, 10]
[-3.2, -3.2, -2.4, 7, -10.1], [100, -3.2, 2.4, -7, -10.1] -> [100, -6.4, 2.4, 7, -20.2]

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