产生一个轮换词列表2


11

轮名2

“ Rotonym”是ROT13转换为另一个单词(使用相同语言)的单词。

对于这个挑战,我们将使用一个替代定义:“ Rotonym”是一个单词,可以循环移位/旋转为另一个单词(使用相同的语言)。

例如:

'stable' < 'tables' < 'ablest'
'abort' > 'tabor'
'tada' >> 'data'

挑战

编写一个程序或函数,该程序或函数接受词典/单词列表,并打印或返回完整的轮换单词列表。

  1. 顺序无关紧要。
  2. 比较应该不区分大小写,因此可以假定输入将作为仅小写的字典传递。
  3. 结果应表示为单个单词(而不是对),并且不包含重复项,因此您可以假设输入内容不包含重复项。
  4. 这是

给定

ablest
abort
green
irk
stable
tables
tabor
tata
terra
vex
you

返回

ablest
abort
stable
tables
tabor

真实的测试

给定

a aa aal aalii aam aani aardvark aardwolf aaron aaronic aaronical aaronite aaronitic aaru ab aba ababdeh ababua abac abaca abacate abacay abacinate abacination abaciscus abacist aback abactinal abactinally abaction abactor abaculus abacus abadite abaff abaft abaisance abaiser abaissed abalienate abalienation abalone abama abampere abandon abandonable abandoned abandonedly abandonee abandoner abandonment abanic abantes abaptiston abarambo abaris abarthrosis abarticular abarticulation abas abase abased abasedly abasedness abasement abaser abasgi abash abashed abashedly abashedness abashless abashlessly abashment abasia abasic abask abassin abastardize abatable abate abatement abater abatis abatised abaton abator abattoir abatua abature abave abaxial abaxile abaze abb abba abbacomes abbacy abbadide abbas abbasi abbassi abbasside abbatial abbatical abbess abbey abbeystede abbie abbot abbotcy abbotnullius abbotship abbreviate abbreviately abbreviation abbreviator abbreviatory abbreviature abby abcoulomb abdal abdat abderian abderite abdest abdicable abdicant abdicate abdication abdicative abdicator abdiel abditive abditory abdomen abdominal abdominales abdominalian abdominally abdominoanterior abdominocardiac abdominocentesis abdominocystic abdominogenital abdominohysterectomy abdominohysterotomy abdominoposterior abdominoscope abdominoscopy abdominothoracic abdominous abdominovaginal abdominovesical abduce abducens abducent abduct abduction abductor abe abeam abear abearance abecedarian abecedarium abecedary abed abeigh abel abele abelia abelian abelicea abelite abelmoschus abelmosk abelonian abeltree abencerrages abenteric abepithymia aberdeen aberdevine aberdonian aberia aberrance aberrancy aberrant aberrate aberration aberrational aberrator aberrometer aberroscope aberuncator abet abetment ablest abort abut ach ache acher achete achill achor acor acre acyl ad adad adat add addlings adet ala ama baa bafta balonea batea beta caba cha chilla cora crea da dad dada data each lacy orach rache saddling stable tables tabor tabu tade teache zoquean zoraptera zorgite zoril zorilla zorillinae zorillo zoroastrian zoroastrianism zoroastrism zorotypus zorrillo zorro zosma zoster zostera zosteraceae zosteriform zosteropinae zosterops zouave zounds zowie zoysia zubeneschamali zuccarino zucchetto zucchini zudda zugtierlast zugtierlaster zuisin zuleika zulhijjah zulinde zulkadah zulu zuludom zuluize zumatic zumbooruk zuni zunian zunyite zupanate zutugil zuurveldt zuza zwanziger zwieback zwinglian zwinglianism zwinglianist zwitter zwitterion zwitterionic zyga zygadenine zygadenus zygaena zygaenid zygaenidae zygal zygantra zygantrum zygapophyseal zygapophysis zygion zygite zygnema zygnemaceae zygnemales zygnemataceae zygnemataceous zygnematales zygobranch zygobranchia zygobranchiata zygobranchiate zygocactus zygodactyl zygodactylae zygodactyli zygodactylic zygodactylism zygodactylous zygodont zygolabialis zygoma zygomata zygomatic zygomaticoauricular zygomaticoauricularis zygomaticofacial zygomaticofrontal zygomaticomaxillary zygomaticoorbital zygomaticosphenoid zygomaticotemporal zygomaticum zygomaticus zygomaxillare zygomaxillary zygomorphic zygomorphism zygomorphous zygomycete zygomycetes zygomycetous zygon zygoneure zygophore zygophoric zygophyceae zygophyceous zygophyllaceae zygophyllaceous zygophyllum zygophyte zygopleural zygoptera zygopteraceae zygopteran zygopterid zygopterides zygopteris zygopteron zygopterous zygosaccharomyces zygose zygosis zygosperm zygosphenal zygosphene zygosphere zygosporange zygosporangium zygospore zygosporic zygosporophore zygostyle zygotactic zygotaxis zygote zygotene zygotic zygotoblast zygotoid zygotomere zygous zygozoospore zymase zyme zymic zymin zymite zymogen zymogene zymogenesis zymogenic zymogenous zymoid zymologic zymological zymologist zymology zymolyis zymolysis zymolytic zymome zymometer zymomin zymophore zymophoric zymophosphate zymophyte zymoplastic zymoscope zymosimeter zymosis zymosterol zymosthenic zymotechnic zymotechnical zymotechnics zymotechny zymotic zymotically zymotize zymotoxic zymurgy zyrenian zyrian zyryan zythem zythia zythum zyzomys zyzzogeton

返回

aal aam aba abac abaft abalone abate abet ablest abort abut ach ache acher achete achill achor acor acre acyl ad adad adat add addlings adet ala ama baa bafta balonea batea beta caba cha chilla cora crea da dad dada data each lacy orach rache saddling stable tables tabor tabu tade teache

我们可以假设输入单词是唯一的吗?
ngn

是的,我想我在运行系统字典时会通过唯一的过滤器预先输入内容。

我注意到一些答案适用于该示例,但不适用于完整的词典。我添加了一个更大的测试集,它是字典的一个子集,足够大,可以包含未能通过简单示例的某些答案的单词。

@雨伞,您应该评论任何无效的答案以提醒用户,以便他们可以修复/删除他们的答案
H.PWiz

abdominovaginal,您那里有些奇怪的话。
魔术章鱼缸

Answers:


5

果冻,8字节

ṙ1$ƬfḊɗƇ

在线尝试!

备用版本,7字节

ṙƬ1fḊʋƇ

Dyadic Ƭ曾经做过一些奇怪的事情,所以在发布挑战时这是行不通的。

在线尝试!

这个怎么运作

ṙƬ1fḊʋƇ  Main link. Argument: A (array of strings)

     ʋ   Vier; combine the 4 preceding links into a dyadic chain.
      Ƈ  Comb; for each string s in A, call the chain with left argument s and
         right argument A. Keep s iff the chain returned a truthy value.
 Ƭ           'Til; keep calling the link to the left, until the results are no
             longer unique. Return the array of unique results.
ṙ 1          Rotate the previous result (initially s) one unit to the left.
   f         Filter; keep only rotations that belong to A.
             s is a rotonym iff there are at least two rotations of s in A.
    Ḋ        Deque; remove the first string (s) of the result.
             The resulting array is non-empty / truthy iff s is a rotonym.

哦,新的快速人物?嗯,现在必须学习何时使用它们……(现在是1字节,这是相同的,所以我可以在使用2字节时再使用它们)
HyperNeutrino

等同于ṙ1$ÐĿfḊɗÐf
丹尼斯

4

APL(Dyalog),20字节

需要 ⎕io←0

⊂∩¨(,/(1↓∘∪⍳∘≢⌽¨⊂)¨)

在线尝试!

(1↓∘∪⍳∘≢⌽¨⊂)¨ 获取字典中每个字符串的唯一旋转(不包括字符串本身)

取向量的长度

⍳∘≢ 创建从0到长度的范围

将向量旋转几次,例如2⌽'abort'->'ortab'

⍳∘≢⌽¨⊂ 然后将给出向量的所有旋转

删除重复项

1↓ 删除第一个元素(原始字符串)

,/ 将所有旋转集中到一个列表中

⊂∩¨ 将字典与旋转的交点


您的结果是封闭的,但是我想应该没问题,@Adám可以进一步窃取您的⊂∩¨把戏(反之亦然)-1
ngn

4

APL(Dyalog Unicode)25 23 22 17 16 字节SBCS

ngn的ngn / k解决方案中借用想法。然后-6感谢他。通过返回一个封闭的列表(如H.PWiz)也为-1 。

匿名默认前缀功能。

⊂∩¨1,.↓(∪≢,/,⍨)¨

在线尝试!

( 对每个单词应用以下默认功能:

,⍨ 将单词连接到自身

≢,/ 所有字长的子字符串(即所有旋转)

 这些旋转的独特元素(以防止tata出现两次这样的单词)

1,.↓ 每个列表的首位跌落(原始单词)的连接

⊂∩¨ 该内容与整个原始单词列表的交集


旧解决方案

-2感谢ngn。

匿名前缀lambda。

{⍵/⍨2≤+/⍵∊⍨↑(∪≢,/,⍨)¨⍵}

在线尝试!

{} 函数单词列表在哪里:

( 对每个单词应用以下默认功能:

  ,⍨ 将单词连接到自身

  ≢,/ 所有字长的子字符串(即所有旋转)

   这些旋转的独特元素(以防止tata出现两次这样的单词)

 将列表的列表混合到单个矩阵中(带有全空格字符串的pad)

⍵∊⍨ 指示矩阵的哪些元素是原始列表的成员

+/ 对行求和(计算每个原始单词的出现次数)

2≤ 指出哪些有重复(即发生在旋转回原件之外的情况)

⍵/⍨ 用它来过滤原始列表


{∪⌽∘⍵¨⍳≢⍵}-> (∪≢,/,⍨); 您的使用是聪明
NGN

@ngn谢谢。我从莫滕那里学到了窍门。
阿达姆(Adám)'18年

这些火车让我的大脑受伤...作为dfn更简单:{⍵∩⊃,/1↓¨(∪≢,/,⍨)¨⍵}
ngn

@ngn这就是我虽然变成火车而没有旋转技巧的东西
H.PWiz

1
抱歉,最后改变主意:⊢∩∘⊃1,.↓(∪≢,/,⍨)¨
ngn

4

Brachylog,26个字节

g;?z{tWl⟧₆∋I;W↺₍R;W≠&h∋R}ˢ

在线尝试!

g;?z                          % Zip the whole input with each word in it respectively
    {                   }ˢ    % Apply this predicate to each pair in the zip
                              %   and select the successful values
     tW                       % Let the current word be W
       l⟧₆∋I                  % There exists a number I from 1 to length(W)-1
            ;W↺₍R             % And R is the result of circularly shifting the 
                              %   current word I times 
                 ;W≠          % And R is not the current word itself (needed for words like "tata")
                    &h∋R      % And R is one of the input dictionary words
                              % (R is implicitly the output of the predicate, and 
                              %  successful R values are collected and output by the ˢ)


3

K(ngn / k),23个字节

{x^x^,/1_'(,/|0 1_)\'x}

在线尝试!

{ } 是带有参数的函数 x

0 1_在索引0和1处剪切字符串,例如"abcd"->(,"a";"bcd")

| 反转两个切片: ("bcd";,"a")

,/ 加入他们: "bcda"

(,/|0 1_)\ 返回字符串的所有旋转

(,/|0 1_)\'x 是每个字符串的旋转 x

1_' 放弃每个旋转的第一个“旋转”,即每个琐碎的身份旋转

,/ 加入

x^y是没有列表x元素的列表y

x^x^y是的交点xy


聪明。我能够使用交集部分来保存另一个字节。
亚当

2

05AB1E,14个字节

εDvDÀ})ÙåO<Ā}Ï

在线尝试!

说明

ε           }    # apply to each word in the input
 Dv  }           # for each letter in the word
   DÀ            # copy the previous word and rotate it left
      )Ù         # wrap the rotations in a list and remove duplicates
        å        # check each rotation for presence in the input
         O       # sum presences
          <Ā     # decrement the sum and truthify it (check if 1 or greater)
             Ï   # filter, keep words in input that are true in the resulting list

2

PynTree,44字节

§y:f#x0€[x/|Ḟz&⁻xzėzḞw+#x`wLx#x`0wRLxy]y#\x1

在线尝试!

事实证明这揭示了PynTree构造列表理解方式的主要缺陷,因为PynTree使用函数来分配变量,以便赋值可以进入表达式中,但是直到变量被求值后,条件才最终没有变量的值,并且主块已被评估。这似乎很容易解决,但是我没有早些注意到,所以这个答案很长。

