Skip to content

Instantly share code, notes, and snippets.

@lordvidex
Last active March 30, 2020 14:02
Show Gist options
  • Save lordvidex/3888c557c697c7c09def8d8891732180 to your computer and use it in GitHub Desktop.
Save lordvidex/3888c557c697c7c09def8d8891732180 to your computer and use it in GitHub Desktop.
Evans Owamoyo:: Day 6 Track 1 task
import 'dart:math';
String findPrimeFactors(int n) {
assert(!n.isNegative && n.isFinite); //just some extra input validations
List<num> ans = [];
while (n % 2 == 0) {
n ~/= 2;
ans.add(2);
}
for (var x = 3; x <= sqrt(n); x += 2)
while (n % x == 0) {
n ~/= x;
ans.add(x);
}
if (n > 2) ans.add(n);
return ans.join(', ');
}
void main() {
int n = 60;
print(findPrimeFactors(n));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment