are_we_fast_yet/permute.fz
# ported from https://github.com/smarr/are-we-fast-yet/blob/master/benchmarks/Java/src/Permute.java
public permute
post result = 8660
=>
mi : mutate is
mi.go ()->
count := mut 0
marr := (mutate.array i32).type.new mi 6 0
swap(i i32, j i32)
# pre i != j
is
tmp := marr[i]
marr[i] := marr[j]
marr[j] := tmp
permute(n i32) is
count <- count.get + 1
if !n.is_zero
n1 := n - 1
permute n1
for i in (-n1..0) do
swap n1 -i
permute n1
swap n1 -i
permute 6
count.get
last changed: 2023-11-14