return tuple or null
package kata
func Solve(s int, g int) []int {
if s % g != 0 {
return []int{-1, -1}
}
return []int{g, s - g}
}
// FYI: the problem to solve is:
// Given the sum and gcd of two numbers, return the two numbers in ascending order.
0
0
# return tuple or null
def solve s,g
s % g != 0 ? -1 : [g, s - g]
end
# FYI: the problem to solve is:
# Given the sum and gcd of two numbers, return the two numbers in ascending order.
Thank you!
0
0
3.83
6
// return a tuple or null
fn solve(sum: u32, gcd: u32) -> Option<(u32, u32)> {
if sum % gcd != 0 {
None
} else {
Some((gcd, sum - gcd))
}
}
// FYI: the problem solved is:
// Given the sum and gcd of two numbers, return the two numbers in ascending order.
Thank you!
6
0
4
5
// return tuple or null
#include <stdlib.h>
int *gdc_sum(int sum, int gcd) {
int *res = malloc(sizeof(int) * 2);
res[0] = gcd;
res[1] = sum - gcd;
return sum % gcd != 0 ? (NULL) : (res);
}
// FYI: the problem to solve is:
// Given the sum and gcd of two numbers, return the two numbers in ascending order.
Thank you!
5
0
4.6
5
// return tuple or null
using namespace std;
pair<int, int> solve(int s, int g){
return (s % g != 0) ? make_pair(-1, -1) : make_pair(g, s - g);
}
// FYI: the problem to solve is:
// Given the sum and gcd of two numbers, return the two numbers in ascending order.
Thank you!
5
0
Are there any code examples left?
New code examples in category Ruby
-
Ruby 2022-03-27 13:25:03 ruby assign value to hash
-
Ruby 2022-03-25 04:05:10 test if array empty ruby
-
Ruby 2022-03-24 19:45:17 rails update without validation
-
Ruby 2022-03-23 05:15:08 ruby hello world
-
Ruby 2022-03-23 02:40:01 rails keep all params except for some
-
Ruby 2022-03-20 06:15:08 rails hidden field default value
-
Ruby 2022-03-19 19:55:31 print things ruby
-
Ruby 2022-03-18 22:15:07 rails command line
-
Ruby 2022-03-18 08:10:03 ruby get the number of same element in array
-
Ruby 2022-03-17 02:40:17 drop rails all db