ชื่อสัตว์ประหลาดของ Frankenstein


15

บทนำ:

เนื่องจากมันเกือบจะเป็นฮัลโลวีนฉันแค่คิดถึงความท้าทายในธีมฮัลโลวีนแบบสุ่ม ในที่สุดฉันก็อ่านหน้าวิกิพีเดียของ Frankensteinและพบกับข้อความต่อไปนี้:

สิ่งมีชีวิต

ส่วนหนึ่งของการปฏิเสธการสร้างของแฟรงเกนสไตน์คือข้อเท็จจริงที่ว่าเขาไม่ได้ตั้งชื่อซึ่งทำให้เกิดการขาดเอกลักษณ์ แต่จะอ้างอิงโดยคำเช่น "wretch", "monster", "creature", "ปีศาจ", "ปีศาจ", "ปีศาจ" และ "มัน" เมื่อแฟรงเกนสไตน์คุยกับสิ่งมีชีวิตในบทที่ 10 เขากล่าวว่ามันเป็น "แมลงร้าย", "ปีศาจที่น่าชิงชัง", "ปีศาจ", "ปีศาจอนาถ" และ "ปีศาจที่น่ารังเกียจ"

แหล่ง

ท้าทาย:

รับสองจำนวนเต็ม (ปีและบท) ส่งออกสตริงตามกฎต่อไปนี้:

  1. ถ้าปีน้อยกว่า 1818: เอาท์พุทสตริงว่างเปล่า
  2. ถ้าปีนั้นเท่ากับ 1818 และบทนั้นต่ำกว่า 10: เอาท์พุทสตริงแบบสุ่มจากรายการ["wretch", "monster", "creature", "demon", "devil", "fiend", "it"]
  3. ถ้าปีนั้นเท่ากับ 1818 และบทคือ 10 หรือสูงกว่า: เอาท์พุทสตริงสุ่มจากรายการ["vile insect", "abhorred monster", "fiend", "wretched devil", "abhorred devil"]
  4. ดังกล่าวข้างต้นเป็นปี 1818 (และหนังสือถูกตีพิมพ์) "Frankenstein's Monster"ผลตอบแทน

กฏท้าทาย:

  • คุณสามารถเลือกว่าจะส่งออกเป็นตัวพิมพ์เล็กตัวพิมพ์ใหญ่หรือชุดค่าผสม
  • ปีจะอยู่ในช่วง 1500-2017
  • บทจะอยู่ในช่วงเสมอ1-24(ถ้าฉันไปอย่างถูกต้องหนังสือเล่มนี้มี 24 บท)
  • แทนการแสดงผลสตริงที่ว่างเปล่าสำหรับตัวเลือกที่ 1 คุณยังได้รับอนุญาตให้ส่งออกnull, undefined, false, 0หรือค่าอื่น ๆ ของทางเลือกของคุณไม่เป็นส่วนหนึ่งของอีกสามตัวเลือก (โปรดระบุสิ่งที่คุณเคยใช้ในคำตอบของคุณ)
  • ผลลัพธ์อาจไม่มีช่องว่าง / แท็บนำหน้าหรือต่อท้ายหรือบรรทัดใหม่ที่นำหน้า อาจมีบรรทัดใหม่ที่เป็นทางเลือกหนึ่งบรรทัด

กฎทั่วไป:

  • นี่คือดังนั้นคำตอบที่สั้นที่สุดในหน่วยไบต์ชนะ
    อย่าปล่อยให้ภาษารหัสกอล์ฟกีดกันคุณจากการโพสต์คำตอบด้วยภาษาที่ไม่ได้เข้ารหัส พยายามหาคำตอบสั้น ๆ ที่เป็นไปได้สำหรับภาษาโปรแกรม 'ใด ๆ '
  • กฎมาตรฐานจะใช้สำหรับคำตอบของคุณดังนั้นคุณจึงได้รับอนุญาตให้ใช้ STDIN / STDOUT ฟังก์ชัน / เมธอดพร้อมพารามิเตอร์ที่เหมาะสมโปรแกรมเต็มรูปแบบ การโทรของคุณ
  • ช่องโหว่เริ่มต้นเป็นสิ่งต้องห้าม (โดยเฉพาะ'หมายเลขสุ่มปลอม' )
  • หากเป็นไปได้โปรดเพิ่มลิงค์พร้อมทดสอบรหัสของคุณ
  • นอกจากนี้โปรดเพิ่มคำอธิบายหากจำเป็น

