aboutsummaryrefslogtreecommitdiff
path: root/test/235.go
diff options
context:
space:
mode:
authorRobert Griesemer <gri@golang.org>2008-09-12 17:39:29 -0700
committerRobert Griesemer <gri@golang.org>2008-09-12 17:39:29 -0700
commitddc7bc5aba8239ae1f83261ce1afb27f0ab0889e (patch)
tree3f2bfe5ef1f203433058e7873cfd561f8dc4d22c /test/235.go
parent904d4045d35605732a7b0abf1c6bc247904b6a4d (diff)
downloadgo-ddc7bc5aba8239ae1f83261ce1afb27f0ab0889e.tar.gz
go-ddc7bc5aba8239ae1f83261ce1afb27f0ab0889e.zip
test program to generate multiples of a set of factors
(as written, factors are 2, 3, and 5) R=r OCL=15286 CL=15286
Diffstat (limited to 'test/235.go')
-rw-r--r--test/235.go61
1 files changed, 61 insertions, 0 deletions
diff --git a/test/235.go b/test/235.go
new file mode 100644
index 0000000000..48bf601973
--- /dev/null
+++ b/test/235.go
@@ -0,0 +1,61 @@
+// $G $F.go && $L $F.$A && ./$A.out
+
+// Copyright 2009 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+package main
+
+type T chan uint64;
+
+func M(f uint64) (in, out *T) {
+ in = new(T, 100);
+ out = new(T, 100);
+ go func(in, out *T, f uint64) {
+ for {
+ out -< f * <- in;
+ }
+ }(in, out, f);
+ return in, out;
+}
+
+
+func min(xs *[]uint64) uint64 {
+ m := xs[0];
+ for i := 1; i < len(xs); i++ {
+ if xs[i] < m {
+ m = xs[i];
+ }
+ }
+ return m;
+}
+
+
+func main() {
+ F := []uint64{2, 3, 5};
+ const n = len(F);
+
+ x := uint64(1);
+ ins := new([]*T, n);
+ outs := new([]*T, n);
+ xs := new([]uint64, n);
+ for i := 0; i < n; i++ {
+ ins[i], outs[i] = M(F[i]);
+ xs[i] = x;
+ }
+
+ for i := 0; i < 100; i++ {
+ t := min(xs);
+ for i := 0; i < n; i++ {
+ ins[i] -< x;
+ }
+
+ for i := 0; i < n; i++ {
+ if xs[i] == x { xs[i] = <- outs[i]; }
+ }
+
+ x = min(xs);
+ print(x, "\n");
+ }
+ sys.exit(0);
+}