Skip to content

Instantly share code, notes, and snippets.

@CamonZ

CamonZ/run.txt Secret

Created April 19, 2018 05:20
Show Gist options
  • Save CamonZ/5435712e519bfdaa82995e60bed87e28 to your computer and use it in GitHub Desktop.
Save CamonZ/5435712e519bfdaa82995e60bed87e28 to your computer and use it in GitHub Desktop.
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
{_, 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