From e6f5af3727f8fee53ca8ff8295b69b972673c5c0 Mon Sep 17 00:00:00 2001 From: Danila Fedorin Date: Wed, 9 Aug 2017 12:47:22 -0700 Subject: [PATCH] Add optimization to NPR. --- src/main/java/org/nwapw/abacus/plugin/StandardPlugin.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/main/java/org/nwapw/abacus/plugin/StandardPlugin.java b/src/main/java/org/nwapw/abacus/plugin/StandardPlugin.java index 7d4fa3b..c264b4c 100755 --- a/src/main/java/org/nwapw/abacus/plugin/StandardPlugin.java +++ b/src/main/java/org/nwapw/abacus/plugin/StandardPlugin.java @@ -154,6 +154,10 @@ public class StandardPlugin extends Plugin { NumberInterface total = fromInt(params[0].getClass(), 1); NumberInterface multiplyBy = params[0]; NumberInterface remainingMultiplications = params[1]; + NumberInterface halfway = params[0].divide(fromInt(params[0].getClass(), 2)); + if(remainingMultiplications.compareTo(halfway) > 0){ + remainingMultiplications = params[0].subtract(remainingMultiplications); + } while(remainingMultiplications.signum() > 0){ total = total.multiply(multiplyBy); remainingMultiplications = remainingMultiplications.subtract(fromInt(params[0].getClass(), 1));