如何将省略号复数?


14

这显然是省略号。

受启发 聊天消息的

你的挑战

给定一个列表,空格或逗号分隔的字符串,用省略号将其括起来。

省略一个单词:

  1. 从单词开始。
  2. 将原始单词的第一个字母添加到末尾。
  3. 在原始单词的最后一个字母的末尾加上2。
  4. 将原始单词的倒数第二个字母添加到末尾。
  5. 将原始单词的第一个字母添加到末尾。
  6. 将原始单词的最后一个字母添加到末尾。
  7. 重复步骤5和6。
  8. 你完成了!

您可以假设:

  • 输入的单词只能是字母数字
  • 输入和输出可以是用空格分隔的字符串或列表
  • 输入将仅包含单词
  • 单词长度至少为2个字母
  • 输入将匹配正则表达式 /^[a-z0-9]{2,}( [a-z0-9]{2,})*$/i
  • 您可以具有不同的输入和输出格式
  • 还有更多...

测试用例:

ellipsis -> ellipsisessieses
goat -> goatgttagtgt
covfefe -> covfefeceefcece
programmer5000 -> programmer5000p000p0p0
up vote down goat -> upuppuupup voteveetveve downdnnwdndn goatgttagtgt
it is golf yo -> itittiitit isissiisis golfgfflgfgf yoyooyyoyo
crossed out 44 is still 44 -> crossedcddecdcd outottuotot 4444444444 isissiisis stillslllslsl 4444444444

最短的答案最简单的字节数bssebsbs winswssnwsws!


可以肯定的是,“省略号”中的“ e”来自“省略号”(第一个“ e”除外)
Leaky Nun

15
仍然不知道如何将省略号复数... 编辑:显然,它是椭圆。
完全人类

1
对于步骤2,我认为应该只添加一个e,而不要添加第一个字母

@苯可能更有意义,但是现在为时已晚。
程序员

2
椭圆。对于以-is结尾的单词和以-e结尾的单词,其拼写相同但发音不同的其他复数是基地

Answers:


16

JavaScript(ES6),58 57字节

注意:事实证明,在这个果冻答案中使用了与乔纳森·艾伦相同的技巧(尽管我在发布后注意到了)。

由于乔纳森·艾伦节省了1个字节

适用于字符串数组。

s=>s.map(s=>s+'01120101'.replace(/./g,n=>s.substr(-n,1)))

测试用例


哇,这太酷了!不错的工作!
程序员

我相信你可以通过更换保存一个字节2110212101120101n-2-n
乔纳森·艾伦

@JonathanAllan好抓住。谢谢!
Arnauld

11

果冻 13 12  11 字节

⁽×ʠb3’ịṭµ€K

一个完整的程序,它使用一个字符列表,并打印以空格分隔的输出。

在线尝试!

怎么样?

⁽×ʠb3’ịṭµ€K - Main link: list of lists of characters e.g. ["this","is","it"]
        µ€  - for each word in the input:            e.g. "this"
⁽×ʠ         -   base 250 literal 5416                     5416
   b3       -   converted to base 3                       [2,1,1,0,2,1,2,1]
     ’      -   decrement                                 [1,0,0,-1,1,0,1,0]
      ị     -   index into the word                       "tssitsts"
       ṭ    -   tack to the word                          ["this",["tssitsts"]]
          K - join the results with spaces                ["this",["tssitsts"]," is",["issiisis"]," it",["ittiitit"]]
            - implicit print                              thistssitsts isissiisis itittiitit

另外,单词列表到单词列表也可以是11个字节

⁽×ʠb3’ị;@µ€

⁽×ʠb3’也可以用4,⁵Bj-相同的字节数替换
[4,10]在二进制[[1,0,0],[1,0,1,0]]中用-1is 联接[1,0,0,-1,1,0,1,0])。


您是否需要将结果与空格连接?您可以输出一个列表/列表列表。
程序员

@ programmer5000是的,在此处可以添加空格
ASCII码,仅ASCII

@ programmer5000还有一个11字节替代方法,它返回我在主要答案下面给出的列表(请注意,无法通过删除删除主K列表将其降至10),因为作为单子链接,返回的列表将不是一个较深的级别,我想这["this", "is", "it"]会将松弛的I / O推得太远了-也就是说,返回值的输入将是[['t','h','i','s',"tssitsts"],['i','s',"issiisis"],['i','t',"ittiitit"]](其中“ ...”是字符列表),并将其打印为完整程序会粉碎它一起作为thistssitstsisissiisisitittiitit
乔纳森·艾伦

7

05AB1E,12个字节

εD•Lz•3вÍèJ«

在线尝试!

说明

ε              # apply on each word in input
 D             # duplicate the word
  •Lz•         # push the base-255 compressed number 5416
      3в       # convert to a list of base-3 digits (yields [2, 1, 1, 0, 2, 1, 2, 1])
        Í      # subtract 2 from each (yields [0, -1, -1, -2, 0, -1, 0, -1])
         è     # index into the word with these numbers
          J    # join to string
           «   # append to the original word

1
呵呵,好主意...
乔纳森·艾伦

@JonathanAllan:是的,我们的想法似乎完全一样。果冻较短的压缩时间赢得了这一天的胜利:)
艾米娜(Emigna)'17

6

视网膜52 49字节

3字节感谢Arnauld。

(\w)(\w+)
$1$2$1
(.)(.)(.)\b
$1$2$3$2$2$1$3$2$3$2

在线尝试!


5
第三行代码让我想起了Total Recall的一个变种。
乔纳森·艾伦

