Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Add the Fannkuch-redux benchmark.

  • Loading branch information...
commit 3d76c4705847185cfa3701ff2dbcfaf33699f89f 1 parent b250641
@ltratt authored
View
1  examples/benchmarks/.gitignore
@@ -1,2 +1,3 @@
cvstone
+fannkuch-redux
richards
View
7 examples/benchmarks/Makefile.in
@@ -1,17 +1,20 @@
include @abs_top_srcdir@/Makefile.inc
-all: cvstone richards
+all: cvstone fannkuch-redux richards
cvstone: cvstone.cv
${CONVERGE_VM} ${CONVERGEC} -m cvstone.cv
+fannkuch-redux: fannkuch-redux.cv
+ ${CONVERGE_VM} ${CONVERGEC} -m fannkuch-redux.cv
+
richards: richards.cv
${CONVERGE_VM} ${CONVERGEC} -m richards.cv
install:
clean:
- rm -f cvstone cvstone.cvb richards richards.cvb
+ rm -f cvstone cvstone.cvb fannkuch-redux fannkuch-redux.cvb richards richards.cvb
distclean: clean
rm -f Makefile
View
77 examples/benchmarks/fannkuch-redux.cv
@@ -0,0 +1,77 @@
+// The Computer Language Benchmarks Game
+// http://shootout.alioth.debian.org/
+
+// contributed by Isaac Gouy
+// converted to Java by Oleg Mazurov
+// converted to Python by Buck Golemon
+// modified by Justin Peel
+// converted to Converge by Laurence Tratt
+
+import Builtins, Strings, Sys
+
+func range(n):
+ t := []
+ i := 0
+ while i < n:
+ t.append(i)
+ i += 1
+ return t
+
+func fannkuch(n):
+ maxFlipsCount := 0
+ permSign := 1
+ checksum := 0
+
+ perm1 := range(n)
+ count := perm1[:]
+ nm := n - 1
+ while 1:
+ k := perm1[0]
+ if k != 0:
+ perm := perm1[:]
+ flipsCount := 1
+ kk := perm[k]
+ while kk != 0:
+ i := 0
+ while i <= k / 2:
+ t := perm[i]
+ perm[i] := perm[k - i]
+ perm[k - i] := t
+ i += 1
+ flipsCount += 1
+ k := kk
+ kk := perm[kk]
+ if maxFlipsCount < flipsCount:
+ maxFlipsCount := flipsCount
+ if permSign == 1:
+ checksum += flipsCount
+ else:
+ checksum += -flipsCount
+
+ // Use incremental change to generate another permutation
+ if permSign == 1:
+ t := perm1[0]
+ perm1[0],perm1[1] := [perm1[1],perm1[0]]
+ permSign := 0
+ else:
+ perm1[1],perm1[2] := [perm1[2],perm1[1]]
+ permSign := 1
+ r := 2
+ while r < n - 1:
+ if count[r] != 0:
+ break
+ count[r] := r
+ perm0 := perm1[0]
+ perm1[:r+1] := perm1[1:r+2]
+ perm1[r+1] := perm0
+ r += 1
+ exhausted:
+ r := nm
+ if count[r] == 0:
+ Sys::println(checksum)
+ return maxFlipsCount
+ count[r] -= 1
+
+func main():
+ n := Builtins::Int.new(Sys::argv[0])
+ Sys::println(Strings::format("Pfannkuchen(%d) = %d", n, fannkuch(n)))
Please sign in to comment.
Something went wrong with that request. Please try again.