Charlie, Oscar, Delta, Tiếng vọng


30

Một phần lớn của giao tiếp vô tuyến là Bảng chữ cái ngữ âm của NATO , mã hóa các chữ cái thành các từ để làm cho chúng dễ hiểu hơn thông qua comms. Công việc của bạn, nếu bạn muốn chấp nhận nó, là in chúng từng cái một.

Bạn phải in chuỗi chính xác này ra thiết bị xuất chuẩn:

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

Quy tắc:

  • Chương trình của bạn không có đầu vào
  • Sơ hở tiêu chuẩn là không được phép .
  • Nếu có bất kỳ nội dung nào trong ngôn ngữ của bạn chuyển các chữ cái thành các chất tương tự NATO của chúng, bạn không thể sử dụng chúng (Tôi đang nhìn vào bạn Mathicala).
  • Bạn có thể có dấu cách và một dòng mới.


4
Tôi sẽ đóng cái này dưới dạng dupe vì nó không có bất kỳ cấu trúc có thể khai thác nào cho phép các lược đồ nén tùy chỉnh thực hiện tốt hơn nén tích hợp và thách thức mục tiêu là thách thức tiêu chuẩn thực tế của chúng tôi đối với nén tích hợp.
Mego

1
Quan hệ gần gũi. Nếu bất cứ điều gì tôi gọi nó là một bản sao của cái này, nhưng nó cho phép mọi người chọn từ riêng của họ, điều thực sự khiến việc nén trở nên khả thi hơn rất nhiều.
Martin Ender

3
không nên là người đầu tiên A: Alpha?
SeanC

3
@SeanC: Theo wikipedia (xem liên kết trong câu hỏi), không. Đó là ATIS, không phải NATO. Nhưng sau đó, nó nên Juliett, không JulietX-raythay vì Xray.
Tít

Câu trả lời:


18

Python 2 , 189 186 byte

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

Hãy thử trực tuyến!


Trước đây: (điều này thật tuyệt, nhưng tôi nhận ra phiên bản đơn giản hơn có thể được rút ngắn bằng một byte)

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

12

Thạch , 76 byte

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

Hãy thử trực tuyến!

Làm sao?

Khá nhiều chỉ là giá trị từ điển và nén. Mã giữa »chỉ là một giá trị được nén sẽ tạo thành chuỗi "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"bằng cách tra cứu tất cả các từ (với các tiền tố không gian duy nhất, ngoại trừ "Alfa") trong từ điển của Jelly (ngoại trừ " Xray"không có trong từ điển, vì vậy giá trị chuỗi trực tiếp " X"và từ điển mục nhập "ray"được sử dụng thay thế).

Phần còn lại của mã làm phần còn lại:

“...»ḲØ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

(LƯU Ý: Tôi chưa bao giờ lập trình trong Jelly.) Khi tôi thấy mã của bạn, tôi đang tự hỏi hai điều: 1. Bạn hiện đang lặp qua bảng chữ cái và nối chúng với các từ. Có thể trong Jelly có được ký tự đầu tiên của chuỗi, vì vậy bạn lặp qua các từ thay vì bảng chữ cái và nối chúng với First_letter_of_word + ":" + word? Và 2. Bạn lấy tất cả các từ bao gồm khoảng trắng và sau đó phân tách bằng dấu cách. Có thể bao gồm - chia bởi các chữ in hoa hàng đầu? Không biết các khoảng trắng này thậm chí có cung cấp thêm byte ở dạng nén hay không và liệu chúng có thể được giảm với mô tả của tôi ở 2.
Kevin Cruijssen

1
@KevinCruijssen (1) có, có thể sử dụng chữ cái đầu tiên của mỗi từ, tuy nhiên sẽ không ngắn vì sản lượng bảng chữ cái là một nguyên tử hai byte. (2) có, có thể phân tách chữ in hoa, nhưng đáng ngạc nhiên là việc nén chuỗi không có khoảng trắng thực sự dài hơn (nhiều từ có khoảng trắng đứng đầu thực sự có trong từ điển, cũng như tất cả những từ này viết hoa).
Jonathan Allan

2
Từ điển không chứa không gian hàng đầu. Tuy nhiên, khi giải nén nhiều từ liên tiếp, mặc định là phân tách chúng bằng khoảng trắng; từ đầu tiên sẽ không có khoảng trắng, nhưng tất cả các từ sau sẽ có.
Dennis

11

Retina, 156 bytes

Byte count assumes ISO 8859-1 encoding.


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

Try it online!


11

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

