Skip to content

Instantly share code, notes, and snippets.

@md-weber
Created March 21, 2020 04:01
Show Gist options
  • Select an option

  • Save md-weber/61a0564e84503fe55cc93e25fba02e33 to your computer and use it in GitHub Desktop.

Select an option

Save md-weber/61a0564e84503fe55cc93e25fba02e33 to your computer and use it in GitHub Desktop.
void main() {
var primeFactors = PrimeFactors();
primeFactors.factors(8);
}
class PrimeFactors {
List<int> factors(int num) {
List<int> primeList = [];
int divisable = 2;
bool search = true;
while (search) {
if (num % divisable == 0) {
primeList.add(divisable);
num = num ~/ divisable;
if (divisable == 2) {
divisable++;
} else
divisable--;
} else
divisable++;
if (divisable > 9) {
search = false;
if (primeList.isEmpty) {
if (num == 1) return [];
primeList.add(num);
}
return primeList;
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment