2015-03-01 06:47:02 -05:00
|
|
|
//
|
|
|
|
// FILE: FractionFindSum.ino
|
|
|
|
// AUTHOR: Rob Tillaart
|
|
|
|
// PURPOSE: demo
|
|
|
|
// DATE: 13-feb-2015
|
2020-11-27 05:16:22 -05:00
|
|
|
// URL: https://github.com/RobTillaart/Fraction
|
2015-03-01 06:47:02 -05:00
|
|
|
//
|
|
|
|
|
2021-11-01 10:56:22 -04:00
|
|
|
|
2015-03-01 06:47:02 -05:00
|
|
|
#include "fraction.h"
|
|
|
|
|
2021-11-01 10:56:22 -04:00
|
|
|
|
2015-03-01 06:47:02 -05:00
|
|
|
uint32_t start;
|
|
|
|
uint32_t stop;
|
|
|
|
|
2021-11-01 10:56:22 -04:00
|
|
|
|
2015-03-01 06:47:02 -05:00
|
|
|
void setup()
|
|
|
|
{
|
|
|
|
pinMode(13, OUTPUT);
|
|
|
|
Serial.begin(115200);
|
|
|
|
Serial.print("\n\nStart F: ");
|
2021-11-01 10:56:22 -04:00
|
|
|
Serial.println(FRACTION_LIB_VERSION);
|
2015-03-01 06:47:02 -05:00
|
|
|
Serial.println();
|
|
|
|
randomSeed(analogRead(A0) * 256 + analogRead(A1));
|
|
|
|
|
|
|
|
start = micros();
|
|
|
|
stop = micros();
|
|
|
|
// Serial.println(stop - start);
|
|
|
|
|
|
|
|
for (int i = 1; i < 93; i++)
|
|
|
|
{
|
|
|
|
Fraction f(i, 93);
|
|
|
|
findSum(f);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-11-01 10:56:22 -04:00
|
|
|
|
2015-03-01 06:47:02 -05:00
|
|
|
void findSum(Fraction f)
|
|
|
|
{
|
2021-01-29 06:31:58 -05:00
|
|
|
Fraction z(0, 1);
|
2015-03-01 06:47:02 -05:00
|
|
|
|
|
|
|
Serial.print(f);
|
|
|
|
Serial.print(" =\t ");
|
|
|
|
for (long i = 1; i < 10000; i++)
|
|
|
|
{
|
|
|
|
Fraction g(1, i);
|
|
|
|
if (g <= f)
|
|
|
|
{
|
|
|
|
f -= g;
|
|
|
|
z += g;
|
|
|
|
Serial.print(g);
|
|
|
|
Serial.print(" + ");
|
|
|
|
}
|
2021-01-29 06:31:58 -05:00
|
|
|
if (f == Fraction(0, 1))
|
2015-03-01 06:47:02 -05:00
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Serial.print("\t => ");
|
|
|
|
Serial.println(z);
|
|
|
|
Serial.println();
|
|
|
|
}
|
2020-11-27 05:16:22 -05:00
|
|
|
|
|
|
|
|
2015-03-01 06:47:02 -05:00
|
|
|
void loop()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2021-11-01 10:56:22 -04:00
|
|
|
|
2020-11-27 05:16:22 -05:00
|
|
|
// -- END OF FILE --
|
2021-11-01 10:56:22 -04:00
|
|
|
|