2
Get it down to 98 using this compressed string instead: ”AlfaІvo¼¯¤œ®È¨›trotŠˆƒ‹Š™ÈŸt Kilo´àma—……ÍЗŽêpa¼°«Äoµ†Çâgo¸šÉµ Whiskey Xrayµ‹nkeeâ¸lu”.
Erik the Outgolfer

@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 :)
Emigna

6

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

6

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();
  }
}

Should work with Java 5 and all subsequent versions.
Holger

5

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' ...

Thanks! This was a bit messier!, and three bytes longer...
Stewie Griffin

Ah, yes, 'split' would be longer here
Luis Mendo

'split' was shorter: 209 :)
Stewie Griffin

I see! Well done!
Luis Mendo

You can split on spaces and save 5 more bytes
Luis Mendo

5

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


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.
manatwork

Instead of constant PREG_SPLIT_NO_EMPTY, better use its value: 1. But personally I would tweak the regular expression instead: /\B(?=[A-Z])/.
manatwork

1
Thanks @insertusernamehere i'll make that edit now :D Still getting used to codegolfing
ʰᵈˑ

That would be one byte shorter with a plain array instead of the preg_split.
Titus

1
10 characters shorter: echo preg_replace('/([A-Z])[a-z]+/',"$1 = $0\n",Alfa...Zulu);
Dewi Morgan

4

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

4

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>


This time competitive ? ;)
Christoph

-13 bytes with gzinflate-ing the result of gzdeflate(Alfa...Zulu).
Titus

Unfortunately, no leading newline is allowed, only a (single) trailing newline
aross

@aross: see the OP´s comment from yesterday: and for your other question, yes, but just one.
Titus

4

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.


4

Python 2, 186 182 bytes

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

Try it online!


2
see comments on question: one leading newline is (now) accepted
Titus

Welcome to PPCG! Nice stuff.
Jonathan Allan

4

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!


How would I compile this?
Itay Grudev

1
@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
chris

@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.
Itay Grudev

2
@ItayGrudev, The way I see it, the question only asked for the functionality, not a full, self-contained program.
chris

1
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.
gastropner

3

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


2

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.


2

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.


2
Golf your original down to 180-1 with for($c=A;$s=[lfa,...,ulu][+$i++];$c++)echo"$c: $c$s\n";. Nice regex though.
Titus

@Titus I had in mind there must be a better way but switched to preg. Thanks for the tip !
Christoph

2

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

2

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

2

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!


+1. The {,} trick in the brace expansion is a very clever way to double up each list member!
Digital Trauma

2

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.


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
manatwork

¯\_(ツ)_/¯ 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.
ʰᵈˑ

2

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.


2

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.


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')[$_]}
Matt

@Matt Oh sure, that makes sense. Thanks!
AdmBorkBork

2

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 );
    }
}

1
Welcome to PPCG! Nice first post!
Rɪᴋᴇʀ

@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.
Itay Grudev

2

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.


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.
Neil

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.
ETHproductions

You can change @"\n{X}: {X}"} in Japt to just "\n$&: $&" :-)
ETHproductions

@ETHproductions Thanks for the help!
Tom

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.
Oliver

2

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

1

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"


Using Try it online! it doesn't give the desired result :/
ʰᵈˑ

@ʰᵈˑ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.
Martijn Vissers

1
@ʰᵈˑ There are some unprintables in the string which don't show up in the Markdown. Try it online!
ETHproductions

@ETHproductions ah thanks for that, I didn't know
ʰᵈˑ

1

Pyke, 89 bytes

.d⻵㡺ᐒଆຳ뼙΋ÒΗ䊊繎ㅨڨǔᯍⰬᐓ❤ᄵ㤉ተ᤬䆰髨⨈性dc Fl5DhRJ": 

Do these characters happen to be in a specific single byte character set?
Adám

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.
Jonathan Allan

@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
Blue

1

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

Old BASIC memories… Can't those be stored in a data statement then read inside the for..next loop?
manatwork

@manatwork, that's a good idea; I hadn't thought of it!
anonymous2

Wouldn't simply ?"A: Alfa" and so on be only 360 bytes?
oerkelens

@oerkelens, you could be right. I didn't even consider the possibility. :)
anonymous2

1

///, 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.


It's not hard, and it saves 20 bytes: Try it online!
ETHproductions

@ETHproductions I get it... for some reason I was overthinking it. I will update the answer.
Comrade SparklePony
Khi sử dụng trang web của chúng tôi, bạn xác nhận rằng bạn đã đọc và hiểu Chính sách cookieChính sách bảo mật của chúng tôi.
Licensed under cc by-sa 3.0 with attribution required.