I made changes from codes and suggestions in comments and answers. Pairs = morse_file_to_dict('morse_alphabet.txt')īUT, the answer should be: 10571 words, not 5 If word_to_morse(word, my_dict) = given_morse: If my_dict = given_morse)] and len(word) < 10:Īdding_to_set(given_morse, my_set, my_dict, word, start) Return dict(line.strip().split() for line in file)ĭef adding_to_set(given_morse, my_set, my_dict, word='', start=0): My code looks like this: def morse_file_to_dict(filename): The given file with the letters and the morse code to it looks like this: A. The length of the decoded word can be maximum 10 letters. Maybe I will try bonus 2 later.I had to find all the possible letter combinations in a given morse code. The sound of non directional beacon WG, on. Full search on bonus 1 input takes 1m35s to complete. Some modern navigation receivers automatically translate the code into displayed letters. Runs in 0.7s for bonus 1, stopping search after first output found. => oqmgztykcxndbjpwalevrsfhuiĬ with bonus 1, greedy algorithm that tries longest code first.ĮDIT 2 New version with comments and now handling full/partial search and verbose/silent mode as program arguments. => oqmgztyknxcdbjruiwalsfhvepīut not guaranteed to be the best one as search is going on. Thanks to u/Separate_Memory for inspiring this week's challenges on r/dailyprogrammer_ideas!īonus 2 found the below morse code using an exhaustive search program. That is, I'll look at the first character where the two strings differ and award the one with a dash ( -) in that position, since - is before. Then scan the code representation for letter and its code, building the tree by going left for a ' and right for a '- This part of the project should be done manually (see below) Your program will use this tree to decode Morse code into English. I'll break ties by taking the lexicographically first string. Complete it in the following way: Start with a signal node that contains no letter. -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-Ĭan you do better? When this post is 7 days old, I'll award +1 gold medal flair to the submission with the fewest possible decodings. The following encoded string has 41 decodings. The object of this bonus challenge is to find a valid input with as few possible outputs as possible, while still having at least 1. Typically, a valid input will have thousands of possible outputs. How fast can you find the output for all of them? A good time depends on your language of choice and setup, so there's no specific time to aim for. Input Format: Decoder: Use one space to seperate letters and two spaces to seperate words. Encoder Logic: Used the hashtable (alphabets only as of yet). Smalpha(".-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.")Īgain, there's more than one valid output for these inputs. Decoder Logic: Implemented 4 levels of the following tree for decoding. It's not enough to write a program that will eventually finish after a very long period of time: run your code through to completion for at least one example. Given a smooshed Morse code encoding of a permutation of the alphabet, find the permutation it encodes, or any other permutation that produces the same encoding (in general there will be more than one). See this week's Easy challenge for more detail.Ī permutation of the alphabet is a 26-character string in which each of the letters a through z appears once. Smooshed Morse code means Morse code with the spaces or other delimiters between encoded letters left out. IRC Channel Message the Moderators Challenge List in Chronological Order To help the community and write your own challenge to be submitted, head on over to /r/DailyProgrammer_Ideas and share your project - read the sidebar in that subreddit for more information. Otherwise, read the Solution Submission Tutorial for a walkthrough of submitting a solution, or click below to message the moderators for assistance. If you are a new or unverified account, and are unable to post comment replies, please click here to verify your account. First time visitors of Daily Programmer please Read the Wiki to learn everything about this subreddit.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |