• Discussion
  • [CODE GOLF] Challenge #2 - Morse Code Translator

Binary_Coder Remove as many newlines, spaces, line breaks, whatever as possible!!! Make it all in one line if possible. Then, make sure all quotation marks are double: ". Then, enclose the whole thing in single quotation marks: ', and call that string.length. If you don't remove unnecessary spaces and line breaks, your total character count will go up...

OR you could just give me the code, and I could do it. I'm not saying that aggressively/patronizingly, just that I can help you if you need it.

ackvonhuelio This should be able to work in any console, like you said yourself... and even if you had a method of getting data for any console, I deliberated that it wouldn't be allowed. No external JS, no external data, no external nothing.

EDIT: also, you don't need lowercase letters. Only 0-9, uppercase, space.

    Ravage is there an example phrase we need to use? EX: "ABC 123" cuz that adds on to the char count for console or does user input not count as part of the solution? and do we also have to account for user error? I.E using lowercase and force correcting to uppercase?

      Varrience All you need to write is a FUNCTION that takes 1 PARAMETER. I will provide the parameters to the function when testing it. Example: function(e){a=long code in here that uses e as input; return a}.

      Don't worry, no need to account for user error. The inputs I will be testing will ALWAYS be uppercase, 0-9, space, NOTHING ELSE.

        Ravage
        u said the function console logs the result, not returns

        Ravage The function has to put back into the console that text as Morse Code,

          ackvonhuelio It returns the text.
          Also, can you PLEASE tell me how you did the thing where you reply to a specific piece of text? I can't find how.

          Awards

          • â’¸ 1 from ackvonhuelio
            Comment: Highlight text and click the button that says quote

          Ravage does it also have to mimic the sites parsing as well, say for instance a double space is done the register only uses 1 / between breaking words, is this required as well?

            Varrience 2 or more spaces have to become one "/ ". Makes it more fun. With that... I have 302. Do beat me, please...

              Ravage i think i did though i'm not to satisfied ain't no way i got it as low as it should be though we aren't accounting for user error for using the wrong casings right? only uppercase & numberals

                Varrience I have 299 now. Also... you don't need to account for wrong casings. The only thing you must account for is extra spaces, in the way I told you.

                  Ravage I know just double checking so that i can confirm that i win

                  // 233
                  function t(n){return n.replace(/\s+/g," ").split("").map(function(n){for(i=32,a=".EISH54V.3UF....2ARL.....WP..J.1TNDB6.X..KC..Y..MGZ7.Q..O.8..90.".indexOf(n),l="";i>1;i/=2)if(l+=a&i?"-":".",(a-=a&i?i:1)<1)return a<0?"/":l}).join(" ")}

                  it could possibly be lower than this.... though I don't care for the time being

                  Awards

                  • â’¸ 7 from Ravage
                    Comment: cool
                  • â’¸ 7 from Ravage
                    Comment: cool
                  • â’¸ 7 from Ravage
                    Comment: cool
                  • â’¸ 7 from Ravage
                    Comment: cool
                  • â’¸ 7 from Ravage
                    Comment: cool
                  • â’¸ 7 from Ravage
                    Comment: cool
                  • â’¸ 7 from Ravage
                    Comment: cool
                  • â’¸ 7 from Ravage
                    Comment: cool
                  • â’¸ 10 from Ravage
                    Comment: cool
                  • â’¸ 7 from Mellow
                    Comment: "so cool"

                    Varrience Map works?? Oh, I gotta revise my code!

                    EDIT: Can you explain this code (how the - and . are added)... and how did you ever get this idea!?

                      Ravage basically converting all numbers in ascii to bitwise gates i read up on it and someone even did put in some of the work by providing the list after i made it myself which made me ree a bit on the inside but anyways since there are 5 bits that each number is composed of and I'm going backwards because it's easier to construct but you can do it going forwards as well but by using this chart we call indexOf which will get the position of the first occurrence in the string take "A" for example it's 17 but how do we convert that? by testing the bitgates of course by using & we get if the bit in that number is shared of which we add a "-" and subtract it from the index otherwise we use "." which counts as 1 and subtract and it will continue to happen until it reaches 0 if it's less than 0 it's a space "/" if not we pass through the converted letter if my explanation doesn't make too much sense i recommend reading up with this project
                      https://github.com/nicolacimmino/MorseDecoder/blob/master/README.md
                      this is what i found like halfway in which was a literal facepalm because I couldn't find anything on what i was planning on doing for like the first day i tried i also made a full on tree to do it to put them in order it was a whole ordeal but this is basically what it does

                      /*
                      0	----- 48 | 62
                      1	.---- 49 | 31
                      2	..--- 50 | 16
                      3	...-- 51 | 9
                      4	....- 52 | 6
                      5	..... 53 | 5
                      6	-.... 54 | 36
                      7	--... 55 | 51
                      8	---.. 56 | 58
                      9	----. 57 | 61
                      A	.-   65 | 17
                      B	-...  66 | 35
                      C	-.-.  67 | 42
                      D	-..   68 | 34
                      E	.     69 | 1 
                      F	..-.  70 | 11
                      G	--.   71 | 49
                      H	....  72 | 4 
                      I	..    73 | 2 
                      J	.---  74 | 29
                      K	-.-   75 | 41
                      L	.-..  76 | 19
                      M	--   77 | 48
                      N	-.   78 | 33
                      O	---   79 | 56
                      P	.--.  80 | 26
                      Q	--.-  81 | 53
                      R	.-.   82 | 18
                      S	...    83 | 3 
                      T	-    84 | 32
                      U	..-   85 | 10
                      V	...-  86 | 7 
                      W	.--  87 | 25
                      X	-..-  88 | 38
                      Y	-.--  89 | 45
                      Z	--..  90 | 50
                      */

                      also i could remove the extra dot at the end since the theoretical max is 62 making my solution 232 now
                      tldr; forbidden bitwise magic: gates & comparison edition, lower level stuff definitely does some shit to your brain

                        Ravage Yeah knowing that earlier would have made my life a lot easier.

                        At least I was on the right track, mine used ASCII character codes to make the conversion. Though it doesn't really matter if you can use bitwise gates to do it. Would never have thought of that.

                        function m(s){s=s.replace(/\s+/g,' ').trim();var q="";for(var i=0;i<s.length;i++){var c=s[i];var d="/ ----- .---- ..--- ...-- ....- ..... -.... --... ---.. ----. .- -... -.-. -.. . ..-. --. .... .. .--- -.- .-.. -- -. --- .--. --.- .-. ... - ..- ...- .-- -..- -.-- --..".split(" ");var x=c.charCodeAt(0)-32;q+=d[x];}return q;} // 349 :(

                        Also (and this could just be me) @Varrience's code crashes when I try to use it, says it can't wrap the value undefined.

                          Varrience Bruh.
                          Next challenge is a juicy one, but I will be abstaining from doing it, because reasons. Should be open to different approaches!!!

                          Also, I broke my icons, yay!!!

                            Binary_Coder riiight..... so technically map does work just not in the actual console apparently but will produce output in the editor of which idfkw i can adjust it so it could be in the console but it will work in the project regaurdless

                            i can adapt it to be inline injection if you wish for that but map will no longer be useable

                            Chat