From 4373200e6a560255da02e8cb2230b786f5bff4f0 Mon Sep 17 00:00:00 2001 From: zeroflag Date: Sat, 7 Aug 2021 16:04:58 +0200 Subject: [PATCH] forth wizard / stack juggler --- src/main/java/com/vectron/fcl/Dictionary.java | 6 +++--- src/main/java/com/vectron/fcl/Juggler.java | 5 +---- 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/src/main/java/com/vectron/fcl/Dictionary.java b/src/main/java/com/vectron/fcl/Dictionary.java index d52e91c..f893192 100644 --- a/src/main/java/com/vectron/fcl/Dictionary.java +++ b/src/main/java/com/vectron/fcl/Dictionary.java @@ -29,9 +29,9 @@ public class Dictionary { } public void remove(String name) { - Word exiting = at(name); - if (exiting != null) - dict.remove(exiting); + Word existing = at(name); + if (existing != null) + dict.remove(existing); } public Set wordList() { diff --git a/src/main/java/com/vectron/fcl/Juggler.java b/src/main/java/com/vectron/fcl/Juggler.java index 0a40b5b..2670b5a 100644 --- a/src/main/java/com/vectron/fcl/Juggler.java +++ b/src/main/java/com/vectron/fcl/Juggler.java @@ -68,6 +68,7 @@ public class Juggler { this.rstack = new Stack<>(); this.code = new ArrayList<>(); this.availableWords = populateWords(excluded); + this.code.add(0); } private List populateWords(Set excluded) { @@ -82,10 +83,6 @@ public class Juggler { private List solve() { if (input.isEmpty() && output.isEmpty() || input.equals(output)) return Collections.emptyList(); - - code.clear(); - code.add(0); - while (code.size() <= maxSteps) { if (goodCode(code)) return result(code);