Skip to content

Commit

Permalink
Include list length in stats
Browse files Browse the repository at this point in the history
  • Loading branch information
Andreas Pauley committed Mar 25, 2011
1 parent fad04d1 commit f19c964
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
10 changes: 5 additions & 5 deletions sudoku.erl
Expand Up @@ -232,10 +232,9 @@ print_results(Filename, Seperator) ->
{Time, Solutions} = timer:tc(sudoku, solve_file, [Filename, Seperator]),
Solved = filter(fun(Puzzle) -> is_solved(Puzzle) end, Solutions),
TimeInSeconds = Time/1000000,
NumberPuzzles = length(Solutions),
Hz = NumberPuzzles/TimeInSeconds,
Eliminations = [Count|| {_, Count} <- Solutions],
{Total, Avg, Max, Min} = stats(Eliminations),
{Total, Avg, Max, Min, NumberPuzzles} = stats(Eliminations),
Hz = NumberPuzzles/TimeInSeconds,
Msg = "Solved ~p of ~p puzzles from ~s in ~f secs (~.2f Hz)
(~p total eliminations, avg ~.2f, max ~p, min ~p)~n",
io:format(Msg,
Expand All @@ -244,10 +243,11 @@ print_results(Filename, Seperator) ->

stats(List) ->
Total = sum(List),
Avg = Total/length(List),
Length = length(List),
Avg = Total/Length,
Max = lists:max(List),
Min = lists:min(List),
{Total, Avg, Max, Min}.
{Total, Avg, Max, Min, Length}.

shallow_flatten([]) -> [];
shallow_flatten([H|T]) ->
Expand Down
3 changes: 2 additions & 1 deletion unittests.erl
Expand Up @@ -218,11 +218,12 @@ test_to_string() ->
ok.

test_stats() ->
{Total, Avg, Max, Min} = stats([2, 9, 4]),
{Total, Avg, Max, Min, Length} = stats([2, 9, 4]),
15 = Total,
5.0 = Avg,
9 = Max,
2 = Min,
3 = Length,
ok.

is_sudoku_puzzle(Puzzle) ->
Expand Down

0 comments on commit f19c964

Please sign in to comment.