예제 #1
0
        private async Task <long> RunAndMeasureElapsedMs()
        {
            string morse = "--.----.......-.---.--......-..";

            ISet <string> dictionary = new HashSet <string>
            {
                "GOD", "IS", "NO", "NOW", "HERE", "WHERE",
                "HER", "GO", "ME", "MED", "MOD", "MO",
            };

            this.decoder = new MorseDecoder()
            {
                MorseSequence      = morse,
                FirstLetters       = MorseDecoderTests.GetFirstLetters(dictionary),
                WordsByFirstLetter = MorseDecoderTests.GetWordsByFirstLetter(dictionary)
            };

            Stopwatch stopwatch = new Stopwatch();

            stopwatch.Start();
            await this.decoder.DecodeMorseSequenceAsync();

            stopwatch.Stop();
            return(stopwatch.ElapsedMilliseconds);
        }
예제 #2
0
        private static void Main()
        {
            IInputReader inputReader = Program.GetInputReader();

            string L = inputReader.ReadLine();
            int    N = int.Parse(inputReader.ReadLine());

            MorseDecoder decoder = new MorseDecoder();

            for (int i = 0; i < N; i++)
            {
                string W = inputReader.ReadLine();

                if (!decoder.WordsByFirstLetter.ContainsKey(W[0]))
                {
                    decoder.WordsByFirstLetter[W[0]] = new HashSet <string>();
                }

                decoder.WordsByFirstLetter[W[0]].Add(W);
                decoder.FirstLetters.Add(W[0]);
            }

            inputReader.Dispose();

            Console.WriteLine(decoder.DecodeAndReturnMessagesCountAsync(L).GetAwaiter().GetResult());
            Console.Read();
        }
예제 #3
0
        public static void TestMeliMessage()
        {
            string meliMessage  = "000000001101101100111000001111110001111110011111100000001110111111110111011100000001100011111100000111111001111110000000110000110111111110111011100000011011100000000000";
            string morseMessage = MorseDecoder.decodeBits2Morse(meliMessage);

            Console.WriteLine(morseMessage);
            Console.WriteLine(MorseDecoder.translate2Human(morseMessage));
        }
예제 #4
0
        static void Main(string[] args)
        {
            bool   continueMessage = true;
            string message         = string.Empty;

            //TestMeliMessage();
            //Console.ReadKey();

            do
            {
                Stopwatch stopwatch = new Stopwatch();

                stopwatch.Start();
                string inputStr = Console.ReadLine();

                stopwatch.Stop();

                long pause = (stopwatch.ElapsedMilliseconds / 800);

                string zeros = string.Empty;

                for (int i = 0; i < pause; i++)
                {
                    zeros += "0";
                }

                message += inputStr + zeros;

                Console.Clear();
                Console.Write(message);

                continueMessage = pause < 10;
            } while (continueMessage);


            string morseParagraph = MorseDecoder.decodeBits2Morse(message);

            List <string> wordsToTRanslate = morseParagraph.Split(MorseDecoder.LetterSeparator).ToList();

            string traslated = string.Empty;

            foreach (var item in wordsToTRanslate)
            {
                string letter = MorseDecoder.TranslateMorseToLetter(item);
                if (letter == "stop")
                {
                    break;
                }

                traslated += letter;
            }

            Console.WriteLine($"Decoded  : {morseParagraph}");
            Console.WriteLine($"Input Traslated: {traslated}");
            Console.ReadLine();
        }
예제 #5
0
        public void Setup()
        {
            ISet <string> dictionary = MorseDecoderTests.GetDefaultDictionary();

            this.decoder = new MorseDecoder()
            {
                MorseSequence      = "--.----.......-.---.--......-..",
                FirstLetters       = MorseDecoderTests.GetFirstLetters(dictionary),
                WordsByFirstLetter = MorseDecoderTests.GetWordsByFirstLetter(dictionary)
            };
        }
        public IActionResult TranslateToMorse(MorseRequest request)
        {
            return(ExecuteResponse(() =>
            {
                MorseResponse morseResponse = new MorseResponse();

                morseResponse.Response = MorseDecoder.traslate2Morse(request.Text);
                morseResponse.Code = StatusCodes.Status200OK;

                return morseResponse;
            }));
        }
        public void WriteToOutputFile()
        {
            MorseDecoder decoder = new MorseDecoder();

            decoder.Decode("../Files/input.txt", "../Files/outputTest.txt");

            FileInfo fileInfo = new FileInfo("../Files/outputTest.txt");

            if (fileInfo.Length > 0)
            {
                Assert.IsFalse(false);
            }
            else
            {
                Assert.IsFalse(true);
            }
        }