กรณีทดสอบ:

year,chapter possible outputs:

1700,1       ""; null; undefined; false; 0; etc.
1700,12      ""; null; undefined; false; 0; etc.
1817,10      ""; null; undefined; false; 0; etc.
1818,1       "wretch"; "monster"; "creature"; "demon"; "devil"; "fiend"; "it"
1818,9       "wretch"; "monster"; "creature"; "demon"; "devil"; "fiend"; "it"
1818,10      "vile insect"; "abhorred monster"; "fiend"; "wretched devil"; "abhorred devil"
1818,11      "vile insect"; "abhorred monster"; "fiend"; "wretched devil"; "abhorred devil"
1818,18      "vile insect"; "abhorred monster"; "fiend"; "wretched devil"; "abhorred devil"
1819,1       "Frankenstein's Monster"; "frankenstein's monster"; "FRANKENSTEIN'S MONSTER"
1819,18      "Frankenstein's Monster"; "frankenstein's monster"; "FRANKENSTEIN'S MONSTER"
2017,24      "Frankenstein's Monster"; "frankenstein's monster"; "FRANKENSTEIN'S MONSTER"

คำตอบ:


3

Perl 5, 156 153 151 bytes

-3 ไบต์ด้วย DomHastings

ทำงานด้วย -p

$_=($d=devil,$m=monster,$w=wretch,<"{creature,demon,it,fiend,vile insect,{abhorr,$w}ed {$d,$d,$m},Frankenstein's $m}">)[/818/?6*/,../+rand 7:$_/606-5]

กระจายผลลัพธ์นี้จะไม่เหมือนกันซึ่งเป็นที่ยอมรับโดยปริยาย โดยเฉพาะถ้าวันที่ 1818 และบทคือ≥10ชื่อ "ปีศาจเกลียดชัง" และ "สัตว์ประหลาดน่ารังเกียจ" มีน้ำหนักสองเท่า ทำให้ฉันใช้rand 7ทั้งสองกรณีแม้ว่ารายการจะมีขนาดต่างกัน

ผลผลิตสำหรับปีก่อนปี 1818 คือ“ สัตว์ประหลาดอนาถ” แม้จะมีความคล้ายคลึงกันบางอย่างสตริงนี้ไม่ได้เป็นส่วนหนึ่งของสามตัวเลือกอื่น ๆ ทำให้มันใช้ได้

สิ่งนี้ล้มเหลวเป็นเวลาหลายปีนอกช่วง 1212–2424 แต่โชคดีที่ปีนั้นได้รับการประกันโดยกฎที่จะอยู่ในช่วง 1500–2017

ลองออนไลน์!


ฉันไม่ทราบว่าการขยายรั้งเป็นสิ่งใน Perl เลย ... การใช้วิธีการนี้มีทางออกที่ดีสำหรับความท้าทายที่เป็นที่รู้จัก ! ลองออนไลน์!
Dom Hastings

@DomHastings Ooh ฉันไม่รู้ว่าคุณสามารถอ้างอิงช่องว่างแบบนั้นได้ นั่นคือ -3 ไบต์ที่นี่!
Grimmy

ดีใจที่ฉันสามารถช่วย! แน่นอนฉันจะต้องพยายามและจำสิ่งนี้ฉันเดาว่าเป็นเพราะความ<...>เศร้าโศก?
Dom Hastings

1
<> เป็น readline หรือ glob ขึ้นอยู่กับ ... เนื้อหา (Perl แบบคลาสสิก: ไวยากรณ์ไม่ชัดเจน แต่ตัวแยกวิเคราะห์พยายามที่จะ DWYM) เมื่อมันเป็นรูปกลมมันจะเลียนแบบเปลือกใกล้ชิดรวมทั้งการขยายตัวของปีกผีเสื้อซึ่งเป็นคุณสมบัติทั่วไปในเปลือกหอย
Grimmy

คุณสามารถเพิ่มลิงค์ TIO ในคำตอบของคุณได้ไหม :) ปัจจุบันเป็นคำตอบที่สั้นที่สุด แต่ฉันแค่ต้องการให้แน่ใจว่าทุกอย่างใช้งานได้ก่อนที่ฉันจะยอมรับว่ามันสั้นที่สุด
Kevin Cruijssen

9

Python 2 , 227 220 214 ไบต์

lambda y,c:[[choice([["wretch",m,"creature","demon",d,F,"it"],["vile insect",a+m,F,"wretched "+d,a+d]][c>9]),"Frankenstein's "+m][y>1818],0][y<1818]
from random import*
m,d,F,a='monster','devil','fiend',"abhorred "

ลองออนไลน์!


1
คุณสามารถบันทึกได้อีก 6 ไบต์โดยใส่'abhorred 'ลงในรายการที่ด้านล่างเช่นกันเนื่องจากมีการใช้สองครั้ง ( 'wretch'อาจเป็นไปได้ แต่จำนวนไบต์ยังคงเหมือนเดิม)
Kevin Cruijssen

6

Perl 5 , 172 ไบต์

171 รหัสไบต์ + 1 -pสำหรับ

@a=<><10?($}=wretch,$M=monster,creature,demon,$D=devil,fiend,it):("vile insect",($A="abhorred ").$M,fiend,"$}ed $D",$A.$D);$_=($a[rand@a],"frankenstein's $M",0)[$_<=>1818]

ลองออนไลน์!

คำอธิบาย

พริตตี้มาตรฐานเพียงสิ่ง unsual เล็กน้อยคือการใช้ 'ผู้ประกอบการยานอวกาศ' ( <=>) กับ1818การกลับมา-1, 0หรือ1ถ้าใส่$_น้อยกว่าเท่ากับหรือมากกว่า1818ที่จะกลับมาสุดท้ายเป็นครั้งแรกหรือดัชนีที่สองของแหล่งข้อมูล . นอกจากนี้ฉันชอบผู้ให้บริการปลา !


ฉันกำลังจะถามคำถามที่ไม่ได้ใช้$F=fiendแต่หลังจากการทดสอบมันก็จบลงด้วยความยาวเท่ากัน
Kamil Drakari

@KamilDrakari ใช่ต้องมีความยาวหกหรือมากกว่าเนื่องจาก$sigil :(
Dom Hastings

$}ชื่อตัวแปรคืออะไร
ติตัส

@Titus Yup! เกือบทุกอย่างใช้ได้ผลแม้ว่าหลายคนจะมีความหมายพิเศษเป็นพิเศษ ฉันใช้มันแค่นั้นเองราวกับว่าฉันเคย$Wฉันต้องการใช้${W}มันเพราะมันอยู่ถัดจากตัวอักษรอื่น
Dom Hastings

1
ฉันคิดว่า gotcha ไม่น้อย :)
ติตัส

4

C # (คอมไพเลอร์ Visual C #) , 225 209 ไบต์

y=>c=>y<1818?"":y>1818?"frankenstein's monster":"wretch,monster,creature,demon,devil,it,fiend,vile insect,abhorred monster,wretched devil,abhorred devil".Split(',')[new System.Random().Next(c>9?6:0,c>9?11:7)];

ลองออนไลน์!

-16 ขอบคุณ Kevin Cruijssen

ไม่กระชับโดยเฉพาะอย่างยิ่ง แต่ฉันคาดหวังว่า C # จะใช้พื้นที่มากขึ้นในการประกาศและใช้สตริงซ้ำ ๆ ในแบบที่ Python ตอบกลับทำได้มากกว่าเพียงแค่ทำซ้ำ ตัวทดสอบการทดสอบที่รวมอยู่มีThread.Sleep(1)การระบุภายในของกรณีทดสอบเนื่องจากการเริ่มต้นเริ่มต้นสำหรับการRandom()ใช้เวลาปัจจุบันและฟังก์ชั่นที่เกิดขึ้นจริงจะทำงานได้เร็วพอที่จะจบลงด้วยเมล็ดเดียวกันในการทดสอบครั้งต่อไปโดยไม่ล่าช้า

การเรียกใช้ func ใช้ currying syntax f(year)(chapter)(หรือชื่อใด ๆ ที่ฟังก์ชันถูกเก็บไว้แทน f)


2
ฉันเห็นว่าคุณใช้กลอุบายแบบเดียวกับที่ฉันนึกไว้เมื่อฉันโพสต์ความท้าทายโดยใส่fiendสตริงอาเรย์เดี่ยวไว้เนื่องจากอยู่ในรายการทั้งสอง คุณสามารถบันทึกบางไบต์โดยแทนที่new[]{"wretch","monster","creature","demon","devil","it","fiend","vile insect","abhorred monster","wretched devil","abhorred devil"}ด้วย"wretch,monster,creature,demon,devil,it,fiend,vile insect,abhorred monster,wretched devil,abhorred devil".Split(',')(-16 ไบต์)
Kevin Cruijssen

