kdb programming challenge – Morse Code

AquaQ Admin kdb+ 7 Comments

Morse Code

dit dit dit – dah dah dah – dit dit dit

“dit dit dit dit – dit dit” We hear this noise in films, war documentaries and even in everyday life. What is this adorable little sound of melody? Yes you are right. This is not just any random sound generated by highly skilled operator (myself) using this little clicking thingy, but THE Morse Code itself. It is just a fancy way of saying “hi”!

And today we have no less than an old school Morse Code challenge (with a bit of my twist). Why? Well, the story is that few days ago an explosion happened in the office (reason unknown) and the staff – all Morse Code experts – are now deaf. Despite the explosion we still have desktops, keyboards and mice for work ;). Due to budget constraints, our CEO decided to hire a junior Morse Code operator as a secretary to handle calls and stuff. One day, we received an important call from our analyst and our operator translated everything to Morse Code. Disaster! We ran out of ink! So we are left with a blank piece of paper with no message on it. But the good thing is we always keep a log of the timestamps when the operator hits the transmitter.

Here is the log we have. Can you parse the log and find out what the message is? Oh and one last thing:


--. --- --- -..|.-.. ..- -.-. -.-|.- -. -..|.... .- ...- .|..-. ..- -.|.-- .. - ....|- .... .|-.-. .... .- .-.. .-.. . -. --. .
AquaQ Adminkdb programming challenge – Morse Code

Comments 7

  1. Pingback: Morse code kdb+ programmer challenge

  2. Nikita

    Interesting. From wikipedia it seems that “. ” and “-” gives you similar difference between hits.
    “. ” is one unit for beep and three units between letters.
    “-” is three units for beep and one unit between parts within letter.
    If you look at your analysis you can see really 5 levels not six, how did you come up with the rule that 350-400ms is “. ” and 400… is :”-“?
    What is 50 actually? If it’s unit than it’s incorrect as “.” should be 100 not 150, etc

    Do I miss something?

    1. WooiKent Lee

      Hi Nikita, I’ve mentioned that:

      (this problem doesn’t follow the exact unit measurement of waiting time, junior operator is still learning his morse code!)

      So the unit of measurement in wiki doesn’t apply in this problem. You will have to look at the data and figure out which one is which.

    1. WooiKent Lee

      Thanks! The log is generated by preparing the message and pre-setting the time unit for each notation:

      q)l:"to the magnificent aquaq employees, we have finally produced the result of this friday's euromillions lottery numbers. we believe this is a 99.99 percent chance of winning the 100 million euro pool. so the numbers are 5 11 23 29 43 and the luck stars are 1 7."
      q)s:".- |"!150 400 200 900

      The message is then translated into morse code using the “m” dictionary from the solution:

      q)"|"sv" "sv'string m?/:" "vs l

      The morse code is then indexed to the “s” dictionary:

      q)s"|"sv" "sv'string m?/:" "vs l

      But this makes the problem a bit simple, so I add in some noises:

      q)s[r]+count[r:"|"sv" "sv'string m?/:" "vs l]?10

      Now add the time unit for “. ” “.|” “- ” “-|” together to obtain the true waiting time. First cut time units:

      q)where[not r in" |"]cut s[r]+count[r:"|"sv" "sv'string m?/:" "vs l]?10

      and do the sums:

      q)sums sum@'where[not r in" |"]cut s[r]+count[r:"|"sv" "sv'string m?/:" "vs l]?10

      Add the sums to a time and omit the last time (don’t want the end time of transmission):

      q)-1_.z.t+0,sums sum@'where[not r in" |"]cut s[r]+count[r:"|"sv" "sv'string m?/:" "vs l]?10

      Lastly change the time to unix format:

      q)"Fri, 13 Feb 2015 ",/:string -1_.z.t+0,sums sum@'where[not r in" |"]cut s[r]+count[r:"|"sv" "sv'string m?/:" "vs l]?10

      and save to a file:

      q)`:mc_log_20150213.log 0:"Fri, 13 Feb 2015 ",/:string -1_.z.t+0,sums sum@'where[not r in" |"]cut s[r]+count[r:"|"sv" "sv'string m?/:" "vs l]?10

      Wish I have something here that can generate the log more realistically but here you go 🙂

  3. luffy

    200 0 2020 22 200 0 2020 222 22 2002 0200 0 2 0 😀
    “good luck and have lun emith the challenge”

Leave a Reply

Your email address will not be published. Required fields are marked *

To create code blocks or other preformatted text, indent by four spaces:

    This will be displayed in a monospaced font. The first four 
    spaces will be stripped off, but all other whitespace
    will be preserved.
    
    Markdown is turned off in code blocks:
     [This is not a link](http://example.com)

To create not a block, but an inline code span, use backticks:

Here is some inline `code`.

For more help see http://daringfireball.net/projects/markdown/syntax