สร้างรายชื่อ Rotonyms 2


11

คำนาม 2

"Rotonym" เป็นคำที่ ROT13s เป็นคำอื่น (ในภาษาเดียวกัน)

สำหรับความท้าทายนี้เราจะใช้คำจำกัดความอื่น: "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

ใช่ฉันคิดว่าฉันรันอินพุตล่วงหน้าของฉันผ่านตัวกรองที่ไม่ซ้ำกันเมื่อฉันรันพจนานุกรมระบบ
ร่ม

ฉันสังเกตว่าคำตอบบางอย่างใช้ได้ผลกับตัวอย่าง แต่ไม่ใช่สำหรับพจนานุกรมเต็มรูปแบบ ฉันเพิ่มชุดทดสอบที่มีขนาดใหญ่กว่าซึ่งเป็นส่วนย่อยของพจนานุกรมที่มีขนาดใหญ่พอที่จะมีคำที่ล้มเหลวสำหรับคำตอบบางอย่างที่ผ่านตัวอย่างเล็กน้อย
ร่ม

@Umbrella คุณควรแสดงความคิดเห็นเกี่ยวกับคำตอบที่ไม่ถูกต้องเพื่อแจ้งเตือนผู้ใช้เพื่อให้พวกเขาสามารถแก้ไข / ลบคำตอบของพวกเขา
H.PWiz

abdominovaginalคุณมีคำแปลก ๆ ที่นั่น
Magic Octopus Urn

คำตอบ:


5

เยลลี่ 8 ไบต์

ṙ1$ƬfḊɗƇ

ลองออนไลน์!

รุ่นสำรอง 7 ไบต์

ṙƬ1fḊʋƇ

ไดยาดิคƬเคยทำสิ่งแปลก ๆ ดังนั้นมันจึงไม่ได้ผลเมื่อมีการโพสต์ความท้าทาย

ลองออนไลน์!

มันทำงานอย่างไร

ṙƬ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 ขอบคุณเขา นอกจากนี้ -1 โดยการกลับรายการที่ล้อมรอบเหมือน H.PWiz

ฟังก์ชันนำหน้าเงียบโดยไม่ระบุชื่อ

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

ลองออนไลน์!

(...  ใช้ฟังก์ชัน tacit ต่อไปนี้กับแต่ละคำ:

,⍨ เชื่อมคำเข้ากับตัวเอง

≢,/ สตริงย่อยความยาวคำทั้งหมด (เช่นการหมุนทั้งหมด)

 องค์ประกอบที่ไม่ซ้ำกันของการหมุนเหล่านั้น (เพื่อป้องกันคำที่ต้องการtataให้ปรากฏสองครั้ง)

1,.↓ การต่อกันของ drop-firsts (คำเดิม) ของแต่ละรายการ

⊂∩¨ จุดตัดของเนื้อหาของรายการนั้นและรายการคำศัพท์ต้นฉบับทั้งหมด


วิธีการแก้ปัญหาเก่า

-2 ขอบคุณ ngn

คำนำหน้าไม่ระบุชื่อแลมบ์ดา

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

ลองออนไลน์!

{... } ฟังก์ชั่นรายการคำอยู่ที่ไหน:

(...  ใช้ฟังก์ชัน tacit ต่อไปนี้กับแต่ละคำ:

  ,⍨ เชื่อมคำเข้ากับตัวเอง

  ≢,/ สตริงย่อยความยาวคำทั้งหมด (เช่นการหมุนทั้งหมด)

   องค์ประกอบที่ไม่ซ้ำกันของการหมุนเหล่านั้น (เพื่อป้องกันคำที่ต้องการtataให้ปรากฏสองครั้ง)

 ผสมรายการของรายการลงในเมทริกซ์เดียว (แผ่นอิเล็กโทรดกับสตริงพื้นที่ทั้งหมด)

⍵∊⍨ ระบุองค์ประกอบของเมทริกซ์ที่เป็นสมาชิกของรายการต้นฉบับ

+/ หาผลรวมของแถว (นับจำนวนที่เกิดขึ้นของแต่ละคำต้นฉบับ)

2≤ บ่งบอกว่ามีการทำซ้ำ (เช่นเกิดขึ้นนอกเหนือจากเมื่อหมุนกลับไปที่เดิม)

⍵/⍨ ใช้สิ่งนั้นเพื่อกรองรายการดั้งเดิม


{∪⌽∘⍵¨⍳≢⍵}-> (∪≢,/,⍨); การใช้งานของคุณเป็นสิ่งที่ชาญฉลาด
ngn

@ngn ขอบคุณ ฉันเรียนรู้เคล็ดลับจากมอร์เทน
Adám

รถไฟเหล่านั้นทำให้เจ็บสมองของฉัน ... มันง่ายเป็น 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เป็นจุดตัดของxและy


ฉลาด. ฉันสามารถใช้ส่วนทางแยกเพื่อบันทึกไบต์อื่นได้
อดัม

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 สร้าง list comprehensions เพราะมันใช้ฟังก์ชั่นในการกำหนดตัวแปรเพื่อให้การมอบหมายสามารถไปในการแสดงออก แต่จากนั้นเงื่อนไขก็สิ้นสุดลงโดยไม่มีค่าของตัวแปรจนกว่าจะได้รับการประเมินและ บล็อกหลักได้รับการประเมิน ดูเหมือนว่าจะสามารถแก้ไขได้อย่างง่ายดาย แต่ฉันไม่ได้สังเกตเรื่องนี้มาก่อนดังนั้นคำตอบนี้ยาวอย่างน่าสังเวช

จริงๆแล้วแม้ว่าฉันจะคิดว่ามันคงนานมาก


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

Ungolfed:

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เพื่อดูว่ามีอะไรที่ใช้ที่นี่
AdmBorkBork

ขอบคุณสำหรับคำใบ้ ฉันอ่านคำตอบทั้งสำหรับ JS และ ES6 แต่ดูเหมือนว่าฉันได้ใช้เคล็ดลับที่เกี่ยวข้องทั้งหมดนี้แล้ว อย่างน้อยคนที่เห็นได้ชัดสำหรับฉัน
bubens

1

เรติน่า 0.8.2 , 71 62 ไบต์

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

ลองออนไลน์! คำอธิบาย:

%+)

ทำซ้ำสำหรับแต่ละคำ

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

!ย่อหน้าหมุนต่อไปของคำที่มีต่อท้าย

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

แต่ถ้านั่นเป็นคำเดิมให้ลบอีกครั้ง

O`

เรียงคำ

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

ค้นหารายการที่ซ้ำกัน


1

Python 2 , 66 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: ตามเงื่อนไขขอบเหล่านั้น! วิธีแก้ปัญหาอย่างรวดเร็ว ...
Chas Brown


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 เพราะมันสั้นในการเขียน คำถามคือรหัสกอล์ฟไม่ใช่รหัสที่เร็วที่สุด
Nit

ฉันเห็น. ฉันไม่คุ้นเคยกับ Japt ดังนั้นฉันจึงไม่ชัดเจนว่าการวนซ้ำน้อยลงจะใช้ตัวละครมากขึ้น
ร่ม

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

Ungolfed

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

ลองออนไลน์!



โดยการใช้ไซต์ของเรา หมายความว่าคุณได้อ่านและทำความเข้าใจนโยบายคุกกี้และนโยบายความเป็นส่วนตัวของเราแล้ว
Licensed under cc by-sa 3.0 with attribution required.