ใช้ Casenader Doomsday Dice's Catuckative ของ Homestuck


29

ท้าทาย

ฉันถูกโจมตีโดยลูกเรือเที่ยงคืนที่ร้ายกาจและฉันจำเป็นต้องเรียกCatenative Doomsday Dice Cascaderเพื่อปกป้องตัวเอง เนื่องจากฉันมีพื้นที่เหลือน้อยฉันจึงต้องใช้รหัสให้สั้นที่สุด

อัลกอริทึมสำหรับ Casenader Dice Catenative Doomsday มีดังต่อไปนี้:

ครั้งแรกแม่พิมพ์รีดหกด้านใน Prime Bubble จะถูกรีดและผลลัพธ์จะพิจารณาว่ามีการวนซ้ำของขั้นตอนถัดไปกี่ครั้ง

เริ่มต้นด้วยการตายหกด้าน หลายต่อหลายครั้งเมื่อการหมุนของ Prime Bubble ตายตัวให้คูณจำนวนด้านในการตายครั้งต่อไปด้วยผลลัพธ์ของการหมุนของ Die ปัจจุบัน ตัวอย่างเช่นหากในการหมุนรอบแรกของการตายหกด้านการหมุนของคุณคือ 2 การตายครั้งต่อไปของคุณจะมี 6 * 2 = 12 ด้าน

เป้าหมายของคุณคือการเขียนฟังก์ชั่นหรือโปรแกรมที่ไม่ต้องป้อนข้อมูลและส่งออกผลลัพธ์สุดท้ายของการรีดตายครั้งสุดท้าย เนื่องจากนี่คือจำนวนไบต์ต่ำสุดในแต่ละภาษาจึงชนะ!

ตัวอย่าง

ตัวอย่าง # 1 (ถ่ายโดยตรงจากลิงก์ด้านบน):

The Prime Bubble rolls a 6, meaning that the Cascader will iterate six times

#1: We always start with a 6 sided die, and it rolls a 2, so the next die has 6x2=12 sides
#2: The 12 sided die rolls an 8, meaning that the third die has 12x8=96 sides
#3: The 96 sided die rolls a 35, meaning that die 4 has 96x35=3360 sides
#4: The 3360 sided die rolls a 2922, so die 5 has 3360x2922 = 9,817,920 sides
#5: The 9.8 million sided die rolls a 5,101,894, so the final die has 50,089,987,140,480 sides
#6: The 50 trillion sided die rolls a one. Hooray. 
Since the last die rolled gave a 1, your function or program should output 1.

ตัวอย่างที่ 2

The Prime Bubble rolls a 2, meaning that the Cascader will iterate twice.

#1: We always start with a 6 sided die, and it rolls a 4, so the next die has 6x4 = 24 sides
#2: The 24 sided die rolls a 14

Since the last die rolled gave a 14, your function or program should output 14.

4
ผลผลิตสูงสุดคืออะไร หากทุกม้วนส่งผลให้ด้านสูงสุด? ฉันคิดว่ามันคือ 7958661109946400884391936 = ((((6 ^ 2) ^ 2) ^ 2) ^ 2) ^ 2) ^ 2 = 6 ^ (2 ^ 5) = 6 ^ 32
Kjetil S.

6
@KjetilS แน่นอนและความน่าจะเป็นของผลลัพธ์นั้นคือ16i=05(62i)=16×6×62×64×68×616×632=12155416739906037495048372267884096782336
Jonathan Allan

3
นี่ควรจะเป็นแบบสุ่มหรือไม่? คำถามไม่ได้พูดถึงอะไรเกี่ยวกับการสุ่มเลย?
ข้าวสาลี Wizard

10
@ SriotchilismO'Zaic ลูกเต๋ากลิ้งหมายถึงการสุ่ม
mbomb007

6
@ SriotchilismO'Zaic xkcd.com/221
Neyt

คำตอบ:



8

Perl 6 , 43 37 bytes

-6 ไบต์ขอบคุณ nwellnhof

{(6,{roll 1..[*] @_:}...*)[1+6.rand]}

ลองออนไลน์!

บล็อกโค้ดที่ไม่ระบุตัวตนที่ส่งคืนผลลัพธ์ของลูกเต๋าวันโลกาวินาศ

คำอธิบาย:

{                                   }   # Anonymous code block
 (                       )[1+6.rand]    # Take a random number from
                     ...*               # The infinite list of
  6,{roll 1..[*] @_:}                   # Cascading dice values
  6,                                    # Starting from 6
    {roll          :}                   # And choosing a random value from
          1..                           # One to
             [*] @_                     # The product of every value so far


