Skip to content

Instantly share code, notes, and snippets.

@geektutor
Last active May 3, 2020 17:01
Show Gist options
  • Save geektutor/437bab37ad95c8841251e966aa164dbe to your computer and use it in GitHub Desktop.
Save geektutor/437bab37ad95c8841251e966aa164dbe to your computer and use it in GitHub Desktop.
void main() {
barnyard(head: 20, leg: 76);
}
barnyard({head, leg}) {
var goat = (leg / 2) - head;
var chicken = head - goat;
if (goat is int &&
chicken is int &&
!goat.isNegative &&
!chicken.isNegative) {
print('There are $goat goats and $chicken chicken in my barnyard');
} else {
print('Invalid entries. Try again');
}
}
/* I used c + 3g = leg-head and c + g = head to get g = (leg/2) - head & c = head - g
*
* I intentionally allowed the user to enter more than int because I dont want the red error of the compiler and want to define my own error statement
* */
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment