Sync
This commit is contained in:
parent
6f050a029e
commit
776bba907c
3887 changed files with 59894 additions and 7280 deletions
|
|
@ -0,0 +1,18 @@
|
|||
-module(beadsort).
|
||||
|
||||
-export([sort/1]).
|
||||
|
||||
sort(L) ->
|
||||
dist(dist(L)).
|
||||
|
||||
dist(L) when is_list(L) ->
|
||||
lists:foldl(fun (N, Acc) -> dist(Acc, N, []) end, [], L).
|
||||
|
||||
dist([H | T], N, Acc) when N > 0 ->
|
||||
dist(T, N - 1, [H + 1 | Acc]);
|
||||
dist([], N, Acc) when N > 0 ->
|
||||
dist([], N - 1, [1 | Acc]);
|
||||
dist([H | T], 0, Acc) ->
|
||||
dist(T, 0, [H | Acc]);
|
||||
dist([], 0, Acc) ->
|
||||
lists:reverse(Acc).
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
1> beadsort:sort([1,734,24,3,324,324,32,432,42,3,4,1,1]).
|
||||
[734,432,324,324,42,32,24,4,3,3,1,1,1]
|
||||
Loading…
Add table
Add a link
Reference in a new issue