Added previous arduino implementations.
This commit is contained in:
41
Problem3.cpp
Normal file
41
Problem3.cpp
Normal file
@@ -0,0 +1,41 @@
|
||||
#include "WString.h"
|
||||
#include "HardwareSerial.h"
|
||||
#include "Problem3.hpp"
|
||||
#include "Arduino.h"
|
||||
#include "Vector.h"
|
||||
|
||||
Problem3::Problem3() {
|
||||
fl_input = 600851475143;
|
||||
|
||||
unsigned long primeArray[] = { 2 };
|
||||
primes = Vector<unsigned long>(primeArray, 1);
|
||||
}
|
||||
|
||||
bool Problem3::Step() {
|
||||
Serial.println("iterator = " + String(iterator));
|
||||
// Find prime
|
||||
bool isPrime;
|
||||
Serial.println("known primes = " + String(primes.size()));
|
||||
|
||||
for (unsigned long prime : primes) {
|
||||
Serial.println("prime = " + String(prime));
|
||||
isPrime = iterator % prime != 0;
|
||||
if (!isPrime) break;
|
||||
}
|
||||
|
||||
// Current value is new prime
|
||||
if (isPrime) {
|
||||
primes.push_back(iterator);
|
||||
Serial.println("Found prime = " + String(iterator));
|
||||
// Is number factor of input
|
||||
if (fl_input / iterator == floor(fl_input / iterator)) {
|
||||
// Save current prime as biggest prime and promote other factor as new max.
|
||||
Serial.println("Found prime factor = " + String(iterator));
|
||||
output = iterator;
|
||||
fl_input = fl_input / iterator;
|
||||
}
|
||||
}
|
||||
iterator++;
|
||||
delay(1000);
|
||||
return fl_input < iterator;
|
||||
}
|
||||
Reference in New Issue
Block a user