72

# 任务

``````zeronineoneoneeighttwoseventhreesixfourtwofive
``````

``````zero nine one one eight two seven three six four two five
``````

# 规则

• 输入始终是字符串。它始终由一个或多个小写的英文数字名称组成，折叠在一起，仅此而已。

• 英文数字名称为`zero one two three four five six seven eight nine`
• 输出可以是字符串列表，也可以是新字符串，其中的数字由非字母，非空字符串分隔。（您的输出也可以选择在开头或结尾处包含这样的字符串，并且分隔符不必保持一致。因此，即使这样，`{{ zero0one\$\$two );`也是有效的答案（如果很荒谬）`zeroonetwo`。）

• 以字节为单位的最短答案将获胜。

# 测试用例

``````three -> three
eightsix -> eight six
fivefourseven -> five four seven
ninethreesixthree -> nine three six three
foursixeighttwofive -> four six eight two five
fivethreefivesixthreenineonesevenoneeight -> five three five six three nine one seven one eight
threesevensevensixninenineninefiveeighttwofiveeightsixthreeeight -> three seven seven six nine nine nine five eight two five eight six three eight
zeroonetwothreefourfivesixseveneightnine -> zero one two three four five six seven eight nine
``````

28

DJMcMayhem

1

Lynn

Michael Dorgan

3
@MichaelDorgan（或任何其他C编码器），您可能想看看我在Befunge答案中使用的算法。将其直接转换为C可以得到104字节的解决方案，我认为它胜过所有现有的C答案。我敢打赌，具有更高C高尔夫技能的人可以改善这一点。
James Holderness

17

# C（gcc），89 80 76 75 72 71 70 69字节

``f(char*s){*s&&f(s+printf(" %.*s",""[(*s^s)%12],s)-1);}``

（89）归功于gastropner进行XOR哈希处理。
（76）感谢Toby Speight提出的使用第一和第三的想法。
（75）感谢迈克尔·多根`'0'``48`
（72）感谢Michael DorganLynn提供带有控制字符的文字。
（69）感谢林恩`x?y:0``x&&y`

``````f (char *s) {        /* K&R style implicit return type. s is the input. */
*s&&f(           /* Recurse while there is input. */
s+printf(    /* printf returns the number of characters emitted. */
" %.*s", /* Prefix each digit string with a space. Limit
* how many bytes from the string to print out. */
""
/* Magic hash table, where the value represents
* the length of the digit string. The string
* is logically equivalent to
* "\04\01\05\03\04\05\05\04\04\01\03\03" */
[(*s^s)%12],
/* The XOR hash (mod 12) */
s)       /* The current digit. */
-1);}    /* Subtract 1 for the space. */``````

11

# Python 2，50个字节

``````import re
re.compile('..[eox]|[tse]?....').findall``````

-3感谢Lynn
-4感谢Uriel答案的正则表达式。

3

Lynn

@Lynn等等，等我完成！:-P编辑：实际上是3个字节。

@Lynn另外，您应该将其转为代码高尔夫 正则表达式。;）
Erik the Outgolfer

9

# Befunge，87 85 81 76字节

``````<*"h"%*:"h"\$_02g-v1\$,*<v%*93,:_@#`0:~
"@{&ruX;\"00^ !: _>_48^>+:"yp!"*+%02p0
``````

Befunge没有任何字符串操作指令，因此我们在处理它们时会在遇到的最后三个字符中创建一种哈希。

Michael Dorgan's

^，我记得看到这个词是mojibake（もじばけ）。您如何找到@JamesHolderness这些数字（基础104，模块3187）？

@Zacharý我写了一个Python脚本，测试了不同的基础和Mod组合，以找到针对所有预期输入运行时可以产生正确结果的组合。一旦知道了哪种组合有效，我便通过Befunge数生成器运行所得的哈希输出，以找出产生最短代码的代码。
James Holderness

6

# Java（OpenJDK 8），55 46 43字节

``s->s.replaceAll("one|tw|th|f|z|s|.i"," \$0")``

3

Kevin Cruijssen '17

@KevinCruijssen谢谢！老实说，我很惊讶Java比JavaScript短。通常，当我阅读挑战时，JS会短很多。

JavaScript应该短2个字节（用`g`regex后缀代替`All`）。

@Neil在这里更长，因为它正在使用`f=(s)=>`而不是`s->`，它短了4个字节。

1
@LucaH-根据FrownyFrog的建议，您可以将几个两个字母的字符串减少为单个字符：z | f | s而不是ze | fo | fi | si | se /
Forty3

6

# C（GCC） ，179 159 146 139 137 116 107 103 102字节

``c,h;f(char*s){while(c=*s++)putchar(c),h=h%10816*104+c%27,memchr("&;@X\\ru{",h%3817,9)&&putchar(h=32);}``

``````
int c;
int h;
void f(char*s)
{
while(c=*s++)
putchar(c),
h=h%10816*104+c%27,
memchr("&;@X\\ru{",h%3817,9)?putchar(h=32):1;
}``````

``````#define p putchar
#define q c=*s++
c,x;f(char*s){while(q){p(c);x=strchr("tse",c);p(q);p(q);if(!strchr("eox",c)){p(q);if(x)p(q);}p(' ');}}``````

``````// Above code makes a macro of putchar() call.

void f(char *s)
{
char c;
while(c = *s++)
{
putchar(c);
int x = strchr("tse", c);

putchar(*s++);
putchar(c=*s++);

if(!strchr("eox", c))
{
putchar(*s++);
if(x)
{
putchar(*s++);
}
}
putchar(' ');
}
}``````

Michael Dorgan

Xcoder先生17年

2

1
109个字节`c,h=0;f(char*s){while(c=*s++)putchar(c),h=h%10816*104+c%27,c=h%3817,printf(" "+!(c&&strchr("&;@X\\ru{",c)));}`
gastropner

Michael Dorgan

5

# JavaScript，66 57 52 44 41字节

`s=>s.replace(/one|t[wh]|.i|[fsz]/g," \$&")`

FrownyFrog很好地抓住了使用2个字符的可能性..“ 1”除外，其中纯2个字符的校验可能会弄乱零值。编辑：单打`f``s`FrownyFrog的好收获，我忽略了我的前两场高尔夫。

Titus提供了一个较小的RegEx。我觉得我们最终将走向Uriel的正则表达式。

FrownyFrog

FrownyFrog

1
@FrownyFrog o首先出现，因此被首先认可。
Uriel's

1
`on|t[wh]|.i|[fsz]`（-4个字节）
Titus

2
@Titus-不幸的是，`on|`将匹配`zeronine`渲染`zer onine`
Forty3

5

# 视网膜，24 23字节

