[CODE GOLF] Challenge #2 - Morse Code Translator
ackvonhuelioLvl 41
Ravage
how did you go up in character count?
RavageLvl 20
ackvonhuelio I added on to my code to account for the 2x or more space correction @Varrience pointed out.
VarrienceLvl 25
- Edited
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"
VarrienceLvl 25
- Edited
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
Binary_CoderLvl 2
- Edited
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.
ackvonhuelioLvl 41
Ravage
takes my crappy school chromebook a solid minute to load them. lol
VarrienceLvl 25
- Edited
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
RavageLvl 20
ackvonhuelio The wall of amogi...