Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You can use <a href="http://www.erlang.org/doc/man/timer.html#tc-1" rel="nofollow">timer</a> module to check speed of execution:</p> <pre><code>{Time, Value} = timer:tc(queen, queen, [N]) </code></pre> <p>Or you can transform you code to escript:</p> <pre><code>#!/usr/bin/env escript -mode(native). %% to fun faster main([NStr]) -&gt; N = list_to_integer(NStr), IJ = [{I, J} || I &lt;- lists:seq(1, N), J &lt;- lists:seq(1, N)], lists:foreach(fun({I, J}) -&gt; put_data(I, J, true) end, IJ), solve(N, 1, [], 0). solve(N, J, Board, Count) when N &lt; J -&gt; print(N, Board), Count + 1; solve(N, J, Board, Count) -&gt; F = fun(I, Cnt) -&gt; case get_data(I, J) of true -&gt; put_data(I, J, false), Cnt2 = solve(N, J+1, [I|Board], Cnt), put_data(I, J, true), Cnt2; false -&gt; Cnt end end, lists:foldl(F, Count, lists:seq(1, N)). put_data(I, J, Bool) -&gt; put({row, I }, Bool), put({add, I+J}, Bool), put({sub, I-J}, Bool). get_data(I, J) -&gt; get({row, I}) andalso get({add, I+J}) andalso get({sub, I-J}). print(N, Board) -&gt; Frame = "+-" ++ string:copies("--", N) ++ "+", io:format("~s~n", [Frame]), lists:foreach(fun(I) -&gt; print_line(N, I) end, Board), io:format("~s~n", [Frame]). print_line(N, I) -&gt; F = fun(X, S) when X == I -&gt; "Q " ++ S; (_, S) -&gt; ". " ++ S end, Line = lists:foldl(F, "", lists:seq(1, N)), io:format("| ~s|~n", [Line]). </code></pre> <p>and make it executable from linux shell:</p> <pre><code>chmod +x queue </code></pre> <p>And then run it from linux shell with command <code>./queue</code> or <code>time ./queue</code></p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload