Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Include median value in stats/1

  • Loading branch information...
commit 98bf793397324322c51f2fd35e08df43edd93e99 1 parent f19c964
Andreas Pauley authored March 25, 2011

Showing 2 changed files with 7 additions and 5 deletions. Show diff stats Hide diff stats

  1. 9  sudoku.erl
  2. 3  unittests.erl
9  sudoku.erl
@@ -233,21 +233,22 @@ print_results(Filename, Seperator) ->
233 233
     Solved = filter(fun(Puzzle) -> is_solved(Puzzle) end, Solutions),
234 234
     TimeInSeconds = Time/1000000,
235 235
     Eliminations = [Count|| {_, Count} <- Solutions],
236  
-    {Total, Avg, Max, Min, NumberPuzzles} = stats(Eliminations),
  236
+    {Total, Avg, Med, Max, Min, NumberPuzzles} = stats(Eliminations),
237 237
     Hz = NumberPuzzles/TimeInSeconds,
238 238
     Msg = "Solved ~p of ~p puzzles from ~s in ~f secs (~.2f Hz)
239  
-  (~p total eliminations, avg ~.2f, max ~p, min ~p)~n",
  239
+  (~p total eliminations, avg ~.2f, median ~p, max ~p, min ~p)~n",
240 240
     io:format(Msg,
241 241
               [length(Solved), NumberPuzzles, Filename, TimeInSeconds, Hz,
242  
-               Total, Avg, Max, Min]).
  242
+               Total, Avg, Med, Max, Min]).
243 243
 
244 244
 stats(List) ->
245 245
     Total = sum(List),
246 246
     Length = length(List),
247 247
     Avg = Total/Length,
  248
+    Med = lists:nth(round((Length/2)), sort(List)),
248 249
     Max = lists:max(List),
249 250
     Min = lists:min(List),
250  
-    {Total, Avg, Max, Min, Length}.
  251
+    {Total, Avg, Med, Max, Min, Length}.
251 252
 
252 253
 shallow_flatten([]) -> [];
253 254
 shallow_flatten([H|T]) ->
3  unittests.erl
@@ -218,9 +218,10 @@ test_to_string() ->
218 218
     ok.
219 219
 
220 220
 test_stats() ->
221  
-    {Total, Avg, Max, Min, Length} = stats([2, 9, 4]),
  221
+    {Total, Avg, Med, Max, Min, Length} = stats([2, 9, 4]),
222 222
     15 = Total,
223 223
     5.0 = Avg,
  224
+    4 = Med,
224 225
     9 = Max,
225 226
     2 = Min,
226 227
     3 = Length,

0 notes on commit 98bf793

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