チャーリー、オスカー、デルタ、エコー


30

無線通信の大部分はNATO Phonetic Alphabetです。これは、通信で文字を理解しやすくするために文字を単語としてエンコードします。あなたがそれを受け入れたいなら、あなたの仕事はそれらを一つずつ印刷することです。

この正確な文字列を標準出力に出力する必要があります。

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

ルール:

  • あなたのプログラムは何も入力しません
  • 標準の抜け穴は許可されていません。
  • あなたの言語にNATO同等者に手紙を送るビルトインがある場合、それらを使用することはできません(私はあなたを見ていますMathematica)。
  • 末尾のスペースと末尾の改行が1つある場合があります。


4
カスタムの圧縮スキームが組み込みの圧縮よりも優れたパフォーマンスを発揮できる悪用可能な構造がないため、これをだましとして閉じています。ターゲットの課題は、組み込みの圧縮に関する事実上の標準の課題です。
メゴ

1
密接に関連しています。どちらかといえば、これをだましと呼びますが、人々が自分の言葉を選択することを可能にし、実際に圧縮をさらに可能にしました。
マーティンエンダー

3
最初のものはいけませんA: Alphaか?
SeanC

3
@SeanC:ウィキペディア(問題のリンクを参照)によると、いいえ。NATOではなくATISです。しかし、そうJuliettではなくJuliet、のX-ray代わりにである必要がありXrayます。
タイタス

回答:


18

Pythonの2189の 186バイト

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

オンラインでお試しください!


前:(これはクールでしたが、単純なバージョンは1バイト短くすることができることに気付きました)

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

12

ゼリー、76 バイト

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

オンラインでお試しください!

どうやって?

辞書の値と圧縮だけです。間のコード»文字列を形成するだけで圧縮された値である"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"(を除いて、単一のスペース接頭辞を持つ、すべての単語を調べることにより、"Alfa"ゼリーの辞書(以外で)" Xray"どの辞書にありませんので、直接文字列値" X"と辞書"ray"代わりにエントリが使用されます)。

残りのコードは残りを行います:

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

(注:私はゼリーでプログラミングしたことはありません。)あなたのコードを見たとき、私は2つのことを疑問に思っています。Jellyで文字列の最初の文字を取得することは可能です。したがって、アルファベットではなく単語をループし、それらをfirst_letter_of_word + ":" + wordで結合しますか?2.スペースを含むすべての単語を取得し、スペースで分割します。先頭の大文字で包含分割することは可能ですか?これらのスペースもその圧縮された形でかいない余分なバイトを与え、彼らは2で私の説明を減少させることができる場合場合は考えていません
ケビンCruijssen

1
@KevinCruijssen(1)はい、各単語の最初の文字を使用することは可能ですが、アルファベットの出力が2バイトのアトムであるため、短くなることはありません。(2)はい、それは大文字で分割することは可能ですが、意外にスペースを含まない文字列の圧縮が実際に長いです(先頭のスペースで多くの単語が実際にあるなど、これらのすべてが、辞書との総額を)。
ジョナサンアラン

2
辞書に先頭のスペースは含まれません。ただし、複数の単語を連続して解凍する場合、デフォルトではスペースで区切られます。最初の単語には先頭のスペースはありませんが、後続のすべての単語にはスペースが含まれます。
デニス


11

05AB1E102 98バイト

Erik the Outgolferのおかげで4バイト節約

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

オンラインでお試しください!

説明

05AB1Eの辞書の単語に対して辞書圧縮を使用します。
他の単語に対して可能な限り、部分的な辞書圧縮を使用します。
どちらも不可能な平文の言葉。

#          # 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
代わりに次の圧縮文字列を使用して、98まで下げてください”AlfaІvo¼¯¤œ®È¨›trotŠˆƒ‹Š™ÈŸt Kilo´àma—……ÍЗŽêpa¼°«Äoµ†Çâgo¸šÉµ Whiskey Xrayµ‹nkeeâ¸lu”
エリックアウトゴルファー

@EriktheOutgolfer:ありがとう!辞書で探していたpaと確信していましたが、li見逃していたに違いありません。私は考えなかったyazu、言葉としても:)
エミグナ

6

ルビー、169文字

(主にJonathan AllanPython 2ソリューションに基づいています。アイデアが気に入ったら、元の答えに賛成してください。)

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

サンプル実行:

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バイト

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

説明:

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

テストコード:

ここで試してみてください。

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

Java 5以降のすべてのバージョンで動作するはずです。
ホルガー

5

オクターブ、215 210 209バイト

Luis Mendoのおかげで5バイト節約されました。Luis Mendoのおかげで4バイト節約できましたが、アプローチを変更するともう1つ節約できます

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

オンラインでお試しください!

スペースを削除した場合、25バイト節約できますが、正規表現を使用する必要があります。正規表現自体にはかなりのバイト数がかかり、すべての単語の大文字も削除され、単語が残りますlfa, ravoなどを。したがって、新しい文字列を先頭の文字と連結する必要があります。これにはすべてバイトがかかります。

古い説明:

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

ありがとう!これは少し面倒でした!、および3バイト長...
Stewieグリフィン

ああ、はい、'split'ここで長くなります
ルイスメンドー


そうですか!よくやった!
ルイスメンドー


5

PHP、202 227 196 187バイト

9バイトを節約してくれたDewi Morganに感謝

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

https://repl.it/GMkH/1


古いバージョン

31バイトを節約してくれたmanatworkinsertusernamehereに感謝します!

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

https://eval.in/749541

以前のバージョンでは出力が間違っていたことに気付いたinsertusernamehereに感謝します。

$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


なぜ可変なの$aか?のパラメータ全体でpreg_split()呼び出し全体を移動するだけforeachです。その後、周囲のスペースはasもう必要ありません。
マナトワーク

constantの代わりにPREG_SPLIT_NO_EMPTY、その値をより適切に使用します1。しかし個人的には、代わりに正規表現を微調整します/\B(?=[A-Z])/
マナトワーク

1
おかげで@insertusernamehere私は今その編集を行います:Dまだコードゴルフに慣れている
ʰᵈˑ

これは、の代わりにプレーンな配列で1バイト短くなりpreg_splitます。
タイタス

1
10文字短縮:echo preg_replace('/([A-Z])[a-z]+/',"$1 = $0\n",Alfa...Zulu);
デウィモーガン

4

Brachylog、178バイト

"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?ẉ}ᵐ

オンラインでお試しください!

説明

"…"ṇ₁               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:昨日のOPのコメントを参照してください:and for your other question, yes, but just one.
タイタス

4

x86アセンブリ、512バイト

NASMでコンパイルされ、QEMUでテストされました。ブートするには、ブートセクターの最後に2バイトのブート署名(ファイルに510バイト)を入れる必要があるため、コンパイルされたコードをゼロで埋める317バイトを失いました。これは私の最初のゴルフですので、私はすべての巨大なエラーについて謝罪する必要があります。

[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

出力

これは上記のコードが出力するものです。ご覧のとおり、A:Alfa is missing and that is because the prompt is 25 lines tall... Above codes output

証明するために私が印刷されたアルファ:Aが、私は交換し0,"ulu"32,"Z: Zulu"ズールーはヤンキーと同じ行に1になるように。 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
弊社のサイトを使用することにより、あなたは弊社のクッキーポリシーおよびプライバシーポリシーを読み、理解したものとみなされます。
Licensed under cc by-sa 3.0 with attribution required.