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 DLosc
Bounty Ended with chunes's answer chosen by DLosc
Notice added Reward existing answer by DLosc
Bounty Started worth 50 reputation by DLosc
added 4 characters in body
Source Link

Over is a higher-order function in multiple languages such as APL (). It takes 2 functions and 2 values as arguments, applies the first function to both values, then applies the second to their result. For example, using to represent Over:

1 2⍥+ 2

We would first calculate 2 of each argument: 12 = 1 and 22 = 4. We then apply + to these, yielding 5.

You are to take as input:

  • A black box function, \$f\$, which takes an integer as input and returns an integer
  • A black box function, \$g\$, which takes 2 integers as input and returns a single integer
  • 2 integers, \$a\$ and \$b\$.

You should then return the result of \$g(f(a), f(b))\$.

If you have a builtin specifically for this (e.g. APL's , Husk's ¤ etc.), consider including a non-builtin answer as well. It might even get you an upvote :)

You may input and output in the most convenient format for your language, and in any convenient method, including taking \$a\$ and \$b\$ as a pair/list/tupleincluding taking \$a\$ and \$b\$ as a pair/list/tuple [a, b]

For the sake of simplicity, you can assume that the black-box function will always input and output integers within your language's integer domain, and that \$a\$, \$b\$ and the output will be with your language's integer domain.

This is , so the shortest code in bytes wins

Test cases

f
g
a, b -> out
f(x) = x2
g(x,y) = x - y
-2, 2 -> 0
f(x) = φ(x) (Euler totient function)
g(x,y) = 2x + y
5, 9 -> 14
f(x) = x3-x2-x-1
g(x,y) = y4-x3-y2-x
-1, -1 -> 22
f(x) = x
g(x,y) = x / y (Integer division)
-25, 5 -> -5

Over is a higher-order function in multiple languages such as APL (). It takes 2 functions and 2 values as arguments, applies the first function to both values, then applies the second to their result. For example, using to represent Over:

1 2⍥+ 2

We would first calculate 2 of each argument: 12 = 1 and 22 = 4. We then apply + to these, yielding 5.

You are to take as input:

  • A black box function, \$f\$, which takes an integer as input and returns an integer
  • A black box function, \$g\$, which takes 2 integers as input and returns a single integer
  • 2 integers, \$a\$ and \$b\$.

You should then return the result of \$g(f(a), f(b))\$.

If you have a builtin specifically for this (e.g. APL's , Husk's ¤ etc.), consider including a non-builtin answer as well. It might even get you an upvote :)

You may input and output in the most convenient format for your language, and in any convenient method, including taking \$a\$ and \$b\$ as a pair/list/tuple [a, b]

For the sake of simplicity, you can assume that the black-box function will always input and output integers within your language's integer domain, and that \$a\$, \$b\$ and the output will be with your language's integer domain.

This is , so the shortest code in bytes wins

Test cases

f
g
a, b -> out
f(x) = x2
g(x,y) = x - y
-2, 2 -> 0
f(x) = φ(x) (Euler totient function)
g(x,y) = 2x + y
5, 9 -> 14
f(x) = x3-x2-x-1
g(x,y) = y4-x3-y2-x
-1, -1 -> 22
f(x) = x
g(x,y) = x / y (Integer division)
-25, 5 -> -5

Over is a higher-order function in multiple languages such as APL (). It takes 2 functions and 2 values as arguments, applies the first function to both values, then applies the second to their result. For example, using to represent Over:

1 2⍥+ 2

We would first calculate 2 of each argument: 12 = 1 and 22 = 4. We then apply + to these, yielding 5.

You are to take as input:

  • A black box function, \$f\$, which takes an integer as input and returns an integer
  • A black box function, \$g\$, which takes 2 integers as input and returns a single integer
  • 2 integers, \$a\$ and \$b\$.

You should then return the result of \$g(f(a), f(b))\$.

If you have a builtin specifically for this (e.g. APL's , Husk's ¤ etc.), consider including a non-builtin answer as well. It might even get you an upvote :)

You may input and output in the most convenient format for your language, and in any convenient method, including taking \$a\$ and \$b\$ as a pair/list/tuple [a, b]

For the sake of simplicity, you can assume that the black-box function will always input and output integers within your language's integer domain, and that \$a\$, \$b\$ and the output will be with your language's integer domain.

This is , so the shortest code in bytes wins

Test cases

f
g
a, b -> out
f(x) = x2
g(x,y) = x - y
-2, 2 -> 0
f(x) = φ(x) (Euler totient function)
g(x,y) = 2x + y
5, 9 -> 14
f(x) = x3-x2-x-1
g(x,y) = y4-x3-y2-x
-1, -1 -> 22
f(x) = x
g(x,y) = x / y (Integer division)
-25, 5 -> -5
Became Hot Network Question
Tweeted twitter.com/StackCodeGolf/status/1384342224264212482
Source Link

Implement an Over function

Over is a higher-order function in multiple languages such as APL (). It takes 2 functions and 2 values as arguments, applies the first function to both values, then applies the second to their result. For example, using to represent Over:

1 2⍥+ 2

We would first calculate 2 of each argument: 12 = 1 and 22 = 4. We then apply + to these, yielding 5.

You are to take as input:

  • A black box function, \$f\$, which takes an integer as input and returns an integer
  • A black box function, \$g\$, which takes 2 integers as input and returns a single integer
  • 2 integers, \$a\$ and \$b\$.

You should then return the result of \$g(f(a), f(b))\$.

If you have a builtin specifically for this (e.g. APL's , Husk's ¤ etc.), consider including a non-builtin answer as well. It might even get you an upvote :)

You may input and output in the most convenient format for your language, and in any convenient method, including taking \$a\$ and \$b\$ as a pair/list/tuple [a, b]

For the sake of simplicity, you can assume that the black-box function will always input and output integers within your language's integer domain, and that \$a\$, \$b\$ and the output will be with your language's integer domain.

This is , so the shortest code in bytes wins

Test cases

f
g
a, b -> out
f(x) = x2
g(x,y) = x - y
-2, 2 -> 0
f(x) = φ(x) (Euler totient function)
g(x,y) = 2x + y
5, 9 -> 14
f(x) = x3-x2-x-1
g(x,y) = y4-x3-y2-x
-1, -1 -> 22
f(x) = x
g(x,y) = x / y (Integer division)
-25, 5 -> -5

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