diff --git a/abstraction/.project b/abstraction/.project index cdac6fb..439c9a9 100644 --- a/abstraction/.project +++ b/abstraction/.project @@ -14,4 +14,15 @@ org.eclipse.jdt.core.javanature + + + 1731947415548 + + 30 + + org.eclipse.core.resources.regexFilterMatcher + node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__ + + + diff --git a/fibonacci/.classpath b/fibonacci/.classpath new file mode 100644 index 0000000..f9ed317 --- /dev/null +++ b/fibonacci/.classpath @@ -0,0 +1,12 @@ + + + + + + + + + + + + diff --git a/fibonacci/.project b/fibonacci/.project new file mode 100644 index 0000000..ad8d5f9 --- /dev/null +++ b/fibonacci/.project @@ -0,0 +1,28 @@ + + + fibonacci + + + + + + org.eclipse.jdt.core.javabuilder + + + + + + org.eclipse.jdt.core.javanature + + + + 1731947415557 + + 30 + + org.eclipse.core.resources.regexFilterMatcher + node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__ + + + + diff --git a/fibonacci/.settings/org.eclipse.core.resources.prefs b/fibonacci/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 0000000..99f26c0 --- /dev/null +++ b/fibonacci/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +encoding/=UTF-8 diff --git a/fibonacci/.settings/org.eclipse.jdt.core.prefs b/fibonacci/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..9a7984b --- /dev/null +++ b/fibonacci/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,11 @@ +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.targetPlatform=21 +org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve +org.eclipse.jdt.core.compiler.compliance=21 +org.eclipse.jdt.core.compiler.debug.lineNumber=generate +org.eclipse.jdt.core.compiler.debug.localVariable=generate +org.eclipse.jdt.core.compiler.debug.sourceFile=generate +org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled +org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=warning +org.eclipse.jdt.core.compiler.release=enabled +org.eclipse.jdt.core.compiler.source=21 diff --git a/fibonacci/src/fibonacci/Main.java b/fibonacci/src/fibonacci/Main.java new file mode 100644 index 0000000..492a8b7 --- /dev/null +++ b/fibonacci/src/fibonacci/Main.java @@ -0,0 +1,174 @@ +package fibonacci; + +import tester.Tester; + +class Examples { + + ISequence f; + ISequence a; + ISeqGen aGen = new AGen(); + + void init() { + this.f = new Fibonacci(); + this.a = new GenSeq("", aGen); + } + + void testFibonacci(Tester t) { + init(); + t.checkExpect(f.get(), 0); + t.checkExpect(f.get(), 1); + t.checkExpect(f.get(), 1); + t.checkExpect(f.get(), 2); + t.checkExpect(f.get(), 3); + t.checkExpect(f.get(), 5); + t.checkExpect(f.get(), 8); + } + + void testASeq(Tester t) { + init(); + t.checkExpect(a.get(), ""); + t.checkExpect(a.get(), "a"); + t.checkExpect(a.get(), "aa"); + t.checkExpect(a.get(), "aaa"); + t.checkExpect(a.get(), "aaaa"); + t.checkExpect(a.get(), "aaaaa"); + } +} + +// A generic list. +interface ILo {} + +class Cons implements ILo { + + A first; + ILo rest; + + Cons(A first, ILo rest) { + this.first = first; + this.rest = rest; + } +} + +class Mt implements ILo {} + +interface ISequence { + // Returns the current element in the sequence. + // EFFECT: Updates the state to the next element in the sequence. + X get(); +} + +// Sequence generator method. +interface ISeqGen { + X gen(X state); // Generates the next value in the sequence given the current state. +} + +// The Fibonacci sequence. +class Fibonacci implements ISequence { + + int idx; // Number of times `get()` has been called. + int pre; // The previous (last) number. + int pen; // The penultimate (second to last) number. + + Fibonacci() { + this.pen = 0; + this.pre = 1; + } + + // Get the next in the sequence. + public Integer get() { + int ret; // What to return. + /* + + idx pen pre ret + 0 0 1 0 + 1 0 1 1 + 2 1 1 2 + 3 1 2 3 + 4 2 3 5 + 5 3 5 8 + + */ + + // F(0) = 0; F(1) = 1 + if (this.idx <= 1) ret = this.idx; + else { // F(n) = F(n-1) + F(n-2) + ret = this.pre + this.pen; + + this.pen = this.pre; + this.pre = ret; + } + + this.idx = this.idx + 1; + return ret; + } +} + +// A generic sequence. +class GenSeq implements ISequence { + + X state; // The current state of the sequence. + ISeqGen seqGen; // The method by which new values are generated. + + // Create new generic sequence given an initial state. + GenSeq(X init, ISeqGen seqGen) { + this.state = init; + this.seqGen = seqGen; + } + + public X get() { + X ret = this.state; + this.state = this.seqGen.gen(this.state); + return ret; + } +} + +// A string of n "a"s. +class AGen implements ISeqGen { + + public String gen(String state) { + return state.concat("a"); + } +} + +class SimpleMarkov implements ISeqGen { + + public String gen(String state) { + return null; + } +} + +// The probability of a word. +class ProbPair { + + String word; // The word itself. + int count; // The number of times the word has appeared after this word. + + ProbPair(String word, int count) { + this.word = word; + this.count = count; + } +} + +// The probable completions for a word. +class Completion { + + String word; // The word the completions are for. + ILo completions; //The probable completions. + + Completion(String word, ILo completions) { + this.word = word; + this.completions = completions; + } +} + +// The list of all known completions. +class CompletionTable { + + ILo table; + + CompletionTable(ILo table) { + this.table = table; + } +} + +static class ProcessInput {} diff --git a/generics/.project b/generics/.project index 520a6cf..0d9abd9 100644 --- a/generics/.project +++ b/generics/.project @@ -14,4 +14,15 @@ org.eclipse.jdt.core.javanature + + + 1731947415563 + + 30 + + org.eclipse.core.resources.regexFilterMatcher + node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__ + + +