-
-
Save CamonZ/5435712e519bfdaa82995e60bed87e28 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Remaining keys: ["1", "10"] - Current Key: 1 - Current bin: 0 - Acc: 0 | |
Remaining keys: ["1", "10"] - Current Key: 1 - Current bin: 1 - Acc: 0 | |
Remaining keys: ["10"] - Current Key: 10 - Current bin: 1 - Acc: 150 | |
Remaining keys: ["10"] - Current Key: 10 - Current bin: 2 - Acc: 0 | |
Remaining keys: ["10"] - Current Key: 10 - Current bin: 3 - Acc: 0 | |
Remaining keys: ["10"] - Current Key: 10 - Current bin: 4 - Acc: 0 | |
Remaining keys: ["10"] - Current Key: 10 - Current bin: 5 - Acc: 0 | |
Remaining keys: ["10"] - Current Key: 10 - Current bin: 6 - Acc: 0 | |
Remaining keys: ["10"] - Current Key: 10 - Current bin: 7 - Acc: 0 | |
Remaining keys: ["10"] - Current Key: 10 - Current bin: 8 - Acc: 0 | |
Remaining keys: ["10"] - Current Key: 10 - Current bin: 9 - Acc: 0 | |
Remaining keys: ["10"] - Current Key: 10 - Current bin: 10 - Acc: 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{_, aggregated_map} = expected_bins_keys | |
|> sort_by_numeric_value() | |
|> Enum.reduce({aggregated_keys, %{}}, fn(bin, {keys_list, acc_map}) -> # iterating over each expected key | |
{acc_count, updated_keys_list} = | |
Enum.reduce_while(keys_list, {0, keys_list}, fn (key, {acc, remaining_keys}) -> | |
IO.puts "Remaining keys: #{inspect remaining_keys} - Current Key: #{key} - Current bin: #{bin} - Acc: #{acc}" | |
if to_integer(key) <= to_integer(bin) do | |
{:cont, {acc + Map.get(aggregated_data, key), List.delete(remaining_keys, key)}} | |
else | |
{:halt, {acc, remaining_keys}} | |
end | |
end) | |
{updated_keys_list, Map.put(acc_map, bin, acc_count)} | |
end) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment