查理,奥斯卡,三角洲,回声


30

无线电通信的重要组成部分是北约语音字母表,该字母表将字母编码为单词,使它们更易于通过通讯理解。您的工作(如果希望接受)是一张一张地打印。

您必须将这个确切的字符串打印到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

规则:

  • 您的程序无需输入
  • 不允许使用标准漏洞。
  • 如果您的语言中有任何内置函件可以将字母转换为它们的北约等值符号,则您可能不会使用它们(我正在寻找Mathematica)。
  • 您可能有尾随空格和一个尾随换行符。


4
我将其关闭,因为它没有任何可利用的结构来允许自定义压缩方案比内置压缩更好地执行,而目标挑战是我们对内置压缩的事实上的标准挑战。
Mego

1
密切相关。如果有什么话,我会称呼它为“重复”,但它使人们可以选择自己的单词,这实际上使压缩成为可能。
Martin Ender

3
第一个不应该A: Alpha吗?
SeanC '17

3
@SeanC:据维基百科(请参阅相关链接),没有。那是ATIS,不是北约。但是,应该是JuliettJulietX-ray不是和Xray
泰特斯

Answers:


18

Python 2中189个 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

在线尝试!


上一篇:(这很酷,但是我意识到可以将简单的版本缩短一个字节)

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"Jelly词典中的所有单词(除了,带单个空格前缀,除外)来形成字符串(除非" 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

(注意:我从来没有在Jelly中编程。)当我看到您的代码时,我想知道两件事:1.您当前在字母上循环并将它们与单词连接在一起。在Jelly中是否可以获取字符串的第一个字符,因此您可以遍历单词而不是字母,然后将它们与first_letter_of_word +“:” + word结合起来?2.您检索所有单词,包括空格,然后按空格分割。是否可以使用大写大写字母来进行包容性拆分?不知道如果这些空间,甚至给予额外的字节,其压缩格式或没有,如果他们能与我的描述在2.减少
凯文Cruijssen

1
@KevinCruijssen(1)是的,可以使用每个单词的第一个字母,但是它不会那么短,因为字母产量是一个两字节的原子。(2)是的,可以使用大写字母进行拆分,但是令人惊讶的是,不带空格的字符串的压缩实际上更长(许多带有前导空格的单词实际上字典中,所有这些都带有大写字母)。
乔纳森·艾伦

2
字典不包含前导空格。但是,当对一行中的多个单词进行解压缩时,默认设置是将它们用空格隔开。第一个单词不会有前导空格,但随后的所有单词都会有。
丹尼斯,

11

视网膜,156字节

字节数假定为ISO 8859-1编码。


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

在线尝试!


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”
暴民埃里克(Erik the Outgolfer)'17

@EriktheOutgolfer:谢谢!我相信,我看了pali字典中的,但我必须错过了他们。我没有考虑yazu而是
说了句

6

Ruby,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和所有后续版本。
Holger

5

八度,215个 210 209字节

感谢Luis Mendo,节省了5个字节。感谢Luis Mendo,我节省了4个字节,但是更改方法又帮助我节省了一个字节

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

谢谢!这有点混乱!和三个字节更长的时间
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
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.