Skip to content

Instantly share code, notes, and snippets.

@Parables
Last active January 12, 2022 12:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Parables/f1f415dbd1ef708ee97136c404d1062e to your computer and use it in GitHub Desktop.
Save Parables/f1f415dbd1ef708ee97136c404d1062e to your computer and use it in GitHub Desktop.
Zizag triples in Dart
// Author: Parables Boltnoel
void main() {
var numbers = [1, 2, 1, 3, 4];
findZigZagTriples(numbers);
}
//
// This function determines whether three numbers a, b, and c is a zigzag triples
bool isZigzag(num a, num b, num c) {
return (a > b && b < c) == true || (a < b && b > c) == true;
}
List<num> findZigZagTriples(List<num> numbers) {
num a, b, c;
List<num> result = [];
for (int i = 0; i < numbers.length - 2; i++) {
a = numbers[i];
b = numbers[i + 1];
c = numbers[i + 2];
int intValue = isZigzag(a, b, c) ? 1 : 0;
result.add(intValue);
}
print(result);
return result;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment