30
\$\begingroup\$

A big part of radio communication is the NATO Phonetic Alphabet, which encodes letters as words to make them easier to understand over comms. Your job, if you wish to accept it, is to print them one by one.

You must print this exact string to stdout:

A: Alfa
B: Bravo
C: Charlie
D: Delta
E: Echo
F: Foxtrot
G: Golf
H: Hotel
I: India
J: Juliet
K: Kilo
L: Lima
M: Mike
N: November
O: Oscar
P: Papa
Q: Quebec
R: Romeo
S: Sierra
T: Tango
U: Uniform
V: Victor
W: Whiskey
X: Xray
Y: Yankee
Z: Zulu

Rules:

  • Your program takes no input
  • Standard loopholes are Disallowed.
  • If there are any builtins in your language that turn letters to their NATO equivelants, you may not use them (I'm looking at you Mathematica).
  • You may have trailing spaces and one trailing newline.
\$\endgroup\$
15
  • 1
    \$\begingroup\$ Related. \$\endgroup\$ Mar 7, 2017 at 8:53
  • 4
    \$\begingroup\$ I'm closing this as a dupe because it doesn't have any exploitable structure that would allow custom compression schemes to perform better than built-in compression, and the target challenge is our de facto standard challenge for built-in compression. \$\endgroup\$
    – user45941
    Mar 7, 2017 at 10:06
  • 1
    \$\begingroup\$ Closely related. If anything I'd call it a dupe of this one, but it allowed people to choose their own words which actually made compression a lot more possible. \$\endgroup\$ Mar 7, 2017 at 10:31
  • 3
    \$\begingroup\$ shouldn't the first one be A: Alpha ? \$\endgroup\$
    – SeanC
    Mar 7, 2017 at 15:13
  • 3
    \$\begingroup\$ @SeanC: According to wikipedia (see link in question), no. That´s ATIS, not NATO. But then, it should be Juliett, not Juliet and X-ray instead of Xray. \$\endgroup\$
    – Titus
    Mar 7, 2017 at 15:27

51 Answers 51

18
\$\begingroup\$

Python 2, 189 186 bytes

i=65
for w in"lfa ravo harlie elta cho oxtrot olf otel ndia uliet ilo ima ike ovember scar apa uebec omeo ierra ango niform ictor hiskey ray ankee ulu".split():print'%c: %c'%(i,i)+w;i+=1

Try it online!


Previous: (this was cool, but I realised the simpler version could be made shorter by a byte)

w=''
i=65
for c in"lfAravOharliEeltAchOoxtroTolFoteLndiAulieTilOimAikEovembeRscaRapAuebeComeOierrAangOniforMictoRhiskeYraYankeEulU":
 w+=c.lower()
 if'_'>c:print'%c: %c'%(i,i)+w;w='';i+=1
\$\endgroup\$
12
\$\begingroup\$

Jelly, 76 bytes

“ṭṡl°ẠkWßġȮRẎ+wḋñȥạġ¢ƊḌ¬kạẠ¦WṡỊƒK⁹ç}⁶hm}Kñ£ɦ/lṇẊɠƓ}pƤ°⁸Ụ.g⁹Ġh9ṁ{f»ḲØAżj€⁾: Y

Try it online!

How?

Pretty much just dictionary values and compression. The code between and » is just a compressed value that will form the string "Alfa Bravo Charlie Delta Echo Foxtrot Golf Hotel India Juliet Kilo Lima Mike November Oscar Papa Quebec Romeo Sierra Tango Uniform Victor Whiskey Xray Yankee Zulu" by looking up all the words (with single space prefixes, except for "Alfa") in Jelly's dictionary (except for " Xray" which is not in the dictionary, so the direct string value " X" and the dictionary entry "ray" are used instead).

The rest of the code does the rest:

“...»ḲØAżj€⁾: Y - Main link: no arguments
“...»           - the string described above (really a list of characters)
     Ḳ          - split at spaces
      ØA        - alphabet yield - ['A','B','C', ...,'X','Y','Z']
        ż       - zip - makes a list of lists [['A'],['A','l','f','a']],[['B'],['B','r','a','v','o']], ...]
         j€     - join each with
           ⁾:   - the string ": "
              Y - join with line feeds
                - implicit print
\$\endgroup\$
3
  • \$\begingroup\$ (NOTE: I never programmed in Jelly.) When I see your code I'm wondering two things: 1. You currently loop over the alphabet and join them with the words. Is it possible in Jelly to get the first character of a string, so you loop over the words instead of the alphabet, and join them with first_letter_of_word + ": " + word? And 2. You retrieve all words including spaces and then split by space. Is it possible to inclusive-split by the leading capital letters? No idea if these spaces even give extra bytes in their compressed form or not, and if they can be reduced with my description at 2. \$\endgroup\$ Mar 7, 2017 at 9:42
  • 1
    \$\begingroup\$ @KevinCruijssen (1) yes it's possible to use the first letter of each word, however it wont be as short since the alphabet yield is a two-byte atom. (2) yes it's possible to split on capital letters, but surprisingly the compression of the string with no spaces is actually longer (many words with leading spaces are actually in the dictionary, as are all of these with capitalisation). \$\endgroup\$ Mar 7, 2017 at 9:48
  • 2
    \$\begingroup\$ The dictionary doesn't contain leading spaces. However, when decompressing multiple words in a row, the default is to separate them by spaces; the first word won't have a leading space, but all following words will. \$\endgroup\$
    – Dennis
    Mar 7, 2017 at 19:36
11
\$\begingroup\$

Retina, 156 bytes

Byte count assumes ISO 8859-1 encoding.


AlfaBravoCharlieDeltaEchoFoxtrotGolfHotelIndiaJulietKiloLimaMikeNovemberOscarPapaQuebecRomeoSierraTangoUniformVictorWhiskeyXrayYankeeZulu
[A-Z]
¶$&: $&
G`.

Try it online!

\$\endgroup\$
11
\$\begingroup\$

05AB1E, 102 98 bytes

Saved 4 bytes thanks to Erik the Outgolfer

”AlfaІvo¼¯¤œ®È¨›trotŠˆƒ‹Š™ÈŸt Kilo´àma—……ÍЗŽêpa¼°«Äoµ†Çâgo¸šÉµ Whiskey Xrayµ‹nkeeâ¸lu”#vy¬„: «ì,

Try it online!

Explanation

Uses dictionary compression for the words in 05AB1E's dictionary.
Uses partial dictionary compression whenever possible for other words.
Plain-text words where neither is possible.

#          # split on spaces
 v         # for each word
  y        # push the word
   ¬       # get the first letter of the word
    „:     # push the string ": "
       «   # append this to the letter
        ì  # prepend the result to the word
         , # print with newline
\$\endgroup\$
2
  • 2
    \$\begingroup\$ Get it down to 98 using this compressed string instead: ”AlfaІvo¼¯¤œ®È¨›trotŠˆƒ‹Š™ÈŸt Kilo´àma—……ÍЗŽêpa¼°«Äoµ†Çâgo¸šÉµ Whiskey Xrayµ‹nkeeâ¸lu”. \$\endgroup\$ Mar 7, 2017 at 12:56
  • \$\begingroup\$ @EriktheOutgolfer: Thanks! I was sure I looked for pa and li in the dictionary but I must have missed them. I didn't consider ya and zu as words though :) \$\endgroup\$
    – Emigna
    Mar 7, 2017 at 13:34
6
\$\begingroup\$

Ruby, 169 characters

(Heavily based on Jonathan Allan's Python 2 solution. If you like the idea, please upvote the original answer.)

i=?@
"LfaRavoHarlieEltaChoOxtrotOlfOtelNdiaUlietIloImaIkeOvemberScarApaUebecOmeoIerraAngoNiformIctorHiskeyRayAnkeeUlu".scan(/.[a-z]+/){|w|puts i.succ!+": "+i+w.downcase}

Sample run:

bash-4.3$ ruby -e 'i=?@;"LfaRavoHarlieEltaChoOxtrotOlfOtelNdiaUlietIloImaIkeOvemberScarApaUebecOmeoIerraAngoNiformIctorHiskeyRayAnkeeUlu".scan(/.[a-z]+/){|w|puts i.succ!+": "+i+w.downcase}' | head
A: Alfa
B: Bravo
C: Charlie
D: Delta
E: Echo
F: Foxtrot
G: Golf
H: Hotel
I: India
J: Juliet
\$\endgroup\$
6
\$\begingroup\$

Java 7, 242 225 222 217 bytes

void d(){char c=65;for(String s:"lpha ravo harlie elta cho oxtrot olf otel ndia uliet ilo ima ike ovember scar apa uebec omeo ierra ango niform ictor hiskey ray ankee ulu".split(" "))System.out.println(c+": "+c+++s);}

Explanation:

void d(){                          // Method
  char c = 65;                     //  Starting character 'A'
  for(String s : "lpha ravo harlie elta cho oxtrot olf otel ndia uliet ilo ima ike ovember scar apa uebec omeo ierra ango niform ictor hiskey ray ankee ulu"
      .split(" "))                 //  Loop over the word-parts
    System.out.println(            //   Print line with:
      c                            //    The current character
      + ": "                       //    + ": "
      + c++ + s                    //    + the current character + word-part (and raise the character afterwards)
    );                             //   End of print line
                                   //  End of loop (implicit / single-line body)
}                                  // End of method

Test code:

Try it here.

class M{
  static void d(){char c=65;for(String s:"lpha ravo harlie elta cho oxtrot olf otel ndia uliet ilo ima ike ovember scar apa uebec omeo ierra ango niform ictor hiskey ray ankee ulu".split(" "))System.out.println(c+": "+c+++s);}

  public static void main(String[] a){
    d();
  }
}
\$\endgroup\$
1
  • \$\begingroup\$ Should work with Java 5 and all subsequent versions. \$\endgroup\$
    – Holger
    Mar 7, 2017 at 14:30
5
\$\begingroup\$

Octave, 215 210 209 bytes

Saved 5 bytes thanks to Luis Mendo. I saved 4 bytes thanks to Luis Mendo, but changing the approach help me save one more

fprintf('%s: %s%s\n',[k=num2cell(65:90);k;regexp('lfaBravoCharlieDeltaEchoFoxtrotGolfHotelIndiaJulietKiloLimaMikeNovemberOscarPapaQuebecRomeoSierraTangoUniformVictorWhiskeyXrayYankeeZulu','[A-Z]','split')]{:})

Try it online!

If I got rid of the spaces, I'd save 25 bytes, but then I'd have to use a regex. The regex itself would cost quite a few bytes, and it would also remove the capital letter of all words, leaving me with the words lfa, ravo etc. I would therefore have to concatenate the new strings with the leading characters. All this costs bytes.

Old explanation:

fprintf('%s: %s\n',      % Print a string with the format "str: str\n"
num2cell(65:90)          % Create a cell array with the numbers 65 - 90, one in each cell
strsplit('Alfa ...       % Split the string on the default delimiter: space
[num2cell();strsplit()]  % Concatenate cell arrays, leaving us with
                         % {'A',    'B'
                         %  'Alfa', 'Bravo'}
[...]{:}                 % Convert the cell array to a comma-delimited vector
                         % 'A', 'Alfa', 'B', 'Bravo' ...
\$\endgroup\$
8
  • \$\begingroup\$ Thanks! This was a bit messier!, and three bytes longer... \$\endgroup\$ Mar 7, 2017 at 10:02
  • \$\begingroup\$ Ah, yes, 'split' would be longer here \$\endgroup\$
    – Luis Mendo
    Mar 7, 2017 at 13:15
  • \$\begingroup\$ 'split' was shorter: 209 :) \$\endgroup\$ Mar 7, 2017 at 14:23
  • \$\begingroup\$ I see! Well done! \$\endgroup\$
    – Luis Mendo
    Mar 7, 2017 at 14:56
  • \$\begingroup\$ You can split on spaces and save 5 more bytes \$\endgroup\$
    – Luis Mendo
    Mar 7, 2017 at 17:24
5
\$\begingroup\$

PHP, 202 227 196 187 bytes

Thanks to Dewi Morgan for saving 9 bytes

echo preg_replace('/([A-Z])[a-z]+/',"$1: $0\n",AlfaBravoCharlieDeltaEchoFoxtrotGolfHotelIndiaJulietKiloLimaMikeNovemberOscarPapaQuebecRomeoSierraTangoUniformVictorWhiskeyXrayYankeeZulu);

https://repl.it/GMkH/1


Older versions

Thanks to manatwork and insertusernamehere for saving 31 bytes!

foreach(preg_split('/\B(?=[A-Z])/',AlfaBravoCharlieDeltaEchoFoxtrotGolfHotelIndiaJulietKiloLimaMikeNovemberOscarPapaQuebecRomeoSierraTangoUniformVictorWhiskeyXrayYankeeZulu)as$k)echo"$k[0]: $k\n";

https://eval.in/749541

Thanks to insertusernamehere for noticing the output was wrong with the previous version.

$a=preg_split('/(?=[A-Z])/',AlfaBravoCharlieDeltaEchoFoxtrotGolfHotelIndiaJulietKiloLimaMikeNovemberOscarPapaQuebecRomeoSierraTangoUniformVictorWhiskeyXrayYankeeZulu,-1,PREG_SPLIT_NO_EMPTY);foreach($a as $k)echo "$k[0]: $k\n";

https://repl.it/GKS8/3

$a=preg_split('/(?=[A-Z])/',AlfaBravoCharlieDeltaEchoFoxtrotGolfHotelIndiaJulietKiloLimaMikeNovemberOscarPapaQuebecRomeoSierraTangoUniformVictorWhiskeyXrayYankeeZulu);foreach($a as $k)echo"$k[0]: $k\n";

https://repl.it/GKS8/2

\$\endgroup\$
16
  • \$\begingroup\$ Why variable $a? Just move the entire preg_split() call in foreach's parameter. Then none of the spaces around as will be necessary anymore. \$\endgroup\$
    – manatwork
    Mar 7, 2017 at 9:06
  • \$\begingroup\$ Instead of constant PREG_SPLIT_NO_EMPTY, better use its value: 1. But personally I would tweak the regular expression instead: /\B(?=[A-Z])/. \$\endgroup\$
    – manatwork
    Mar 7, 2017 at 9:22
  • 1
    \$\begingroup\$ Thanks @insertusernamehere i'll make that edit now :D Still getting used to codegolfing \$\endgroup\$
    – ʰᵈˑ
    Mar 7, 2017 at 9:34
  • \$\begingroup\$ That would be one byte shorter with a plain array instead of the preg_split. \$\endgroup\$
    – Titus
    Mar 7, 2017 at 14:21
  • 1
    \$\begingroup\$ 10 characters shorter: echo preg_replace('/([A-Z])[a-z]+/',"$1 = $0\n",Alfa...Zulu); \$\endgroup\$ Mar 8, 2017 at 16:46
4
\$\begingroup\$

Brachylog, 178 bytes

"Alfa Bravo Charlie Delta Echo Foxtrot Golf Hotel India Juliet Kilo Lima Mike November Oscar Papa Quebec Romeo Sierra Tango Uniform Victor Whiskey Xray Yankee Zulu"ṇ₁{hw": "w?ẉ}ᵐ

Try it online!

Explanation

"…"ṇ₁               Split the string on spaces
     {         }ᵐ   Map on each word:
      hw              Write the first letter
        ": "w         Write ": "
             ?ẉ       Write the word followed by a new line
\$\endgroup\$
4
\$\begingroup\$

PHP, 188 186 180 174 bytes

no trailing spaces, one leading newline

<?=preg_filter("#[A-Z]#","
$0: $0",AlfaBravoCharlieDeltaEchoFoxtrotGolfHotelIndiaJulietKiloLimaMikeNovemberOscarPapaQuebecRomeoSierraTangoUniformVictorWhiskeyXrayYankeeZulu);

simply replaces all uppercase letters in the compressed string with
<newline><letter><colon><space><letter>

\$\endgroup\$
4
  • \$\begingroup\$ This time competitive ? ;) \$\endgroup\$
    – Christoph
    Mar 7, 2017 at 14:28
  • \$\begingroup\$ -13 bytes with gzinflate-ing the result of gzdeflate(Alfa...Zulu). \$\endgroup\$
    – Titus
    Mar 7, 2017 at 19:07
  • \$\begingroup\$ Unfortunately, no leading newline is allowed, only a (single) trailing newline \$\endgroup\$
    – aross
    Mar 8, 2017 at 13:58
  • \$\begingroup\$ @aross: see the OP´s comment from yesterday: and for your other question, yes, but just one. \$\endgroup\$
    – Titus
    Mar 9, 2017 at 1:22
4
\$\begingroup\$

Python 2, 186 182 bytes

print''.join('\n%s: '%c*('['>c)+c for c in'AlfaBravoCharlieDeltaEchoFoxtrotGolfHotelIndiaJulietKiloLimaMikeNovemberOscarPapaQuebecRomeoSierraTangoUniformVictorWhiskeyXrayYankeeZulu')

Try it online!

\$\endgroup\$
2
  • 2
    \$\begingroup\$ see comments on question: one leading newline is (now) accepted \$\endgroup\$
    – Titus
    Mar 7, 2017 at 19:13
  • \$\begingroup\$ Welcome to PPCG! Nice stuff. \$\endgroup\$ Mar 7, 2017 at 20:02
4
\$\begingroup\$

C (MinGW, Clang), 218 bytes

Thanks to @gastropner!

i;f(){char s[]="lfa:ravo:harlie:elta:cho:oxtrot:olf:otel:ndia:uliet:ilo:ima:ike:ovember:scar:apa:uebec:omeo:ierra:ango:niform:ictor:hiskey:ray:ankee:ulu";for(i=64;++i<91;)printf("%c: %c%s\n",i,i,strtok(i^65?0:s,":"));}

Try it online!

C, 259 236 bytes

i;f(){char*s="lfa\0ravo\0harlie\0elta\0cho\0oxtrot\0olf\0otel\0ndia\0uliet\0ilo\0ima\0ike\0ovember\0scar\0apa\0uebec\0omeo\0ierra\0ango\0niform\0ictor\0hiskey\0ray\0ankee\0ulu";for(i=64;++i<91;s+=strlen(s)+1)printf("%c: %c%s\n",i,i,s);}

Try it online!

\$\endgroup\$
6
  • \$\begingroup\$ How would I compile this? \$\endgroup\$ Mar 8, 2017 at 2:12
  • 1
    \$\begingroup\$ @ItayGrudev, GCC and Clang should both compile that as is. gcc src.c or clang src.c. Here's a sample run with a main function added so the code will actually link and run: ideone.com/4Eowlh \$\endgroup\$
    – chris
    Mar 8, 2017 at 17:51
  • \$\begingroup\$ @chris Then at the expense of 4 bytes, shouldn't f be replaced with main so the code is valid, or am I missing some golfing convention. \$\endgroup\$ Mar 8, 2017 at 18:36
  • 2
    \$\begingroup\$ @ItayGrudev, The way I see it, the question only asked for the functionality, not a full, self-contained program. \$\endgroup\$
    – chris
    Mar 8, 2017 at 20:03
  • 1
    \$\begingroup\$ 218 with strtok() and some fiddling with the string i;f(){char s[]="lfa:ravo:harlie:elta:cho:oxtrot:olf:otel:ndia:uliet:ilo:ima:ike:ovember:scar:apa:uebec:omeo:ierra:ango:niform:ictor:hiskey:ray:ankee:ulu";for(i=64;++i<91;)printf("%c: %c%s\n",i,i,strtok(i^65?0:s,":"));} Unclear if it works everywhere: TIO segfaults but works in MinGW at least. Can't see much of a reason why it wouldn't work. \$\endgroup\$
    – gastropner
    Nov 23, 2017 at 11:40
3
\$\begingroup\$

Gema, 168 characters

\A=@subst{?<J>=\?: \$0\\n;AlfaBravoCharlieDeltaEchoFoxtrotGolfHotelIndiaJulietKiloLimaMikeNovemberOscarPapaQuebecRomeoSierraTangoUniformVictorWhiskeyXrayYankeeZulu}@end

Sample run:

bash-4.3$ gema '\A=@subst{?<J>=\?: \$0\\n;AlfaBravoCharlieDeltaEchoFoxtrotGolfHotelIndiaJulietKiloLimaMikeNovemberOscarPapaQuebecRomeoSierraTangoUniformVictorWhiskeyXrayYankeeZulu}@end' | head
A: Alfa
B: Bravo
C: Charlie
D: Delta
E: Echo
F: Foxtrot
G: Golf
H: Hotel
I: India
J: Juliet
\$\endgroup\$
3
\$\begingroup\$

x86 Assembly, 512 bytes

Compiled with NASM and tested with QEMU. To boot you need to put a 2 byte boot signature at the end of the bootsector (510 bytes into the file) so I lost 317 bytes filling the compiled code with zeros. This is my first golf so I have to apologize for any gigantic errors.

[org 7c00h]     ;So NASM can change the labels into memory locations correctly.

cld             ;Tells lodsb to look forward in memory

mov bh, 65      ;Moves the ASCII value of A into the BH register
mov si, NATO    ;Moves the first byte of NATO into the si register
call print      ;Call the 'print' subroutine

jmp $            ;Loops forever

print:
    mov ah, 0eh ;Moves the hex value 0E into the AH register. Tells interrupt 10h that we want subfucntion 0E
    lodsb       ;Load a byte of SI into AL and increments a register (DL i think) that tells it the offset to look at

    cmp al, 3   ;Compares the AL register that now has a byte from our string to ASCII value 3 (Enf Of Text)
    je R        ;If AL == 3 then jump to R

    cmp al, 0   ;Comapre AL to ASCII 0 (NULL)
    je newWord  ;If AL == 0 hump to newWord
    int 10h     ;Execute interrupt 10h Subfunction 0Eh (stored in AH register) which prints character value in AL
    jmp print   ;Jump to print

newWord:
    mov al, 10  ;Move ASCII 10 (New Line) into AL
    int 10h     ;Print character

    mov al, 13  ;Move ASCII 13 (Carriage Return) into AL
    int 10h     ;Print character

    mov al, bh  ;Move BH (which has our starting letter) into AL
    int 10h     ;Print Character

    mov al, 58  ;Move ASCII 58 (:) into AL
    int 10h     ;Print Character

    mov al, 32  ;Move ASCII 32 (Space) into AL
    int 10h     ;Print Character

    mov al, bh  ;Move BH into AL
    int 10h     ;Print Character

    inc bh      ;Increments BH by one (BH++)
    jmp print   ;Jump to print

R:
    ret         ;Returns from a subroutine

;Below defines bytes (db) of our string to print. I used 0 as word seperators and 3 to end the string.
NATO: db 0,"lfa",0,"ravo",0,"harlie",0,"elta",0,"cho",0,"oxtrot",0,"olf",0,"otel",0,"ndia",0,"uliet",0,"ilo",0,"ima",0,"ike",0,"ovember",0,"scar",0,"apa",0,"uebec",0,"omeo",0,"ierra",0,"ango",0,"niform",0,"ictor",0,"hiskey",0,"ray",0,"ankee",0,"ulu",3

times 0200h - 2 - ($ - $$) db 0 ;Zerofill the file with upto 510 bytes (This is where all my bytes are)
dw 0AA55H   ;Write the bootsignature

Output

This is what the above code outputs. As you can see A: Alfa is missing and that is because the prompt is 25 lines tall... Above codes output

To prove I printed A: Alfa I replaced 0,"ulu" with 32,"Z: Zulu" so that Zulu is one on the same line as Yankee. Changed code

I would appreciate it if someone told me if I would be able to subtract the 317 bytes of zerofill from my code so it would be 195 bytes. Also if this is even valid because the output won't fit on the screen.

\$\endgroup\$
3
\$\begingroup\$

Bash, 224 205 188 180 bytes

Thanks to Digital Trauma for removing 17 bytes, and manatwork for 8 bytes.

set {A..Z}
for i in lfa ravo harlie elta cho oxtrot olf otel ndia uliet ilo ima ike ovember scar apa uebec omeo ierra ango niform ictor hiskey ray ankee ulu;{ echo $1: $1$i;shift;}

Try it online!

\$\endgroup\$
2
  • 1
    \$\begingroup\$ Some golfing \$\endgroup\$ Mar 8, 2017 at 22:14
  • \$\begingroup\$ Indexing array a is too long. set {A..Z};for i in lfa … ulu;{ echo $1: $1$i;shift;} \$\endgroup\$
    – manatwork
    Mar 9, 2017 at 12:23
2
\$\begingroup\$

Python 2, 198 bytes

for x in'Alfa Bravo Charlie Delta Echo Foxtrot Golf Hotel India Juliet Kilo Lima Mike November Oscar Papa Quebec Romeo Sierra Tango Uniform Victor Whiskey Xray Yankee Zulu'.split():print x[0]+': '+x

Try it online!

Not exciting or clever. Just loops through the list and prints the first letter then ': ' then the whole word.

\$\endgroup\$
2
\$\begingroup\$

PHP, 184 bytes 179 bytes 178

<?=preg_filter('/(.)[a-z]+/',"$1: $0
",AlfaBravoCharlieDeltaEchoFoxtrotGolfHotelIndiaJulietKiloLimaMikeNovemberOscarPapaQuebecRomeoSierraTangoUniformVictorWhiskeyXrayYankeeZulu);

saved a single byte by using preg_filter instead of preg_replace.


Original answer 184 bytes 179 bytes

for($c=A;$s=[lfa,ravo,harlie,elta,cho,oxtrot,olf,otel,ndia,uliet,ilo,ima,ike,ovember,scar,apa,uebec,omeo,ierra,ango,niform,ictor,hiskey,ray,ankee,ulu][+$i++];$c++)echo"$c: $c$s
";

uses the fact that its sorted to generate the first char on the fly.

5 bytes saved by @Titus.

\$\endgroup\$
2
  • 2
    \$\begingroup\$ Golf your original down to 180-1 with for($c=A;$s=[lfa,...,ulu][+$i++];$c++)echo"$c: $c$s\n";. Nice regex though. \$\endgroup\$
    – Titus
    Mar 7, 2017 at 14:59
  • \$\begingroup\$ @Titus I had in mind there must be a better way but switched to preg. Thanks for the tip ! \$\endgroup\$
    – Christoph
    Mar 7, 2017 at 15:01
2
\$\begingroup\$

SOGL, 91 bytes

╗D↕«∙φā¡75↔TI.½!γΜΧ…¡%<F┼0h╔κy|▓@TņV≈%⁹cr_σy░mgļΕžΕ⅝ »τ{M╔|«▼↔»aΓ²⁹┘′⅓G…└g↔bFΞ‽‘θ{KUtƧ: ooo

Explanation:

...‘θ{KUtƧ: ooo  that gibberish is a compressed string                 
...‘             push the compressed string of the words
    θ            split on spaces
     {           for each
      K          pop the 1st letter off & push it
       U         uppercase it
        t        output in newline a copy of the letter
         Ƨ: o    append ": "
             o   append the alphabet letter
              o  append the rest of the word
\$\endgroup\$
2
\$\begingroup\$

GNU sed, 165 bytes

This script is based on the Retina answer by Martin Ender.

s/$/AlfaBravoCharlieDeltaEchoFoxtrotGolfHotelIndiaJulietKiloLimaMikeNovemberOscarPapaQuebecRomeoSierraTangoUniformVictorWhiskeyXrayYankeeZulu/
s/[A-Z]/\n&: &/g
s/.//

Try it online!

Explanation:

s/$/AlfaBravoCharlieDeltaEchoFoxtrotGolfHotelIndiaJulietKiloLimaMikeNovemberOscarPapaQuebecRomeoSierraTangoUniformVictorWhiskeyXrayYankeeZulu/
   # generate the alphabet words in concatenated form
s/[A-Z]/\n&: &/g
   # prepend '\nUL: ' before each upper-case letter (UL), getting the needed format
s/.//
   # delete the leading newline, plus implicit printing at the end
\$\endgroup\$
2
\$\begingroup\$

Bash, 184 bytes

printf '%c: %s
' {Alfa,Bravo,Charlie,Delta,Echo,Foxtrot,Golf,Hotel,India,Juliet,Kilo,Lima,Mike,November,Oscar,Papa,Quebec,Romeo,Sierra,Tango,Uniform,Victor,Whiskey,Xray,Yankee,Zulu}{,}

Try it online!

\$\endgroup\$
1
  • \$\begingroup\$ +1. The {,} trick in the brace expansion is a very clever way to double up each list member! \$\endgroup\$ Mar 8, 2017 at 22:14
2
\$\begingroup\$

Lua, 278 260 bytes

Thanks again to Manatwork for saving 18 bytes!

function f(w)print(w.sub(w,0,1)..": "..w)end
f"Alfa"f"Bravo"f"Charlie"f"Delta"f"Echo"f"Foxtrot"f"Golf"f"Hotel"f"India"f"Juliet"f"Kilo"f"Lima"f"Mike"f"November"f"Oscar"f"Papa"f"Quebec"f"Romeo"f"Sierra"f"Tango"f"Uniform"f"Victor"f"Whiskey"f"Xray"f"Yankee"f"Zulu"

Try it online


Older versions

a={"Alfa","Bravo","Charlie","Delta","Echo","Foxtrot","Golf","Hotel","India","Juliet","Kilo","Lima","Mike","November","Oscar","Papa","Quebec","Romeo","Sierra","Tango","Uniform","Victor","Whiskey","Xray","Yankee","Zulu"}
for i=1,26 do print(a[i].sub(a[i],0,1) .. ": " .. a[i]) end

https://repl.it/GK8J

First time doing Lua, do probably can golf more, but thought I'd add it as an answer anyways.

\$\endgroup\$
2
  • \$\begingroup\$ My question may become boring, but again: Why variable a? ;) You can move the entire array declaration inside the for. And the for..in syntax helps to avoid writing those long array indices: pastebin.com/rxck79md Weird Lua thing: if you declare a function and call it 26 times “manually” (I mean, not in a loop) is shorter: pastebin.com/FMF9GmLJ \$\endgroup\$
    – manatwork
    Mar 8, 2017 at 9:04
  • \$\begingroup\$ ¯\_(ツ)_/¯ for the simple reason that I never used Lua before so I was just following the manual to try make it work, aha. Thanks @manatwork for the info, I didn't know about that. \$\endgroup\$
    – ʰᵈˑ
    Mar 8, 2017 at 9:08
2
\$\begingroup\$

Lua, 177 bytes

print(("AlfaBravoCharlieDeltaEchoFoxtrotGolfHotelIndiaJulietKiloLimaMikeNovemberOscarPapaQuebecRomeoSierraTangoUniformVictorWhiskeyXrayYankeeZulu"):gsub('%u',"\n%1: %1"):sub(2))

Try it online!

Without trailing newline, 180 bytes:

io.write(("AlfaBravoCharlieDeltaEchoFoxtrotGolfHotelIndiaJulietKiloLimaMikeNovemberOscarPapaQuebecRomeoSierraTangoUniformVictorWhiskeyXrayYankeeZulu"):gsub('%u',"\n%1: %1"):sub(2))

Explanation

str = "AlfaBravoCharlieDeltaEchoFoxtrotGolfHotelIndiaJulietKiloLimaMikeNovemberOscarPapaQuebecRomeoSierraTangoUniformVictorWhiskeyXrayYankeeZulu"
str = str:gsub('%u',"\n%1: %1") -- returns "\nA: Alfa...". %u matches uppercase letters, %1 returns matched letter in this case.
str = str:sub(2) -- remove added newline in the beginning
print(str) -- native print command

It uses Lua's string.gsub substitution function to pattern match the uppercase letters. The letters are then replaced with the requested format (plus the letters themselves). Newlines are also added on the same pass.

The sub-function at the end just trims out newline from the beginning and also works nicely to hide the second return value of gsub, which would have been the amount of replacements.

\$\endgroup\$
2
\$\begingroup\$

PowerShell, 187 185 bytes

0..25|%{($a=[char]($_+65))+": $a"+(-split'lfa ravo harlie elta cho oxtrot olf otel ndia uliet ilo ima ike ovember scar apa uebec omeo ierra ango niform ictor hiskey ray ankee ulu')[$_]}

Try it online!

Loops from 0 to 25, each iteration forming $a of the corresponding capital char. Then string-concatenated with : $a (i.e., the colon-space-letter). Then that string is string-concatenated with an string that's formed by indexing into an array created by -splitting the phonetic string on spaces. Each of those 26 strings is left on the pipeline, and an implicit Write-Output happens at program completion, inserting a newline between elements.

Saved two bytes thanks to @Matt.

\$\endgroup\$
2
  • \$\begingroup\$ Nice. Removing the first character of each word didn't even occur to me. You can chop off 2 bytes doing this: 0..25|%{($a=[char]($_+65))+": $a"+(-split'lfa ravo harlie elta cho oxtrot olf otel ndia uliet ilo ima ike ovember scar apa uebec omeo ierra ango niform ictor hiskey ray ankee ulu')[$_]} \$\endgroup\$
    – Matt
    Mar 8, 2017 at 15:18
  • \$\begingroup\$ @Matt Oh sure, that makes sense. Thanks! \$\endgroup\$ Mar 8, 2017 at 15:29
2
\$\begingroup\$

C, 216 215 212 bytes

i=64,l;f(){for(char*s="lfAravOharliEeltAchOoxtroTolFoteLndiAulieTilOimAikEovembeRscaRapAuebeComeOierrAangOniforMictoRhiskeYraYankeEulU";++i<91;printf("%c: %c%.*s%c\n",i,i,l,s,s[l]+32),s+=l+1)for(l=0;s[++l]>90;);}

Try it online!

A detailed, human readable, well commented and perfectly valid (no compiler warnings) version of the program can be found below:

#include <stdio.h>

int main() {
    // Uppercase characters designate the last character of a word
    char*s="lfAravOharliEeltAchOoxtroTolFoteLndiAulieTilOimAikEovembeRscaRapAuebeComeOierrAangOniforMictoRhiskeYraYankeEulU";

    int i = 64; // Consecutive character
    int l; // Word length

    // Loop `i` from A to Z; Shift `s` with word length
    // `s` always points to the beginning of a word
    for( ; ++i < 91; s += l + 1 ) {
        // Increment `l` until you reach the next capital letter
        for( l = 0; s[++l] > 90 ;);
        // Print the current character, the word without it's last letter
        // and the last letter lowercased
        printf( "%c: %c%.*s%c\n", i, i, l, s, s[l]+32 );
    }
}
\$\endgroup\$
2
  • 1
    \$\begingroup\$ Welcome to PPCG! Nice first post! \$\endgroup\$
    – Riker
    Mar 8, 2017 at 21:28
  • \$\begingroup\$ @ceilingcat Not only the char*s but the printf could go in there too. Thus saving another 3 bytes - a semicolon and 2 curly braces as we no longer need them since there is only one instruction in it's body - the other for loop. \$\endgroup\$ Mar 9, 2017 at 12:05
2
\$\begingroup\$

JavaScript ES6, 216 187 184 180 174 bytes

"AlfaBravoCharlieDeltaEchoFoxtrotGolfHotelIndiaJulietKiloLimaMikeNovemberOscarPapaQuebecRomeoSierraTangoUniformVictorWhiskeyXrayYankeeZulu".replace(/[A-Z]/g,`
$&: $&`).trim()

Saved a byte thanks to Neil. Saved 5 bytes thanks to ETHproductions.

console.log("AlfaBravoCharlieDeltaEchoFoxtrotGolfHotelIndiaJulietKiloLimaMikeNovemberOscarPapaQuebecRomeoSierraTangoUniformVictorWhiskeyXrayYankeeZulu".replace(/[A-Z]/g,`
$&: $&`).trim());

Japt, 127 bytes

`AlfaBŸvoC•r¦eDeltaE®oFoxÉ•GolfHÇUI˜iaJªietKiloL‹aMikeNovem¼rOs¯rPapaQue¼cRo´oSi€ŸTÂ
UnifŽmVÅ¡rW–skeyXŸyY„keeZªu`r"%A""
$&: $&

Try it online!

Saved 2 bytes thanks to obarakon.

\$\endgroup\$
5
  • \$\begingroup\$ I was wondering how else you could get rid of that leading newline - it would have actually been a byte cheaper than your previous approach to manually prepend A: A to the string. But you can still save another byte by using a literal newline character instead of \n. \$\endgroup\$
    – Neil
    Mar 7, 2017 at 10:23
  • \$\begingroup\$ Nice answers. You can use a literal newline in Japt as well. Also, replace accepts a string for its second argument and replaces any $&s in it with the match, so you can do e.g "\n$&: $&" for both langs instead of using functions. \$\endgroup\$ Mar 7, 2017 at 21:54
  • \$\begingroup\$ You can change @"\n{X}: {X}"} in Japt to just "\n$&: $&" :-) \$\endgroup\$ Mar 8, 2017 at 15:23
  • \$\begingroup\$ @ETHproductions Thanks for the help! \$\endgroup\$
    – Tom
    Mar 8, 2017 at 15:36
  • \$\begingroup\$ Nice answer! You can save a couple bytes by dropping the " x and inserting a -x flag into the input. Note that the flag adds 1 byte to the total bytes. \$\endgroup\$
    – Oliver
    Mar 9, 2017 at 0:16
2
\$\begingroup\$

PHP, 175 171 164 162 bytes

Note: no longer requires compressed file, uses IBM-850 encoding.

for($l=A;$c=LfaRavoHarlieEltaChoOxtrotOlfOtelNdiaUlietIloImaIkeOvemberScarApaUebecOmeoIerraAngoNiformIctorHiskeyRayAnkeeUlu[$i++];)echo$c<a?"
$l: ".$l++:"",$c|~▀;

Run like this:

php -nr 'for($l=A;$c=LfaRavoHarlieEltaChoOxtrotOlfOtelNdiaUlietIloImaIkeOvemberScarApaUebecOmeoIerraAngoNiformIctorHiskeyRayAnkeeUlu[$i++];)echo$c<a?"
$l: ".$l++:"",$c|~▀;';echo

Explanation

Prints every character individually (lowercased by OR with a space). If an uppercase character is encountered, it first prints a string of the form "\nA: A".

Tweaks

  • Saved 4 bytes by using another compression strategy
  • Saved 7 bytes by using a different delimiter (to combine assignment of $l with explode param), and not preventing a leading newline
  • Saved 2 bytes with a new method
\$\endgroup\$
1
\$\begingroup\$

Japt, 216 214 bytes

`A: Alfa
B: Bvo
C: Cr¦e
D: Delta
E: E®o
F: FoxÉ
G: Golf
H: HÇU
I: Iia
J: Jªiet
K: Kilo
L: La
M: Mike
N: Novem¼r
O: Os¯r
P: Papa
Q: Que¼c
R: Ro´o
S: Si
T: TÂ
U: Unifm
V: VÅ¡r
W: Wskey
X: Xy
Y: Ykee
Z: Zªu

