forth wizard / stack juggler

This commit is contained in:
zeroflag 2021-08-07 16:04:58 +02:00
parent e1c004bd38
commit 4373200e6a
2 changed files with 4 additions and 7 deletions

View file

@ -29,9 +29,9 @@ public class Dictionary {
} }
public void remove(String name) { public void remove(String name) {
Word exiting = at(name); Word existing = at(name);
if (exiting != null) if (existing != null)
dict.remove(exiting); dict.remove(existing);
} }
public Set<String> wordList() { public Set<String> wordList() {

View file

@ -68,6 +68,7 @@ public class Juggler {
this.rstack = new Stack<>(); this.rstack = new Stack<>();
this.code = new ArrayList<>(); this.code = new ArrayList<>();
this.availableWords = populateWords(excluded); this.availableWords = populateWords(excluded);
this.code.add(0);
} }
private List<Word> populateWords(Set<String> excluded) { private List<Word> populateWords(Set<String> excluded) {
@ -82,10 +83,6 @@ public class Juggler {
private List<String> solve() { private List<String> solve() {
if (input.isEmpty() && output.isEmpty() || input.equals(output)) if (input.isEmpty() && output.isEmpty() || input.equals(output))
return Collections.emptyList(); return Collections.emptyList();
code.clear();
code.add(0);
while (code.size() <= maxSteps) { while (code.size() <= maxSteps) {
if (goodCode(code)) if (goodCode(code))
return result(code); return result(code);