DEV Community

Discussion on: Daily Challenge #63- Two Sum

Collapse
 
fennecdjay profile image
Jérémie Astor

In gwion:

fun <~int, int~>Tuple twosum(int data[], int total) {
  for(int i; i < data.size(); ++i) {
    for(i + 1 => int j; j < data.size(); ++j) {
      if((data[i]+data[j]) == total)
        return <(i, j);
    }
  }
  return null;
}

([1, 2, 3], 4) => twosum @=> >(index0, index1);
<<< index0, " ", index1 >>>;

The fun thing is that it undercovered a (now fixed) bug on tuple unpacking. 🍾