Created
March 21, 2020 04:01
-
-
Save md-weber/61a0564e84503fe55cc93e25fba02e33 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| 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