实际上,即使我修复了问题,我仍然认为它可能还很长。


2

Perl 6、65字节

{@^a.grep:{@aany(($/=[.comb]).rotate,*.rotate...^*eq$/).join}}

尝试一下

展开:

{  # bare block lambda with placeholder parameter @a

  @^a     # declare and use placeholder parameter
  .grep:  # find the values that match
  {

    @a
                # Set contains operator

    any(         # create a junction of the following

      # generate a sequence
      (
        $/ =     # store into $/ (no declaration needed for this variable)
        [        # turn into an array instead of a one-time sequence
          .comb  # the input split into characters
        ]
      ).rotate,  # start the sequence on the first rotation

      *.rotate   # use this to generate the rest of the values in the sequence

      ...^       # keep generating values until: (and throw out last value)

      * eq $/    # one of them matches the cached array of the input

    ).join       # for each array in the junction join the strings (no spaces)
  }
}

2

JavaScript(Node.js),105 99字节

f=l=>l.filter(w=>[...Array(k=w.length)].map((x,i)=>(w+w).substr(i,k)).some(r=>l.includes(r)&&r!=w))

取消高尔夫:

f = list =>
  list.filter( word =>
    // create a list of all rotonyms for the current word
    [ ...Array( len = word.length ) ]
      .map( (x,i) => 
         ( word+word ).substr(i, len)
      )
    // check if any of the rotonyms is in the initial dictionary/wordlist
     .some( rotonym =>
        list.includes( rotonym )
    // and is not the word itself
        && rotonym != word
     )

在线尝试!


欢迎来到PPCG!我并不精通JavaScript,但是一定要检查一下JavaScript Tips线程,看看这里是否有适用的内容。
AdmBorkBork

感谢您的提示。我已经阅读了JS和ES6的答案,但似乎已经应用了所有相关技巧。至少对我来说很明显。
bubens

1

视网膜0.8.271 62个字节

^(\w)(\w*)
$2$1!¶$&
%+)s`^(.+)(!.*¶\1)$
$2
O`
!`\b(.+)(?=¶\1!)

在线尝试!说明:

%+)

重复每个单词。

^(\w)(\w*)
$2$1!¶$&

在单词的下一个旋转后面加上尾随的!

s`^(.+)(!.*¶\1)$
$2

但是,如果这是原始词,请再次将其删除。

O`

排序单词。

!`\b(.+)(?=¶\1!)

查找重复项。


1

Python 266 55 70字节

lambda d:{w for w in d for v in d if v not in w not in v in w*2in v*3}

在线尝试!

丹尼斯需要11个字节的字节数才能使用链式x in y in z方法处理。

用一套话d; 返回一组Rotonyms。


支票太弱了;{ab,abab}会通过。
xnor

@xnor:那些边缘条件!快速修复...
布朗


0

Japt,17个字节

极其缓慢的,但工程。TIO超时,但是我确认可以通过手动减少语言源中的迭代次数来工作。

f@_XéZ ÀX©UøXéZ}a
f@                // Filter the input array by
  _            }a // generating up to 1e8 rotations of each string
   XéZ ÀX         // and checking if the rotation is different than the original,
         ©UøXéZ   // yet still exists in the input array.

在线尝试!


为什么要进行这么多迭代?我最初对字符串长度进行了迭代,但是通过测试,发现每个单词向左旋转十次就足以在MacOS dict文件中找到所有情况。
Umbrella

@Umbrella因为写起来很短。问题是代码高尔夫球,而不是最快的代码。
Nit

我知道了。我不熟悉Japt,因此对我而言,迭代次数越少就越需要更多字符。
Umbrella

0

Javascript,129个字符

f=a=>{n={};r=w=>w.slice(1,w.length)+w[0];a.map(w=>{m=r(w);while(m!=w){if(-~a.indexOf(m))n[m]=1;m=r(m);}});return Object.keys(n);}

不打高尔夫球

f=a=>{
    n={};
    r=w=>w.slice(1,w.length)+w[0];
    a.map(w=>{
        m=r(w);
        while(m!=w){
            if(-~a.indexOf(m))n[m]=1;
            m=r(m);
        }
    });
    return Object.keys(n);
}

在线尝试!



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.