From 38cad937b483822cfd650411e97e7dc33c74e7b6 Mon Sep 17 00:00:00 2001 From: paddi Date: Sat, 10 Mar 2018 02:12:43 +0100 Subject: Fixed bug. --- .idea/vcs.xml | 6 +++++ .idea/workspace.xml | 25 ++++++++++++++------- out/production/PatternFinder/PatternFinderKt.class | Bin 7809 -> 7886 bytes src/PatternFinder.kt | 8 +++---- 4 files changed, 27 insertions(+), 12 deletions(-) create mode 100644 .idea/vcs.xml diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..94a25f7 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.idea/workspace.xml b/.idea/workspace.xml index a9e14c7..63ac00e 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -1,7 +1,12 @@ - + + + + + + + + + @@ -238,11 +247,11 @@ - - + + - + @@ -286,8 +295,8 @@ - - + + diff --git a/out/production/PatternFinder/PatternFinderKt.class b/out/production/PatternFinder/PatternFinderKt.class index 371883b..a964725 100644 Binary files a/out/production/PatternFinder/PatternFinderKt.class and b/out/production/PatternFinder/PatternFinderKt.class differ 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): 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): 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): Boolean { +private fun nAsExponent(differences: List, numbers: List): 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 -- cgit