Run ❯
Get your
own
website
❯
Run Code
Ctrl+Alt+R
Change Orientation
Ctrl+Alt+O
Change Theme
Ctrl+Alt+D
Change Language
Go to Spaces
Ctrl+Alt+P
import 'dart:async'; int countPrimes(int max) { int count = 0; for (int n = 2; n <= max; n++) { bool isPrime = true; for (int d = 2; d * d <= n; d++) { if (n % d == 0) { isPrime = false; break; } } if (isPrime) count++; } return count; } void main() { int ticks = 0; final timer = Timer.periodic(Duration(milliseconds: 100), (t) { ticks++; }); int primes = countPrimes(5000000); timer.cancel(); print('Primes up to 5 million: $primes'); print('Did the timer run? ${ticks > 0}'); }
Primes up to 5 million: 348513
Did the timer run? false