1
2
3
4
5
6
7
8public
9class Hamilton {
10 public
11 static
12 void main(String[] argv) {
13 printSequence("Hamilton",
14 20,
15 hamilton());
16 printSequence("sum of Fibonacci",
17 20,
18 new Sum(new Fibonacci()));
19 printSequence("sum of n^2",
20 20,
21 new Sum(new Power(new Count(),2)));
22 printSequence("diff of sum of Fibonacci",
23 20,
24 new Diff(new Sum(new Fibonacci())));
25
26 }
27
28 public
29 static
30 void
31 printSequence(String title,
32 int limit,
33 Sequence s) {
34
35 System.out.println(title);
36
37 for (int i = 0;
38 i < limit;
39 ++i) {
40 System.out.println("\t" + i + ":\t" + s.next());
41 }
42
43 System.out.println("");
44 }
45
46 public
47 static
48 Sequence hamilton() {
49 Sequence s2 = new Scale(2, new Count());
50 Sequence s3 = new Scale(3, new Count());
51 Sequence s5 = new Scale(5, new Count());
52
53 Sequence m23 = new Merge(s2, s3);
54 Sequence m235 = new Merge(m23, s5);
55
56 return
57 new Unique(m235);
58 }
59
60}
61
62