``````!`..[eox]|[fnz]...|.{5}
``````

1
`.....`-> `.{5}`工作吗？
FrownyFrog

5

# C，103 99字节

``char*r="f.tzuonresn.xgv";f(char*s){*s&&f(s+printf("%.*s ",(strrchr(r,s)-strchr(r,*s))%10,s)-1);}``

## 测试程序

``````#include <stdio.h>
int main(int argc, char **argv)
{
for (int i = 1;  i < argc;  ++i) {
f(argv[i]);
puts("");
}
}``````

1

##

4

# J，37 35字节

``````rplc'twthsiseeinionzef'(;LF&,)\~_2:
``````

2

@GalenIvanov TIO具有最新版本，可能是J的回归
。– FrownyFrog

4

# C（gcc），106字节 104字节

-2个字节，感谢@jxh

``c;f(char*s){char*t=" \$&=B*,29/?";while(*s)for(c=4+(strchr(t,(*s^s)+35)-t)/4;c--;)putchar(c?*s++:32);}``

XOR确实是我们最大的盟友。

Michael Dorgan's

1
`s`会更短。
jxh

@jxh不错！更新。
gastropner

3

# 视网膜，28字节

``````t[ewh]|[zfs]|(ni|o)ne|ei
\$&
``````

3

# Pyth，35 27 23字节

``````:Q"..[eox]|[tse]?...."1
``````

3

# 点，27字节

``````aR`[zfs]|one|[ent][iwh]`s._
``````

``````a@`..[eox]|[tse]?....`
``````

3

# 果冻， 23  21 字节

``````ḣ3OP%953%7%3+3ɓḣṄȧṫḊÇ
``````

### 怎么样？

1. 使用一些序数数学来找到字符列表中第一个单词的长度；
2. 打印单词加上换行符；和
3. 从字符列表的开头删除单词

``````word   head3  ordinals       product  %953  %7  %3  +3 (=len(word))
zero   zer    [122,101,114]  1404708   939   1   1   4
two    two    [111,110,101]  1233210    28   0   0   3
one    one    [116,119,111]  1532244   773   3   0   3
three  thr    [116,104,114]  1375296   117   5   2   5
four   fou    [102,111,117]  1324674     4   4   1   4
five   fiv    [102,105,118]  1263780   102   4   1   4
six    six    [115,105,120]  1449000   440   6   0   3
seven  sev    [115,101,118]  1370570   156   2   2   5
eight  eig    [101,105,103]  1092315   177   2   2   5
nine   nin    [110,105,110]  1270500   151   4   1   4
``````

``````ḣ3OP%953%7%3+3ɓḣṄȧṫḊÇ - Main link, list of characters           e.g. "fiveeight..."
ḣ3              - head to index three                                "fiv"
O             - ordinals                                           [102,105,118]
P            - product                                            1263780
%953        - modulo by 953                                      102
%7      - modulo by seven                                    4
%3    - modulo by three                                    1

ɓ - dyadic chain separation swapping arguments...
... ḣṄȧṫḊÇ ...
ḣ         - head to index                                        "five"
Ṅ        - print the result plus a line-feed and yield the result
ṫ      - tail from index                                      "eeight..."
ȧ       - and (non-vectorising)                                "eeight..."
Ḋ     - dequeue                                               "eight..."
Ç    - call the last link (Main*) as a monad with this as input
-       * since it's the only link and link indexing is modular.
``````

1

ØrjanJohansen

OP明确声明“您的输出也可以选择在开头或结尾处包含此类字符串”，并且该程序实际上随其进行打印，因此无论如何都必须在强制终止之前生成输出。

Jonathan Allan

3

# C 168 ，145，144，141字节

a，b; main（i）

141

``````#define s|a%1000==
a,i;main(b){for(;~scanf("%c",&b);printf(" %c"+!!i,b),a|=b%32<<5*i++)if(i>4|a%100==83 s 138 s 116 s 814 s 662 s 478)a=i=0;}
``````

144

``````a,i;main(b){for(;~(b=getchar());printf(" %c"+!!i,b),a=a*21+b-100,++i)if(i>4|a==204488|a==5062|a==7466|a==23744|a==21106|a==6740|a==95026)a=i=0;}
``````

168

``````i,a;main(b){for(;~scanf("%c",&b);printf(" %c"+!!i,b),a|=b<<8*i++)if(i>4|a==1869768058|a==6647407|a==7305076|a==1920298854|a==1702259046|a==7891315|a==1701734766)a=i=0;}
``````

``````i,a;main(b){
for(;~scanf("%c",&b); // for every char of input
printf(" %c"+!!i,b), // print whitespace if i==0 , + char
a|=b<<8*i++ // add char to a for test
)
if(
i>4| // three seven eight
a==1869768058|      // zero
a==6647407|        // one
a==7305076|       // two
a==1920298854|   //four
a==1702259046|  //five
a==7891315|    //six
a==1701734766 //nine
) a=i=0; //reset i and a
}
``````

146使用字符串比较

``````#define s|a==*(int*)
a,b;main(i){for(;~(b=getchar());printf(" %c"+!!i,b),a|=b<<8*i++)if(i>4 s"zero"s"one"s"two"s"four"s"five"s"six"s"nine")a=i=0;}
``````

``````#define F(x)if(scanf(#x+B,&A)>0){printf(#x,&A);continue;}
B;A;main(i){for(;i;){B=1;F(\40e%4s)F(\40th%3s)F(\40se%3s)F(\40o%2s)B=2;F(\40tw%1s)F(\40si%1s)B=1;F(\40%4s)i=0;}}
``````

2

# 果冻，44字节

``````Ṛ¹Ƥz⁶ZUwÐ€“¢¤Ƙƒ⁺6j¹;Ċ-ḶṃżṃgɼṘƑUẏ{»Ḳ¤\$€Ẏḟ1Ṭœṗ
``````

3

2

# R，109位元组

``function(x)for(i in utf8ToInt(x)){F=F+i;cat(intToUtf8(i),if(F%in%c(322,340,346,426,444,448,529,536,545))F=0)}``

Michael Dorgan's

Michael M

2

``````f[c]=[c]
f(h:t)=[' '|s<-words"z one tw th f s ei ni",and\$zipWith(==)s\$h:t]++h:f t``````

``````f(h:t)=                      h:f t -- recurse over input string
[' '|s<-               ]++      -- and add a space for each string s
words"z one tw th f s ei ni" -- from the list ["z","one","tw","th","f","s","ei","ni"]
,and\$zipWith(==)s\$h:t        -- which is a prefix of the current string``````

2

# Python 3（无正则表达式），85字节

``````i=3
while i<len(s):
if s[i-3:i]in'ineiveroneghtwoureesixven':s=s[:i]+' '+s[i:]
i+=1``````

2

Laikoni '17

2

# Excel，181字节

``````=SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(A1,"z"," z"),"on"," on"),"tw"," tw"),"th"," th"),"f"," f"),"s"," s"),"ei"," ei"),"ni"," ni")
``````

2

# Z80汇编，46 45字节

``````; HL is the address of a zero-terminated input string
; DE is the address of the output buffer

Match5: ldi                                 ; copy remaining characters
Match4: ldi
Match3: ld a,32 : ld (de),a : inc de        ; and add space after a matched word.

Uncollapse:

ld a,(hl) : ldi : or a : ret z      ; copy first byte (finish if it was zero)
ex af,af'                           ; and save its value for later.

ldi : ld a,(hl) : ldi               ; copy second and third bytes

cp 'e' : jr z,Match3                ; is the third letter 'e' or 'o' or 'x'?
cp 'o' : jr z,Match3
cp 'x' : jr z,Match3

ex af,af'                           ; now look at the first letter

cp 'e' : jr z,Match5                ; is it 't' or 's' or 'e'?
sub 's' : jr z,Match5
dec a : jr z,Match5
jr Match4
``````

（将Uriel的酷正则表达式适应不符合正则表达式的环境很有趣）。

1

# 果冻，40 39字节

``````“¢¤Ƙƒ⁺6j¹;Ċ-ḶṃżṃgɼṘƑUẏ{»Ḳe€€@ŒṖẠ€TḢịŒṖK
``````

## 这个怎么运作

``````“¢¤Ƙƒ⁺6j¹;Ċ-ḶṃżṃgɼṘƑUẏ{»Ḳe€€@ŒṖẠ€TḢịŒṖK
“¢¤Ƙƒ⁺6j¹;Ċ-ḶṃżṃgɼṘƑUẏ{»                 = the compressed string of the digit names
Ḳ                = split at spaces
e€€@ŒṖ          = check whether each member of each partition of the argument is a digit.
Ạ€        = A function that checks whether all values of an array are true, applied to each element.
T       = Finds the index of each truthy element
Ḣ      = Grab the first element, since we have a singleton array
ịŒṖ  = The previous command gives us the index, partition that splits the input into digits. This undoes it and gives us the partition.
K = Join the array of digits with spaces
``````

1

# Python 3，无正则表达式， 83 68 65  63字节

-15感谢Lynn（将其重构为单个函数），
-3感谢Lynn（避免使用更多算术索引到列表中）
...导致另外节省2个字节（避免使用负模数的括号）:)

``def f(s):h=ord(s)*ord(s)%83%-7%-3+5;print(s[:h]);f(s[h:])``

Lynn

0

# 果冻，36个字节

``````œṣj⁶;\$}
W;“€ɗİẒmṫṃ¦¦ạỊɦ⁼Fḷeṭḷa»s2¤ç/
``````

``````for x in ['ze', 'ni', 'on', 'tw', 'th', ...]:
replace x in input by space+x
``````

0

# Mathematica，125个字节

``````(s=#;While[StringLength@s>2,t=1;a="";While[FreeQ[IntegerName/@0~Range~9,a],a=s~StringTake~t++];Print@a;s=StringDrop[s,t-1]])&
``````

TIO输出有关“ CountryData”（???）的错误消息，

0

# q / kdb +，59个 51字节

``````{asc[raze x ss/:string`z`one`tw`th`f`s`ei`ni]cut x}
``````

``````q){asc[raze x ss/:string`z`one`tw`th`f`s`ei`ni]cut x}"threesevensevensixninenineninefiveeighttwofiveeightsixthreeeight"
"three"
"seven"
"seven"
"six"
"nine"
"nine"
"nine"
"five"
"eight"
"two"
"five"
"eight"
"six"
"three"
"eight"
``````

``````{asc[raze x ss/:string`z`one`tw`th`f`s`ei`ni]cut x} / ungolfed solution
{                                                 } / lambda with implicit x as input
cut x  / cut x at indices given by left
asc[                                       ]       / sort ascending
string`z`one`tw`th`f`s`ei`ni        / string list ("z","one",...)
x ss/:                                    / string-search left with each right
raze                                           / reduce down list
``````

46个字节，进行一些简单的打高尔夫球，用k个电话代替q个电话，但仍然是一个沉重的解决方案。

`asc[(,/)x ss/:(\$)`z`one`tw`th`f`s`ei`ni]cut x:`