Skip to content
Browse files

Include list length in stats

  • Loading branch information...
1 parent fad04d1 commit f19c964967415111c7a641bddd132a4c1efedbfb @apauley committed Mar 25, 2011
Showing with 7 additions and 6 deletions.
  1. +5 −5 sudoku.erl
  2. +2 −1 unittests.erl
View
10 sudoku.erl
@@ -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,
@@ -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]) ->
View
3 unittests.erl
@@ -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) ->

0 comments on commit f19c964

Please sign in to comment.
Something went wrong with that request. Please try again.