Are you well rested from your last code golf competition? Good, because I've got another one for you!

For this challenge you are to write a program that takes a string of International Morse code and converts it to a string of Alphanumeric characters (including white space) giving the output as a string in Ans. Use the decimal key as the dit and the minus key as the dah. Use the division key to represent white space.

Your byte count is the number of bytes of code, i.e. (program size) - 9 - (name length). Thanks lirtosiast for this!

Test cases:
Code:
"../.-.. .. -.- ./-- --- .-. ... ."-> I LIKE MORSE
"- .-.. --/.. .../- .... ./-... . ... -"->TLM IS THE BEST

Note: your program must produce results for all valid Morse code inputs, not just the test cases.

Leaderboard
  1. PT_ utilizing LogicalJoe, kg583, and lirtosiast's programs: 147 bytes
  2. LogicalJoe with kg583: 149 bytes
  3. LogicalJoe: 151 bytes
  4. lirtosiast: 152 bytes
  5. kg583: 163 bytes
  6. PT_: 170 bytes
  7. commandblockguy: 196 bytes
  8. weregoose: 210 bytes

Well done everyone! Keep those entries coming, I'll be keeping this leader board updated!
Just to be sure on the rules, we only have to account for the 26 letters and 10 digits right? (Does the program have to do anything with bad input or can it just output whatever)
Here is my 170 bytes solution, but I truly think it can be optimized more (don't have time currently), so I will post it anyways:

Ans+" ->Str1
"
For(A,1,length(Str1
Ans->Str3
inString(".- /",sub(Str1,A,1->B
N->P
(2N+B)(B<3->N
Str3
If B>2
Ans+sub("ETIANMSURWDKGOHVF L PJBXCYZQ 54 3 2 16 7 8 90",P,1
If B=4
Ans+"
End
sub(Ans,2,length(Ans)-1


Assumes a fresly reset calc.

Edit: it seems browsers don't like multiple spaces, so the huge string is actually wrong. If you really want to test out my entry and include numerals, don't Razz. I'm quite sure it is 170 bytes though.
mr womp womp wrote:
Just to be sure on the rules, we only have to account for the 26 letters and 10 digits right? (Does the program have to do anything with bad input or can it just output whatever)

You must account for the 26 letters, 10 numbers, and a white space. You don't have to account for invalid input.


Well done PT_, I think I see what you based your structure off of!
210 bytes:

Ans+" →Str1
"?→Str2
1→A
For(B,1,length(Str1
sub(Str1,B,1
(Ans=" ")-(Ans="/→C
If not(Ans
End
B-A
sub("*ETINAMSDRGUKWOHBLZFCP*VX*Q*YJ*56*7***8*******94*******3***2*10",2^Ans+sum(seq((sub(Str1,A+I,1)="-")2^I,I,0,Ans-1)),1
If C<0
Ans+"
Str2+Ans→Str2
B+1→A
End
sub(Str2,2,length(Str2)-1


I tried to do too much at once. Bad Idea

PT_: Nice trick with inString(). If I were to fit that to my program, I would immediately save 7 bytes!
Here's my 199 byte entry:

" "+Ans+" ->Str1
5->V
"Ans->Str9
For(P,1,length(Str1
sub(Str1,P,1->Str3
If inString(" /",Str3
Then
32->S
Str9+sub("5H4S:V31-F-U--2E-L-R+--A-P-W-J1,6B=D/X-N-C-K-Y-T7Z-G-Q-M8--O9-0",V,1,Str9
DelVar V
If Str3="/
Str9+" ->Str9
End
V+S-2S(Str3=".->V
S/2->S
End
sub(Str9,3,length(Str9)-2


As you can see, the lookup table is about a quarter unused, and there is also a pattern to the numbers. I'm investigating an alternative method which uses a smaller table. Right now it's just a bit larger than this method, unfortunately.

EDIT: got it optimized down to 196 bytes:

" "+Ans+" →Str1
7→V
"Ans→Str9
For(P,1,length(Str1
sub(Str1,P,1→Str3
If inString (" /",Str3
Then
16→S
V>Ans
toString(5+5Ans-log(.5+32Ans+V-2AnsV,2
If not(fPart(V
sub("HSVIFU:ELR-APWJ,BDXNCKYTZGQM-O",V,1
If Str3="/
Ans+"
Str9+Ans→Str9
DelVar V
End
V+S-2S(Str3=".→V
S/2→S
End
sub(Str9,3,length(Str9)-2
155 bytes… 152 151 bytes if the calc is pre-cleared:

Ans+" ->Str1
4->C:" // Remove <4->C:> for pre-reset calc
For(B,1,length(Str1
Ans->Str2
(2D+C)(C<3->D
inString(".-/ ",sub(Str1,B,1->C
Str2
If C<3
End
toString(int(10fPart(857819700ln(D
If D<31
sub("ETIANMSURWDKGOHVF-L-PJBXCYZQ",D,1
If length(Str2
Str2+Ans
If C=3
Ans+" " // closed for readability
End


I'm still working on it… But I still beat PT :3
I can't wait to see lirtosiast's

Edit 1: -1 byte at the suggestion of kg583 using a page of PT's
Edit 2: Corrected initialization (+1 for unreset to make 155 again)
163 bytes, assuming a freshly-cleared calc. I'm sure I can drop a few bytes on the number translating though...


Ans+" ->Str1:".- /
For(I,1,length(Str1
Ans->Str2
inString(Ans,sub(Str1,I,1->D
C->B:2Ans+D->C:Str2
If D>2:Delvar CAns+sub("ETIANMSURWDKGOHVF.L.PJBXCYZQ.54.3.2.......16.......7...8.90",B,1
If D=4:Ans+"
End
sub(Ans,5,length(Ans)-4
kg583 managed to get mine down to 149 bytes:

Ans+" ->Str1
"
For(B,1,length(Str1
Ans->Str2
2D+Y->D
inString(".- ",sub(Str1,B,1->Y
Str2
If fPart(Y/3
End
toString(int(10fPart(857819700ln(D
If D<31
sub("ETIANMNSURWDKGOHVF-L-PJBXCYZQ",D,1
If not(Y
Ans+"
DelVar DZStandard
If length(Str2
Str2+Ans
End


Good job!
152 bytes.


Code:
Ans+" ->Str1
"->Str2
For(I,1,length(Str1
inString("/.-",sub(Str1,I,1->C
If Ans>1
Then
2Y+Ans-1->Y
Else
sub("ETIANMSURWDKGOHVF L PJBXCYZQ  54 3 0928   7  16",min(Y,98-Y),1
If length(Str2
Str2+Ans
If C
Ans+"
Ans->Str2
ZStandard
End
End


EDIT: Fixed at the cost of 3 bytes
147 bytes, combined from 2 other programs Smile

Ans+" ->Str1
"->Str3
For(A,1,length(Str1
2Y+B->Y
inString(" .-",sub(Str1,A,1->B
DS<(B,1:End
toString(int(10fPart(857819700ln(Y
If Y<31
sub("ETIANMSURWDKGOHVF-L-PJBXCYZQ",Y,1
If B
Ans+"
DelVar BZStandard
If length(Str3
Str3+Ans
Ans->Str3
End


@lirtosiast: your program doesn't work, it omits the last char and returns the wrong value in Ans.
  
Register to Join the Conversation
Have your own thoughts to add to this or any other topic? Want to ask a question, offer a suggestion, share your own programs and projects, upload a file to the file archives, get help with calculator and computer programming, or simply chat with like-minded coders and tech and calculator enthusiasts via the site-wide AJAX SAX widget? Registration for a free Cemetech account only takes a minute.

» Go to Registration page
Page 1 of 1
» All times are GMT - 5 Hours
 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

 

Advertisement