@KevinCruijssen Nice trick มันไม่ได้ดูเหมือนเป็นประโยชน์ทันที แต่การเปลี่ยนตัวคั่นจาก","เป็นเพียง,ทำให้นานขึ้น.Split(',')เมื่อเทียบnew[]{}กับมากกว่าสองสามรายการ
Kamil Drakari

3

Bash, 229 , 206 , 197 , 179 bytes

m=monster
a=("Frankenstein's $m" wretch $m creature demon devil it fiend vile\ insect {abhorr,wretch}ed\ {devil,$m})
echo "${a[$1>1818?0:$1<1818?13:RANDOM%($2>9?5:7)+($2>9?7:1)]}"

คำอธิบายเกี่ยวกับการขยายรั้ง / ตัวแปร

m=monster
{abhorr,wretch}ed\ {devil,$m}

ถูกขยายเป็นครั้งแรก

abhorred\ {$m,devil} wretched\ {devil,$m}
abhorred\ $m abhorred\ devil wretched\ devil wretched\ $m

ตัวแปร m จึงถูกขยาย

abhorred\ monster abhorred\ devil wretched\ devil wretched\ monster

อย่างไรก็ตามการติดตามต่อไปนี้ใช้ไม่ได้เพราะ$wจะรวมเป็นครั้งแรกedและwedไม่ได้กำหนดและจะขยายเป็นสตริงว่าง

m=monster
w=wretch
{abhorr,$w}ed\ {devil,$m}

มันสามารถทำได้เพิ่มการจัดฟันอย่างชัดเจน arround w แต่จะนานกว่า

m=monster
w=wretch
{abhorr,${w}}ed\ {devil,$m}

TIO


คุณสามารถบันทึก 4 ไบต์โดยสร้างตัวแปรสำหรับwretchและmonster( 225 ไบต์ )
Kevin Cruijssen

ไม่ง่ายนักเนื่องจากการขยายตัวของรั้งซึ่งเกิดขึ้นก่อนการขยายตัวของตัวแปร
Nahuel Fouilleul

ฉัน (เกือบ) ไม่เคยตั้งโปรแกรมใน Bash ดังนั้นคุณช่วยอธิบายความหมายของสิ่งนั้นได้ไหม? ดูเหมือนว่าจะใช้งานได้ใน TIOแต่บางทีฉันอาจจะพลาดบางสิ่งบางอย่างเนื่องจากลักษณะของภาษาการเขียนโปรแกรม
Kevin Cruijssen

1
@KevinCruijssen thnak คุณฉันได้เรียนรู้บางสิ่งบางอย่างเมื่อวงเล็บปีกกาเป็นส่วนขยายองค์ประกอบสุดท้าย
Nahuel Fouilleul

1
@ DomHastings ใช่คงที่
Nahuel Fouilleul

2

APL (Dyalog Unicode) , 189 ไบต์

m'monster'
a'abhorred ',⊢
f'fiend'
d'devil'
{⊃⍵=1818:{⊃⌽⍵<10:(?7)⊃'wretch'm'creature' 'demon'd f'it'⋄(?5)⊃'vile insect'(a m)f('wretched ',⊢d)(a d)}⍵⋄{⊃⍵>1818:'frankenstein''s ',⊢m''}⍵}

ลองออนไลน์!

หากต้องการทดสอบเพียงเพิ่มกรณีทดสอบต่อท้ายวงเล็บปีกกาสุดท้ายเช่น:

{⊃⍵=1818:{⊃⌽⍵<10:(?7)⊃'wretch'm'creature' 'demon'd f'it'⋄(?5)⊃'vile insect'(a m)f('wretched ',⊢d)(a d)}⍵⋄{⊃⍵>1818:'frankenstein''s ',⊢m''}⍵}1818 10

ต้องขอบคุณ @ngn เป็นอย่างมากที่ช่วยแก้ไขปัญหาช่องว่างนำ

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

เป็นที่น่าสังเกตว่า APL ตีความสตริงเป็นอาร์เรย์ ( เวกเตอร์ ) ของตัวอักษรดังนั้น'wretch' 'creature'จะตีความในภาษาอื่น ๆ ดังนี้[[w,r,e,t,c,h],[c,r,e,a,t,u,r,e]]

เหล่านี้เป็นฟังก์ชั่นตัวช่วย:

m'monster'      #These are pretty self explanatory, variables m, f and d are being set to 'monster', 'fiend' and 'devil respectively.
f'fiend'
d'devil'
a'abhorred ',⊢  # a is being set to 'abhorred ' concatenated with the argument to it's right.

นี่คือหน้าที่หลักซึ่งจะถูกแบ่งออกเป็น 3 ส่วนเพื่อความเข้าใจที่ดีขึ้น:

{⊃⍵=1818:{⊃⌽⍵<10:(?7)⊃'wretch'm'creature' 'demon'd f'it'⋄(?5)⊃'vile insect'(a m)f('wretched ',⊢d)(a d)}⍵⋄{⊃⍵>1818:'frankenstein''s ',⊢m''}⍵}

ส่วนที่ 1:

{⊃⍵=1818:{Part2}⍵⋄{Part3}⍵} # First conditional
        :                   # If
                           # the first element
                           # of the argument ⍵
   =1818                    # Equals the literal 1818
         {Part2}⍵           # Executes part 2 with argument ⍵
                           # Else
                  {Part3}⍵  # Executes part 3 with argument ⍵

ส่วนที่ 2:

{⊃⌽⍵<10:(?7)⊃'wretch'm'creature' 'demon'd f'it' # Second conditional
(?5)⊃'vile insect'(a m)f('wretched ',⊢d)(a d)}⍵                
       :                                         # If
                                                # the first element
                                                # of the inverse
                                                # of the argument ⍵
    <10                                          # is less than 10
                                                # pick the nth
       (?7)                                      # random element between [1,7]
            'wretch'm'creature' 'demon'd f'it'   # from this string array
                                                # Else
                                                # pick the nth
(?5)                                             # random element between [1,5]
     'vile insect'(a m)f('wretched ',⊢d)(a d)    # from this string array
                                             }⍵  # using argument ⍵

ส่วนที่ 3:

{⊃⍵>1818:'frankenstein''s ',⊢m''}⍵ # Third conditional
        :                           # If
                                   # the first element
                                   # of the argument ⍵
   >1818                            # is greater than 1818
         'frankenstein''s ',⊢m      # print the string "frankenstein's" concatenated with m (which prints monster)
                                   # else
                               ''   # print an empty string
                                 }⍵ # with argument ⍵

2

Java (OpenJDK 8) , 275 269 255 207 203 ไบต์

y->c->y<1818?0:y>1818?"Frankenstein's monster":"wretch;monster;creature;demon;devil;it;fiend;vile insect;abhorred monster;wretched devil;abhorred devil".split(";")[c+=Math.random()*(c>9?5:7)+(c>9?6:0)-c]

ลองออนไลน์!


คุณสามารถประหยัด 44 ไบต์ได้โดยส่งคืนObjectแทนที่จะพิมพ์โดยตรง:y->c->y<1818?0:y>1818?"Frankenstein's monster":"wretch,monster,creature,demon,devil,fiend,it,vile insect,abhorred monster,fiend,wretched devil,abhorred devil".split(",")[(int)(Math.random()*(c<9?7:5))+(c<9?0:7)]
Kevin Cruijssen

และคุณสามารถบันทึกได้อีก 4 ไบต์โดยการใส่fiend(ซึ่งมีอยู่ในทั้งสองรายการ) ที่อยู่ตรงกลาง: y->c->y<1818?0:y>1818?"Frankenstein's monster":"wretch;monster;creature;demon;devil;it;fiend;vile insect;abhorred monster;wretched devil;abhorred devil".split(";")[(int)(Math.random()*(c<10?7:5))+(c<10?0:6)]( 207 ไบต์ )
Kevin Cruijssen

1
203 ไบต์ ใช้IntFunctions แทนFunction<Integer>เพื่อให้มันใช้งานได้
Olivier Grégoire

2

PHP, 184 176 ไบต์

<?=strtr([0,1,2,Creature,Demon,It,Fiend,30,31,"2ed 1","Vile Insect","Frankenstein´s 0"][[rand(6*$x=$argv[2]>9,6+4*$x),11][$argv[1]<=>1818]],[Monster,Devil,Wretch,"Abhorred "]);