@JonathanAllan受到《希奇徒步旅行者银河指南》中提到的Eccentrica Gallumbits的启发。
尼尔

5

Python 2 2,56个字节

lambda s:[i+i[0]+i[-1]*2+i[-2]+(i[0]+i[-1])*2for i in s]

在线尝试!

我认为这是我最快的FGITW,甚至没有那么令人印象深刻。:P



4

木炭,20字节

F⪪S «ι↑E”o∨↙8”§ι±Iκ→

在线尝试!链接是详细版本的代码。只是在编码后才偶然读取@Arnauld的答案,但这基本上是它的一部分。说明:

F   «                   Loop over
  S                     Input string
 ⪪                       Split at spaces
     ι                  Print the word
        ”o∨↙8”          Compressed string 01120101
       E                Map over each character
                 Iκ     Cast character to integer
                ±       Negate
              §ι        Circularly index into word
      ↑                 Print array upwards, prints each element rightwards
                    →    Move right


@only ASCII您是否不必为-rs标志添加额外的字节?
尼尔

不确定,我猜是这样吗?-rs有没有只是禁用打印输入提示,但是
仅ASCII,

我应该将-rs模式设置为默认模式吗?
仅使用ASCII


3

JavaScript(ES6),74个 60字节

s=>s.map(s=>s+(a=s[l=s.length-1],b=s[0])+a+a+s[l-1]+b+a+b+a)

将输入作为数组,并输出一个数组。

-9字节归功于Programmer5000

测试用例:


3

Mathematica,89个字节

((f[a_]:=#~StringTake~a;k=#<>(q=f@1)<>(w=f[-1])<>w<>f@{-2}<>q<>w<>q<>w)&/@StringSplit@#)&

1
没有Ellipsisessieses内置的mathematica 吗?:(
程序员


3

Dyalog APL,51 49字节

需要 ⎕ML←3

∊{⍺,' ',⍵}/{S←1,L←≢⍵⋄⍵,⍵[∊S(L-0 1)S S]}¨' '(≠⊂⊢)⍞

-9个字节感谢@Adám的聊天!

在线尝试!


3

Paradoc(v0.2.10),13?字节(CP-1252)

µ96Qó3BÌDX=v+

在线尝试!

获取单词列表,并在堆栈上生成单词列表。

Base-3技巧的一个小变化。也许是时候使用我的基础250压缩机了。

说明:

μ             .. Map the following block over each word (the block is
              .. terminated by }, but that doesn't exist, so until EOF)
              .. (The word is on the stack now.)
 96Qó         .. 96 * 26 (Q in base 26) = 2496, a hack to prevent us from
              .. needing a space to separate this from the following number.
     3B       .. Convert 2496 to base 3 to get [1,0,1,0,2,1,1,0]
       ÌD     .. Negate and reverse to get [0,-1,-1,-2,0,-1,0,-1]
         X    .. Push the loop variable: the word being mapped over
          =v  .. Index, vectorize; map over the indices by indexing them
              .. into the word
            + .. Concatenate with the original word

(字节计数问题:现在我实际上是在TIO中进行演示的,它在堆栈上获取了一个单词列表,并在堆栈上生成了一个单词列表,但是您实际上不能对该单词列表做太多工作除非您关闭以µ开头的程序段。我应该算出该关闭括号吗?)


1
我应该说一下那个大括号吗?是的,如果您需要它。
暴民埃里克(Erik the Outgolfer)

3

Wolfram语言/数学,66字节

StringJoin[StringSplit[#,""]/.{a_,___,b_,c_}:>{#,a,c,c,b,a,c,a,c}]&

Just whipped it up real quick, might have a minor improvement here or there.


2

Perl 5, 55 49 + 1 (-a) = 56 50 bytes

used a trick from @Arrnauld's post to save a couple bytes

say map$_.'01120101 '=~s/\d/substr$_,-$&,1/egr,@F

Try it online!


2

Charcoal, 38 30 bytes

-8 bytes thanks to ASCII-only.

F⪪S «ι§ι⁰ײ§ι±¹§ι±²×²⁺§ι⁰§ι±¹ 

Try it online! Link is to verbose version.

Note the trailing space.


2

Java 8, 117 bytes

a->{int i=0,l;for(String s:a){char c=s.charAt(0),d=s.charAt(l=s.length()-1);a[i++]+=""+c+d+d+s.charAt(l-1)+c+d+c+d;}}

Takes the input as a String-array, and modified this original array instead of returning a new one to save bytes.

Can most likely be golfed some more..

Explanation:

Try it here.

a->{                          // Method with String-array as parameter and no return-type
  int i=0,                    //  Index-integer (starting at 0)
      l;                      //  Length-integer which we use multiple times
  for(String s:a){            //  Loop over the input array
    char c=s.charAt(0),       //   The first character of the word
         d=s.charAt(          //   The last character of the word
            l=s.length()-1);  //    and set `l` at the same time to `length()-1`
    a[i++]+=                  //   Append to the current value in the array:
      ""                      //    String so the characters aren't appended as integers
      +c                      //    + the first character
      +d+d                    //    + two times the last character
      +s.charAt(l-1)          //    + the single-last character
      +c+d+c+d;               //    + the first + last character two times
  }                           //  End of loop
}                             // End of method

2

C# (.NET Core), 106 bytes

n=>{for(int i=0,x;i<n.Length;){var h=n[i];x=h.Length-1;char y=h[0],j=h[x];n[i++]=h+y+j+j+h[x-1]+y+j+y+j;}}

Try it online!

Lambda function that takes input as array of strings, and modifies original array for output

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.