aboutsummaryrefslogtreecommitdiff
path: root/src/PatternFinder.kt
diff options
context:
space:
mode:
authorpaddi <paddim8@gmail.com>2018-03-10 02:12:43 +0100
committerpaddi <paddim8@gmail.com>2018-03-10 02:12:43 +0100
commit38cad937b483822cfd650411e97e7dc33c74e7b6 (patch)
treefee5e471cdd1fc5c209118d66b4e9c25c8360929 /src/PatternFinder.kt
parent599311d94690c4867504a2dbc65a631828060755 (diff)
downloadPatternToFormula-38cad937b483822cfd650411e97e7dc33c74e7b6.tar.gz
PatternToFormula-38cad937b483822cfd650411e97e7dc33c74e7b6.tar.bz2
PatternToFormula-38cad937b483822cfd650411e97e7dc33c74e7b6.zip
Fixed bug.
Diffstat (limited to 'src/PatternFinder.kt')
-rw-r--r--src/PatternFinder.kt8
1 files changed, 4 insertions, 4 deletions
diff --git a/src/PatternFinder.kt b/src/PatternFinder.kt
index bbab9ae..fb660f5 100644
--- a/src/PatternFinder.kt
+++ b/src/PatternFinder.kt
@@ -33,7 +33,7 @@ private fun findFormula(numbers: List<Double>): String {
increment = differences[0]
// Start-value
- val nAsExponent = nAsExponent(differences)
+ val nAsExponent = nAsExponent(differences, numbers)
val startValueDifference = when {
incrementsByDifference -> differences[0] // xn
nAsExponent -> getBase(differences) // x^n
@@ -45,7 +45,7 @@ private fun findFormula(numbers: List<Double>): String {
// Exponents
var base = "n"
var exponent = ""
- if (nAsExponent(differences)) {
+ if (nAsExponent(differences, numbers)) {
base = getBase(differences).cleanRedundancy() + "^"
exponent = "n"
} else if (!incrementsByDifference) {
@@ -113,7 +113,7 @@ private fun getExponent(secondNumber: Double, startValue: Double): Double {
return Math.log(secondNumber - startValue) / Math.log(2.0)
}
-private fun nAsExponent(differences: List<Double>): Boolean {
+private fun nAsExponent(differences: List<Double>, numbers: List<Double>): Boolean {
val base = getBase(differences)
- return base == differences[0] / (differences[0] / base)
+ return Math.log(numbers[1] - (base - 1)) / Math.log(base) == 2.0
} \ No newline at end of file