ทำงานด้วย-nและให้ปีและบทเป็นอาร์กิวเมนต์บรรทัดคำสั่งหรือลองออนไลน์

ดัชนีและประเมินผลลัพธ์NULLเป็นปี <1818 ซึ่งนำไปสู่ผลลัพธ์ที่ว่างเปล่า


อะไร$argv[1]<=>1818ทำอย่างไร ฉันไม่เคยเห็นแบบนั้นมาก่อน
YU NO WORK


1

Javascript (ES6), 205 ไบต์

a="abhorred ",d="devil",f="fiend",m="monster"
y=>c=>y<1818?0:y>1818?"frankenstein's "+m:(l=c<10?[f,"wretch",m,"creature","demon",d,f,"it"]:["vile insect",a+m,f,"wretched "+d,a+d])[0|Math.random()*l.length]

ส่งคืน0ถ้าปีมีค่าน้อยกว่า 1818


1

Javascript 199 ไบต์

M="monster"
A=(y,c)=>y<1818?"":y^1818?"Frankenstein's "+M:[W="wretch",M,"creature","demon",D="devil",F="fiend","it","vile insect",(H="abhorred ")+M,F,W+"ed "+F,H+D][Math.random()*(c>9?5:7)+7*(c>9)|0]

console.log(A(1700,1))
console.log(A(1700,12))
console.log(A(1817,10))
console.log(A(1818,1))
console.log(A(1818,9))
console.log(A(1818,10))
console.log(A(1818,11))
console.log(A(1819,1))
console.log(A(1819,18))
console.log(A(2017,24))


1

C, 380 BYTES

void ok(int *year, int* chapter){char*below_10[] = {"wretch", "monster", "creature", "demon", "devil", "fiend", "it"}; char*at_10[] = {"vile insect", "abhorred monster", "fiend", "wretched devil", "abhorred devil"}; year < 1818?printf("0"):(year == 1818?(chapter<10 printf("%s",below_10[rand()%8]):printf("%s",at_10[rand()%7])):printf("Frankenstein's Monster"));}

4
สวัสดียินดีต้อนรับสู่ PPCG! ในการท้าทายรหัสกอล์ฟมีเป้าหมายให้มีจำนวนไบต์น้อยที่สุด ดังนั้นชื่อเมธอด / ตัวแปรจึงดีที่สุดเป็นอักขระเดี่ยว นอกจากนี้คุณสามารถลบช่องว่างและบรรทัดใหม่ที่ไม่จำเป็นทั้งหมดและใช้"Frankenstein's Monster"โดยตรงแทนการสร้างตัวแปร นอกจากนี้ที่ไหนyearและchapterมาจากไหน ฉันไม่เห็นว่ามันเป็นพารามิเตอร์ของวิธีการ เคล็ดลับสำหรับการเล่นกอล์ฟใน <ทุกภาษา>และเคล็ดลับสำหรับการเล่นกอล์ฟใน Cอาจมีประโยชน์ เพลิดเพลินไปกับการพักผ่อนของคุณ! :)
Kevin Cruijssen

ไม่มีปัญหา. และคุณสามารถตีกอล์ฟเพิ่มอีก: void o(int y,int c){char*b[]={"wretch","monster","creature","demon","devil","fiend","it"},*a[]={"vile insect","abhorred monster","fiend","wretched devil","abhorred devil"};printf("%s",y<1818?0:y==1818?c>9?a[rand()%6]:b[rand()%7]:"Frankenstein's Monster");} 256 ไบต์ ลองที่นี่! (ฉันลบช่องว่างที่ไม่จำเป็นทั้งหมดเปลี่ยนชื่อวิธี / ตัวแปร / พารามิเตอร์เป็นตัวอักษรเดียวลบวงเล็บที่ไม่จำเป็นบางส่วนที่ ternary-if; single printf; เปลี่ยน<10เป็น>9ฯลฯ ) ไม่แน่ใจว่าทำไมrand()ไม่ทำงานใน TIO .. : S
Kevin Cruijssen


1

MBASICขนาด 288 ไบต์

1 DIM R$(12):FOR I=1 TO 12:READ R$(I):NEXT:INPUT Y,C:IF Y<1818 THEN 5
2 IF Y>1818 THEN O$="Frankenstein's Monster":GOTO 5
3 IF C>9 THEN O=7
4 O$=R$(O+INT(RND(1)*N+1))
5 PRINT O$:DATA wretch,monster,creature,demon,devil,fiend,it,vile insect,abhorred monster,fiend,wretched devil,abhorred devil

