are_we_fast_yet/queens.fz
# ported from https://github.com/smarr/are-we-fast-yet/blob/master/benchmarks/Java/src/Queens.java
public queens bool
post result
is
mi : mutate is
mi.go ()->
run_queens bool is
free_rows := (mutate.array bool).type.new mi 8 true
free_maxs := (mutate.array bool).type.new mi 16 true
free_mins := (mutate.array bool).type.new mi 16 true
queen_rows := (mutate.array i32).type.new mi 8 -1
place_queen(c i32) bool is
return := mut false
for r in 0..7
do
if get_row_column r c
queen_rows[r] := c
set_row_column r c false
if c = 7
return <- true
else if place_queen (c+1)
return <- true
else
set_row_column r c true
until return.get
return.get
get_row_column(r,c i32)=>
free_rows[r] && free_maxs[c+r] && free_mins[c-r+7]
set_row_column(r,c i32, v bool) =>
free_rows[r ] := v
free_maxs[c + r ] := v
free_mins[c - r + 7] := v
place_queen 0
(1..10) ∀ (_ -> run_queens)
last changed: 2023-11-14