Created
November 14, 2023 01:41
-
-
Save sixtusagbo/f21f6a0338b9fee97dd9edd3dc9ea5d4 to your computer and use it in GitHub Desktop.
Weird and Not Weird numbers...
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'dart:math'; | |
void main() { | |
Random random = Random(); | |
/// Generate random number between 1 to 10 | |
int n = random.nextInt(10)+1; | |
bool _even = n % 2 == 0; | |
/// Inclusive range from 2 to 5 | |
List<int> rangeOne = [for(var i=2; i<=5; i++) i]; | |
/// Inclusive range from 6 to 20 | |
List<int> rangeTwo = [for(var i=6; i<=20; i++) i]; | |
if (!_even) { | |
print('Weird'); | |
} else if (_even && rangeOne.contains(n)) { | |
print('Not Weird'); | |
} else if (_even && rangeTwo.contains(n)) { | |
print('Weird'); | |
} else if (_even && n > 20) { | |
print('Not Weird'); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment