File: solve-async-lua.lp

package info (click to toggle)
gringo 4.4.0-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 8,260 kB
  • ctags: 10,755
  • sloc: cpp: 55,049; python: 629; yacc: 569; sh: 124; makefile: 23
file content (23 lines) | stat: -rw-r--r-- 503 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#script(lua)

function make_on_finish(stop)
    return function (ret, interrupted)
        stop[1] = true
    end
end

function main(prg)
    stop = {false}
    prg:ground({{"base", {}}})
    future, n, m = prg:solve_async(nil, nil, make_on_finish(stop)), 0, 0
    while not stop[1] do
        x, y, m = math.random(), math.random(), m+1
        if x * x + y * y < 1 then
            n = n + 1
        end
    end
    future:wait()
    print(string.format("approximation of pi: %f", 4.*n/m))
end

#end.