Explaination: There is most likely a much better way to do it, but since i'm new I don't know it. I basically compressed the string with Oc" and put that string to be decompressed using Od"

If someone wants to help me save bytes by using something different from line breaks, I'd be happy to learn!

edit: Saved 2 bytes using ` instead of Od"

\$\endgroup\$
4
  • \$\begingroup\$ Using Try it online! it doesn't give the desired result :/ \$\endgroup\$
    – ʰᵈˑ
    Mar 7, 2017 at 9:59
  • \$\begingroup\$ @ʰᵈˑyes that could be, I didn't have enough time to check everything before I had to go to work. I might do it again (and better) after work. \$\endgroup\$ Mar 7, 2017 at 10:32
  • 1
    \$\begingroup\$ @ʰᵈˑ There are some unprintables in the string which don't show up in the Markdown. Try it online! \$\endgroup\$ Mar 7, 2017 at 21:57
  • \$\begingroup\$ @ETHproductions ah thanks for that, I didn't know \$\endgroup\$
    – ʰᵈˑ
    Mar 8, 2017 at 8:35
1
\$\begingroup\$

Pyke, 89 bytes

.d⻵㡺ᐒଆຳ뼙΋ÒΗ䊊繎ㅨڨǔᯍⰬᐓ❤ᄵ㤉ተ᤬䆰髨⨈性dc Fl5DhRJ": 
\$\endgroup\$
3
  • \$\begingroup\$ Do these characters happen to be in a specific single byte character set? \$\endgroup\$
    – Adám
    Mar 7, 2017 at 21:10
  • \$\begingroup\$ TIO gives a bad eval error and reports 161 bytes in the message. Either Pyke needs pushing there or something went wrong with a copy and paste here. @Adám if it was 1-1 it would be 41 bytes, utf-8 would be 88, but something definitely looks a bit off. \$\endgroup\$ Mar 7, 2017 at 21:43
  • \$\begingroup\$ @JonathanAllan it should be UTF-8. TIO runs it in not UTF-8. I think the byte-count might be wrong because it's measured as UTF-8 \$\endgroup\$
    – Blue
    Mar 8, 2017 at 17:38
1
\$\begingroup\$

Qbasic, 383 bytes

Not impressive, but for what it's worth:

dim a(1to 26)as string
a(1)="lfa
a(2)="ravo
a(3)="harlie
a(4)="elta
a(5)="cho
a(6)="oxtrot
a(7)="olf
a(8)="otel
a(9)="ndia
a(10)="uliet
a(11)="ilo
a(12)="ima
a(13)="ike
a(14)="ovember
a(15)="scar
a(16)="apa
a(17)="uebec
a(18)="omeo
a(19)="ierra
a(20)="ango
a(21)="niform
a(22)="ictor
a(23)="hiskey
a(24)="ray
a(25)="ankee
a(26)="ulu
for i=1to 26
?chr$(i+64);": ";chr$(i+64);a(i)
next
\$\endgroup\$
4
  • \$\begingroup\$ Old BASIC memories… Can't those be stored in a data statement then read inside the for..next loop? \$\endgroup\$
    – manatwork
    Mar 7, 2017 at 21:25
  • \$\begingroup\$ @manatwork, that's a good idea; I hadn't thought of it! \$\endgroup\$
    – anonymous2
    Mar 7, 2017 at 21:35
  • \$\begingroup\$ Wouldn't simply ?"A: Alfa" and so on be only 360 bytes? \$\endgroup\$
    – oerkelens
    Mar 9, 2017 at 15:47
  • \$\begingroup\$ @oerkelens, you could be right. I didn't even consider the possibility. :) \$\endgroup\$
    – anonymous2
    Mar 9, 2017 at 16:42
1
\$\begingroup\$

///, 220 bytes

/;/: /A;Alfa
B;Bravo
C;Charlie
D;Delta
E;Echo
F;Foxtrot
G;Golf
H;Hotel
I;India
J;Juliet
K;Kilo
L;Lima
M;Mike
N;November
O;Oscar
P;Papa
Q;Quebec
R;Romeo
S;Sierra
T;Tango
U;Uniform
V;Victor
W;Whiskey
X;Xray
Y;Yankee
Z;Zulu

Try it online!

-20 bytes thanks to @ETHproductions.

\$\endgroup\$
2
  • \$\begingroup\$ It's not hard, and it saves 20 bytes: Try it online! \$\endgroup\$ Mar 7, 2017 at 21:48
  • \$\begingroup\$ @ETHproductions I get it... for some reason I was overthinking it. I will update the answer. \$\endgroup\$
    – sporkl
    Mar 7, 2017 at 21:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.