예제 #8
0
        public async Task TestHelloWorld()
        {
            ISet <string> dictionary = new HashSet <string>
            {
                "HELL", "HELLO", "OWORLD", "WORLD", "TEST"
            };

            this.decoder = new MorseDecoder()
            {
                MorseSequence      = "......-...-..---.-----.-..-..-..",
                FirstLetters       = MorseDecoderTests.GetFirstLetters(dictionary),
                WordsByFirstLetter = MorseDecoderTests.GetWordsByFirstLetter(dictionary)
            };

            await this.decoder.DecodeMorseSequenceAsync();

            Assert.AreEqual(2, this.decoder.DecodedMessageCount);
        }
예제 #9
0
        public void TestDecodeMorse()
        {
            string morse = "--.-";

            ISet <string> dictionary = new HashSet <string>
            {
                "MA", "G", "M", "A", "T", "TNT"
            };

            this.decoder = new MorseDecoder()
            {
                FirstLetters       = MorseDecoderTests.GetFirstLetters(dictionary),
                WordsByFirstLetter = MorseDecoderTests.GetWordsByFirstLetter(dictionary)
            };

            ISet <KeyValuePair <string, string> > result = this.decoder.DecodeMorse(morse);

            Assert.AreEqual(6, result.Count);
        }
예제 #10
0
        static void Main(string[] args)
        {
            Console.WriteLine("Please enter the path to the file with the morse code: ");
            string inputPath = Console.ReadLine();

            Console.WriteLine("Please enter the path to the file into which the decoded text should be written: ");
            string outputPath = Console.ReadLine();

            try {
                MorseDecoder md = new MorseDecoder();
                md.Decode(inputPath, outputPath);
            } catch (Exception e)
            {
                Console.Error.WriteLine(e.Message);
            }

            Console.WriteLine("Press any key to continue");
            Console.ReadKey();
        }
예제 #11
0
        public static void readFromFile(string input, string output)
        {
            char         ch      = ' ';
            string       code    = " ";
            StreamReader reader  = new StreamReader(input);
            StreamWriter writer  = new StreamWriter(output);
            MorseDecoder decoder = new MorseDecoder();

            while (!reader.EndOfStream)
            {
                ch = (char)reader.Read();

                if (ch != '\n' && ch != '\r')
                {
                    try
                    {
                        string let = Char.ToString(ch);
                        let  = let.ToUpper();
                        code = decoder.getMorseFromLetter(let);
                        code = code + " ";
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine("Wrong Character!" + (int)ch);
                    }
                }
                else
                {
                    code = ch + "";
                }

                //Hinausschreiben
                writer.Write(code);
            }
            reader.Close();
            writer.Flush();
            writer.Close();
        }
예제 #12
0
 public void DecodeTest1()
 {
     Assert.AreEqual("HEY JUDE", MorseDecoder.Decode(".... . -.--   .--- ..- -.. ."));
 }
예제 #13
0
 public void Setup()
 {
     morseDecoder = new MorseDecoder();
 }
예제 #14
0
        public static void Test_MessageWithStop()
        {
            string inputWithFullStop = "000000001101101100111000001111110001111110011111100000001110011111110001100111111000110011111100000001110111111110111011100000001100011111100000111111001111110000000110000110111111110111011100000011011100000000000";

            Console.WriteLine(MorseDecoder.decodeBits2Morse(inputWithFullStop));
        }
