Calculates the factorial of a number. Throws for negative inputs.
int factorial(int n) { if (n < 0) throw ArgumentError('Negative numbers not allowed'); return n <= 1 ? 1 : n * factorial(n - 1); }