5

J , 21 ไบต์

1+[:?(*1+?)^:(?`])@6x

ลองออนไลน์!

+6 ไบต์ด้วยปัญหาตรรกะที่พบโดย FrownyFrog

หมายเหตุ: J ไม่มีกริยา niladic อย่างไรก็ตามคำกริยานี้จะทำงานเหมือนกันไม่ว่าคุณจะโต้แย้งอะไร ในตัวอย่าง TIO ผมเรียกมันว่ามี0แต่ฉันจะได้ใช้99หรือ''เพียงเช่นกัน

อย่างไร

  • 1+ เพิ่มหนึ่งรายการไปยัง ...
  • [:?ม้วนเดียวของตาย n ด้าน (ด้านการอ่าน0การn-1) ซึ่งมีจำนวนnจะถูกกำหนดโดย ...
  • (*1+?)ใช้อาร์กิวเมนต์ปัจจุบันyและม้วน?ในการผลิตจำนวนสุ่มระหว่างและ 0 ทำให้การรวม ในที่สุดการสร้างเบ็ด J ซึ่งจะทวีคูณอีกครั้งy-11+1y*y
  • ^: ทำข้างต้นนี้หลายครั้ง ...
  • (?`]) ?ย้อนกลับอาร์กิวเมนต์เริ่มต้นซึ่งก็คือ6เพื่อกำหนดจำนวนครั้งที่จะทำซ้ำ หากเรากลิ้ง0(ตรงกับ a 1บน the Prime Bubble) อาร์กิวเมนต์จะไม่ผ่านการเปลี่ยนแปลง การ]ระบุว่า6ไม่เปลี่ยนแปลงจะเป็นค่าเริ่มต้นของ(*1+?)คำกริยาซ้ำที่กำหนดค่าตายสำหรับม้วนสุดท้าย
  • @6xแนบกริยาคงที่6เพื่อที่เราจะได้เรียกมันว่าอะไรก็ได้และxแรง J เพื่อใช้การคำนวณจำนวนเต็มแบบขยายซึ่งเราต้องการสำหรับจำนวนที่มาก

in this case 0 executes the previous verb once, 1 twice, etcทำไมถึงเป็นอย่างนั้น?
FrownyFrog

เพราะฉันทำผิดพลาด :( จะแก้ไขเร็ว ๆ นี้
Jonah

แก้ไขแล้ว ขอบคุณ
โยนาห์

4

K (oK) 32 ไบต์

วิธีการแก้:

*|{x,1+1?x:(*).x}/[*a;6,a:1+1?6]

ลองออนไลน์!

เริ่มต้นด้วย 6 และ "1 เลือก 6" ซ้ำกับ "1 เลือก 6" ครั้ง:

*|{x,1+1?x:(*).x}/[*a;6,a:1+1?6] / the solution
  {             }/[n;    c     ] / iterate over lambda n times with starting condition c
                            1?6  / 1 choose 6, between 0..5 (returns a list of 1 item)
                          1+     / add 1 (so between 1..6)
                        a:       / store as 'a'
                      6,         / prepend 6, the number of sides of the first dice
                   *a            / we are iterating between 0 and 5 times, take first (*)
           (*).x                 / multi-argument apply (.) multiply (*) to x, e.g. 6*2 => 12
         x:                      / save that as 'x'
       1?                        / 1 choose x, between 0..x-1
     1+                          / add 1 (so between 1..x)
   x,                            / prepend x
*|                               / reverse-first aka 'last'

คุณสามารถดูการวนซ้ำได้โดยสลับไปมาเพื่อทำการสแกนเช่น

(6 3        / 1 choose 6 => 3, so perform 3 iterations
 18 15      / 1 choose (6*3=18) => 15
 270 31     / 1 choose (18*15=270) => 31
 8370 5280) / 1 choose (270*31=8730) => 5280

1
(*).x-> */xและ{ }/[*a;6,a:1+1?6]->a{ }/6,a:*1+1?6
ngn

4

เยลลี่ขนาด 9 ไบต์

6X×$5СXX

ลิงก์ niladic ซึ่งให้ค่าจำนวนเต็มบวก

ลองออนไลน์!

การบันทึกไบต์ให้ชัดเจนยิ่งขึ้น 6X×$6X’¤¡X

อย่างไร?

6X×$5СXX - Link: no arguments
6         - initialise left argument to 6
    5С   - repeat five times, collecting up as we go: -> a list of 6 possible dice sizes
   $      -   last two links as a monad = f(v):           e.g [6,18,288,4032,1382976,216315425088]
 X        -     random number in [1,v]                     or [6,6,6,6,6,6]
  ×       -     multiply (by v)                            or [6,36,1296,1679616,2821109907456,7958661109946400884391936]
       X  - random choice (since the input is now a list) -> faces (on final die)
        X - random number in [1,faces]

ดี ฉันพยายามคิดหาวิธีที่จะก้าวข้ามคำตอบที่ 'ชัดเจน' ของฉัน แต่ไม่ได้คิดว่าจะสร้างลูกเต๋าทั้งหมดจากนั้นก็เลือกสุ่ม
Nick Kennedy

เฮ้ฉันพลาดไปว่าคุณโพสต์คำตอบเกือบตรงนั้น!
Jonathan Allan

3

05AB1E , 10 ไบต์

X6DLΩF*DLΩ

ตัวเลือกแบบสุ่มที่สร้างขึ้นสำหรับรายการขนาดใหญ่ค่อนข้างช้าดังนั้นอาจส่งผลให้หมดเวลาหาก Prime Bubble roll เป็นตัวอย่างที่ 6

ลองมันออนไลน์หรือลองออนไลน์ที่มีการเพิ่มการพิมพ์เพื่อดูม้วน (TIO ใช้รุ่นเก่าของ 05AB1E เนื่องจากเร็วกว่าเล็กน้อย)

คำอธิบาย:

X           # Push a 1 to the stack
 6          # Push a 6 to the stack
  D         # Push another 6 to the stack
   L        # Pop the top 6, and push a list [1,2,3,4,5,6] to the stack
    Ω       # Pop and push a random item from this list (this is out Prime Bubble roll)
     F      # Loop that many times:
      *     #  Multiply the top two values on the stack
            #  (which is why we had the initial 1 and duplicated 6 before the loop)
       D    #  Duplicate this result
        LΩ  #  Pop and push a random value from its ranged list again
            # (after the loop, output the top of the stack implicitly)

3

เยลลี่ขนาด 9 ไบต์

6×X$X’$¡X

ลองออนไลน์!

คำตอบของ Jonathan Allanอ้างว่าเป็น

การบันทึกไบต์ให้ชัดเจนยิ่งขึ้น 6X×$6X’¤¡X

. ในความเป็นจริงเราไม่จำเป็นต้องทำการเปลี่ยนแปลงครั้งใหญ่ ดังนั้นนี่เป็นวิธีการอื่นในการตอบโจนาธานอัลลันและเป็นที่พำนักสำหรับ 6-byter ที่ไม่ถูกต้องเริ่มต้นของฉัน :(



2

ถ่าน 16 ไบต์

⊞υ⁶F⊕‽⁶⊞υ⊕‽ΠυI⊟υ

ลองออนไลน์! การเชื่อมโยงคือการใช้รหัสเวอร์ชันอย่างละเอียด คำอธิบาย:

⊞υ⁶

กด 6 ไปยังรายการที่กำหนดไว้ล่วงหน้า

F⊕‽⁶

ทำซ้ำจำนวนสุ่มจาก 1 ถึง 6 ...

⊞υ⊕‽Πυ

... กดตัวเลขสุ่มระหว่าง 1 ถึงผลิตภัณฑ์ของรายการไปยังรายการ

I⊟υ

เอาท์พุทจำนวนสุดท้ายผลักไปที่รายการ

ทางเลือกวิธีการ 16 ไบต์เช่นกัน

≔⁶θF‽⁶≧×⊕‽θθI⊕‽θ

ลองออนไลน์! การเชื่อมโยงคือการใช้รหัสเวอร์ชันอย่างละเอียด คำอธิบาย:

≔⁶θ

กำหนดจำนวนด้านเป็น 6

F‽⁶

ทำซ้ำตัวเลขสุ่มระหว่าง 0 ถึง 5 ครั้ง ...

≧×⊕‽θθ

... คูณจำนวนด้านด้วยจำนวนสุ่มจาก 1 ถึงจำนวนข้าง

I⊕‽θ

พิมพ์ตัวเลขสุ่มจาก 1 ถึงจำนวนด้าน



2

R , 43 ไบต์

s=sample
for(i in 1:s(k<-6))T=s(k<-k*T,1)
T

ลองออนไลน์!

kติดตามจำนวนใบหน้าปัจจุบันบนผู้ตาย ใช้ความจริงที่ว่าจะเริ่มต้นเป็นT1

ฉันลองอีกสองสามอย่าง แต่ไม่สามารถเอาชนะวิธีง่าย ๆ ที่ตรงไปตรงมานี้ได้


1

เยลลี่ 10 ไบต์

6×X$6X’¤¡X

ลองออนไลน์!

คำอธิบาย

       ¤   | Following as a nilad:
    6X     | - A random number between 1 and 6
      ’    | - Decrease by 1 (call this N)
6          | Now, start with 6
   $    ¡  | Repeat the following N times, as a monad
 ×         | - Multiply by:
  X        |   - A random number between 1 and the current total
         X | Finally, generate a random number between 1 and the output of the above loop


1

Java 10, 214 93 86 ไบต์

v->{int r=6,n=0;for(var d=Math.random()*6;d-->0;n*=Math.random(),r*=++n)n=r;return n;}

ลองมันออนไลน์หรือลองออนไลน์ที่มีการพิมพ์บรรทัดเพิ่มเติมเพื่อดูขั้นตอน

intjava.math.BigInteger632intlongBigIntegerintBigIntegers

คำอธิบาย:

v->{                        // Method with empty unused parameter & integer return-type
  int r=6,                  //  The range in which to roll, starting at 6
      n=0;                  //  The roll itself (which must be initialized, therefor is 0)
  for(var d=Math.random()*6;//  Roll the Prime Bubble Dice
      d-->0                 //  Loop that many times:
      ;                     //    After every iteration:
       n*=Math.random(),    //     Roll a random dice in the range [0, n)
       r*=++n)              //     Increase `n` by 1 first with `++n`, so the range is [1,n]
                            //     And then multiply `r` by `n` for the new range
    n=r;                    //   Set `n` to `r`
  return n;}                //  After the loop, return `n` as result

โพสต์โซลูชันที่ไม่ทำ BigInteger เป็นโซลูชันคู่แข่งของคุณ
Stackstuck

232int

ฉันจะดูว่าฉันสามารถหาอะไรในเมตาเกี่ยวกับเรื่องนี้
Stackstuck

1
OP บอกว่าไม่ต้องกังวลกับการ จำกัด ขนาดของจำนวนเต็ม ใช้intประเภท
Stackstuck

1
@Stackstuck Done และ golfed 7 ไบต์ในกระบวนการ :)
Kevin Cruijssen

0

PHP , 59 ไบต์

$r=$q=rand(1,$s=6);while($l++<$q)$r=rand(1,$s*=$r);print$r;

ขยาย:

$r=$q=rand(1,$s=6);
while($l++<$q)$ 
    r=rand(1,$s*=$r);
print$r;

ไม่แน่ใจว่าฉันควรจะรวมแท็กเปิดหรือไม่

บนเครื่องของฉันมันขัดข้องถ้า$s*$rมันใหญ่เกินไปดังนั้น$q>=5บางครั้งมันก็ไม่พิมพ์บน... เพราะตัวเลขมีขนาดใหญ่มาก ไม่แน่ใจในการแก้ไข


0

Pyth , 14 ไบต์

uhO=*|Z6GO6hO6

ลองออนไลน์!

uhO=*|Z6GO6hO6   
         O6      Random number in range [0-6)
u                Perform the following the above number of times...
           hO6   ... with starting value G a random number in range [1-6]:
    *   G          Multiply G with...
     |Z6           The value of Z, or 6 if it's the first time through (Z is 0 at program start)
   =  Z            Assign the above back into Z
  O                Random number in range [0-Z)
 h                 Increment
                 Implicit print result of final iteration

0

C # (. NET Core) , 136 ไบต์

class A{static void Main(){var r=new System.Random();int i=r.Next(6),j=6;while(i-->0)j*=1+r.Next(j);System.Console.Write(r.Next(j)+1);}}

ลองออนไลน์!

ฉันค่อนข้างมั่นใจว่ามันใช้งานได้เนื่องจากข้อสันนิษฐานของความยาวจำนวนเต็มที่ไม่สิ้นสุดที่เราชอบที่นี่ ถ้าฉันต้องจัดการกับน้ำล้นจริง ๆ ฉันจะต้องเลิกเรียนที่แตกต่างออกไปโดยสิ้นเชิง


System.ArgumentOutOfRangeException: 'maxValue' must be greater than zero632intlongBigIntegers

@KevinCruijssen ใช่นั่นคือประเด็นทั้งหมดของความคิดเห็นของฉัน
Stackstuck


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