예제 #15
0
        static void Main(string[] args)
        {
            //Morse // CodeWars web interface supplied an API for this dictionary
            InitializeDictionary();


            string decodedString = MorseDecoder.Decoder(".... . -.--   .--- ..- -.. .");

            Console.WriteLine(decodedString);


            //Tribonacci
            int n = 22;

            double[] tribo  = new double[] { 0, 3, 16 };
            double[] result = Tribonacci(tribo, n);

            foreach (var item in result)
            {
                Console.WriteLine(item);
            }


            //ValidatePin
            //string[] testCases = new string[] { "1234-+", "1234\n", "573012    ", "120412", "0000" };

            bool resA = ValidatePin("1233-+");
            bool resB = ValidatePin("1234\n");
            bool resC = ValidatePin("573012   ");
            bool resD = ValidatePin("120412");
            bool resE = ValidatePin("0000");

            Console.WriteLine(resA);
            Console.WriteLine(resB);
            Console.WriteLine(resC);
            Console.WriteLine(resD);
            Console.WriteLine(resE);


            //Disemvowel

            string resultA = Disemvowel("This website is for losers LOL!");
            string resultB = Disemvowel("Your mother is a terrible weight watcher LOL!");

            Console.WriteLine(resultA);
            Console.WriteLine(resultB);



            //Exes and Ohs

            //(true, XO("xo"))
            //(true, XO("xxOo"))
            //(false, XO("xxxm"))
            //(false, XO("Oo"))
            //(false, XO("ooom"))
            var inputA = "xo";
            var inputB = "xXOo";
            var inputC = "xoomm";

            bool resultBoolA = XO(inputA);
            bool resultBoolB = XO(inputB);
            bool resultBoolC = XO(inputC);

            Console.WriteLine(resultBoolA);
            Console.WriteLine(resultBoolB);
            Console.WriteLine(resultBoolC);



            // Sum Of Numbers(from A to B)
            int sumA = -1;
            int sumB = -5;

            int sum = GetSum(sumA, sumB);

            Console.WriteLine(sum);



            //Square Every Digit
            int squareMe  = 9999;
            int squaredMe = SquareDigits(squareMe);

            Console.WriteLine(squaredMe);



            //DuplicateCount

            int duplicateCount = DuplicateCount("AaBbCc44a");

            Console.WriteLine("Expected: 4 Count: " + duplicateCount);



            //ListFilterer

            //var list = new List<object>() { 1, 2, "a", "b" };
            //var resultR = GetIntegersFromList(list);
            //foreach (var item in resultR)
            //{
            //    Console.WriteLine(item);
            //}



            //IQTest..
            Console.WriteLine(Test("2 4 7 8 10"));



            //Number of people on the bus
            List <int[]> peopleListInOut = new List <int[]> {
                new[] { 10, 0 }, new[] { 3, 5 }, new[] { 5, 8 }
            };

            int resultNumber = Number(peopleListInOut);

            Console.WriteLine(resultNumber);



            //WUBWUBWUBWUB

            string testAB = SongDecoder("WUBWUBABCWUB");
            string testAC = SongDecoder("RWUBWUBWUBLWUB");
            string testAD = SongDecoder("WUBWEWUBAREWUBWUBTHEWUBCHAMPIONSWUBMYWUBFRIENDWUB");


            Console.WriteLine(testAB);
            Console.WriteLine(testAC);
            Console.WriteLine(testAD);



            //NEWWORDORDER

            string inOrder = Order("is2 Thi1s T4est 3a");

            Console.WriteLine(inOrder);



            //ArrayDiff

            int[] a = ArrayDiff(new int[] { 1, 2 }, new int[] { 1 });
            int[] b = ArrayDiff(new int[] { 1, 2, 2, 2, 2 }, new int[] { 1 });
            int[] c = ArrayDiff(new int[] { 1, 2, 2 }, new int[] { 2 });
            int[] d = ArrayDiff(new int[] { 1, 2, 2 }, new int[] { });
            int[] e = ArrayDiff(new int[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 12, 13, 14, 15 }, new int[] { 1, 7, 7 });

            foreach (var item in b)
            {
                Console.WriteLine(item);
            }

            //Split String into pairs. if pairs are not even, even it out with "_"

            string[] resultSol = Solution("abcdedasdsdvsdfsfdada");
            foreach (var item in resultSol)
            {
                Console.WriteLine(item);
            }
        }
예제 #16
0
 public void DecodingACharacter()
 {
     Assert.AreEqual("e", MorseDecoder.Decode("."));
     Assert.AreEqual("j", MorseDecoder.Decode(".---"));
 }
예제 #17
0
 public void DecodingAWord()
 {
     Assert.AreEqual("steak", MorseDecoder.Decode("... - . .- -.-"));
 }
예제 #18
0
 public void DecodingASentence()
 {
     Assert.AreEqual("i like steaks a lot", MorseDecoder.Decode("..   .-.. .. -.- .   ... - . .- -.- ...   .-   .-.. --- -"));
 }
예제 #19
0
 public void DecodeTest2()
 {
     Assert.AreEqual("HELLO WORLD", MorseDecoder.Decode(".... . .-.. .-.. ---   .-- --- .-. .-.. -.."));
 }