0

05AB1E , 114 110 ไบต์

0…뢼–±¹.•ʒ¦Ë"ìËM₂G¶тá≠•ì#.•1ÏiT¥Ƶʒ“T¡Äg… 5ÀΘO¼™Ãí?ιË%4₄‡‡λYιi¾н••Jtm•17в£‚…'s 'ì³R7£R’¡¬ÿÿ±¹’¸¸)sŽ7X.S>èsT@èΩ

ขาออกเมื่อปีที่อยู่ด้านล่าง01818

ลองมันออนไลน์หรือตรวจสอบกรณีทดสอบทั้งหมด

คำอธิบาย:

0                    # Push a 0
…뢼–±¹              # Push dictionary string "creature devil monster"
 .•ʒ¦Ë"ìËM₂G¶тá≠•   "# Push compressed string "demon fiend it wretch "
  ì                  # Prepend it: "demon fiend it wretch creature devil monster"
   #                 # Split by spaces: ["demon","fiend","it","wretch","creature","devil","monster"]
.•1ÏiT¥Ƶʒ“T¡Äg 5ÀΘO¼™Ãí?ιË%4₄‡‡λYιi¾н•
                     # Push compressed string "abhorred devilabhorred monsterfiendvile insectwretched devil"
 Jtm               # Push compressed integer 1249548
      17в            # Converted to Base-17 as list: [14,16,5,11,14]
         £           # Split the string into parts of that size: ["abhorred devil","abhorred monster","fiend","vile insect","wretched devil"]
                    # Pair both string-lists together
's                 '# Push string "'s "
   'ì³              '# Push dictionary string "liechtenstein"
      R7£R           # Leave the last 7 characters: "enstein"
          ’¡¬ÿÿ±¹’   # Push dictionary string "frankÿÿmonster", where the "ÿ" are automatically
                     # replaced with the strings at the top of the stack: "frankenstein's monster"
                  ¸¸ # Wrap it twice into a list: [["frankenstein's monster"]]
)                    # Wrap everything on the stack into a list
                     # (We now have: [0,[["demon","fiend","it","wretch","creature","devil","monster"],["abhorred devil","abhorred monster","fiend","vile insect","wretched devil"]],[["frankenstein's monster"]]])
 s                   # Swap to get the first (implicit) input
  Ž7X                # Push compressed integer 1818
     .S              # Compare it with the input (-1 if below; 0 if equal; 1 if above)
       >             # Increase it by 1 (0 if below; 1 if equal; 2 if above)
        è            # Use it to index into the list
         s           # Swap to get the second (implicit) input
          T@         # Check if it's larger than or equal to 10 (results in 0 for falsey; 1 for truthy)
            è        # Use it to index into the inner list
             Ω       # And finally get a random value from that list (which is output implicitly)

ดู 05AB1E เคล็ดลับของฉันนี้ (ส่วนวิธีใช้พจนานุกรม? ; วิธีการบีบอัดสตริงที่ไม่ได้เป็นส่วนหนึ่งของพจนานุกรมอย่างไร ; วิธีการบีบอัดจำนวนเต็มขนาดใหญ่?และวิธีการบีบอัดรายการจำนวนเต็ม? )เพื่อทำความเข้าใจว่าทำไม:

  • …뢼–±¹คือ"creature devil monster";
  • .•ʒ¦Ë"ìËM₂G¶тá≠• คือ "demon fiend it wretch ";
  • .•1ÏiT¥Ƶʒ“T¡Äg… 5ÀΘO¼™Ãí?ιË%4₄‡‡λYιi¾н• คือ "abhorred devilabhorred monsterfiendvile insectwretched devil";
  • •Jtm•เป็น1249548และ•Jtm•17вเป็น[14,16,5,11,14];
  • 'ì³ คือ "liechtenstein ";
  • ’¡¬ÿÿ±¹’ คือ "frankÿÿmonster";
  • Ž7X1818เป็น

-1

JavaScript, 194 B

e=Math.random,f=Math.floor;x=(a,b,c=`insect,monster,wretch,creature,demon,devil,fiend,it`.split`,`,d=[`vile `,`abhorred `])=>a<1818||a-1818?`Frankenstein's `+c[1]:(b<10||c[f(e()*2)])+c[f(e()*8)]

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