This file contains hidden or 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
| def decode(morse_string, target_checksum): | |
| """ | |
| Decode a compact Morse code string and return all valid interpretations | |
| that match the given checksum. | |
| Args: | |
| morse_string: String of dots and dashes without pauses | |
| target_checksum: The expected checksum value | |
| Returns: |
This file contains hidden or 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
| #include <iostream> | |
| #include <algorithm> | |
| #include <functional> | |
| #include <queue> | |
| using namespace std; | |
| int main(int argc, char** argv) | |
| { | |
| priority_queue<int, vector<int>, function<bool(int,int)>> |
This file contains hidden or 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
| if (min_heap.size() == max_heap.size()) | |
| { | |
| if (u < max_heap.top()) | |
| { | |
| max_heap.push(u); | |
| total += max_heap.top(); | |
| } | |
| else | |
| { | |
| min_heap.push(u); |
This file contains hidden or 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
| defmodule Inversion do | |
| def summarize(a, b, acc, list_acc) do | |
| case {a, b} do | |
| {[], []} -> {list_acc, acc} | |
| {a, []} -> {list_acc ++ a, acc} | |
| {[], b} -> {list_acc ++ b, acc} | |
| {a,b} when hd(a) > hd(b) -> summarize(a, tl(b), length(a) + acc, list_acc ++ [hd(b)]) | |
| {a,b} when hd(a) <= hd(b) -> summarize(tl(a), b, acc, list_acc ++ [hd(a)]) | |
| end |
This file contains hidden or 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
| defmodule Inversion do | |
| def summarize(a, b, acc, list_acc) do | |
| case {a, b} do | |
| {[], []} -> {list_acc, acc} | |
| {a, []} -> {Enum.reverse(a) ++ list_acc, acc} | |
| {[], b} -> {Enum.revserse(b) ++ list_acc, acc} | |
| {a,b} when hd(a) > hd(b) -> summarize(a, tl(b), length(a) + acc, [hd(b) | list_acc]) | |
| {a,b} when hd(a) <= hd(b) -> summarize(tl(a), b, acc, [hd(a) | list_acc]) | |
| end |