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
Awgiedawgie 440215 points

                                    # 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. 

0
0
3.83
6
Krish 100200 points

                                    // 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. 

3.83 (6 Votes)
0
4
5
Awgiedawgie 440215 points

                                    // 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. 

4 (5 Votes)
0
4.6
5
Awgiedawgie 440215 points

                                    // 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. 

4.6 (5 Votes)
0
Are there any code examples left?
Made with love
This website uses cookies to make IQCode work for you. By using this site, you agree to our cookie policy

Welcome Back!

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign in
Recover lost password
Or log in with

Create a Free Account

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign up
Or sign up with
By signing up, you agree to the Terms and Conditions and Privacy Policy. You also agree to receive product-related marketing emails from IQCode, which you can unsubscribe from at any time.
Creating a new code example
Code snippet title
Source