เล่น Pickomino


10

ในเกมPickominoมีไพ่หลายใบวางอยู่กลางโต๊ะแต่ละแผ่นมีจำนวนเต็มบวกที่แตกต่างกัน ในแต่ละเทิร์นผู้เล่นจะทอยลูกเต๋าในวิธีที่แน่นอนและได้รับคะแนนซึ่งเป็นจำนวนเต็มที่ไม่ใช่ค่าลบ

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

ความท้าทาย

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

กฏท้าทาย

  • คุณสามารถสมมติได้ว่ารายการที่มีไทล์เรียงตามลำดับและไม่มีจำนวนเต็มสองเท่า
  • คุณสามารถนำรายการเข้าทั้งสองตามลำดับที่คุณต้องการ
  • เอาท์พุทต้องรักษาลำดับของไทล์บนสแต็ก แต่คุณสามารถตัดสินใจได้ว่ารายการเรียงลำดับจากบนลงล่างหรือจากล่างขึ้นบน

กฎทั่วไป

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

ตัวอย่าง

(นำมาจาก testcase ที่ 6)

Tiles: [21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36]
Scores: [22, 22, 22, 23, 21, 24, 0, 22]

คะแนนแรกคือ 22 ดังนั้นให้จับไทล์สูงสุดที่อยู่ตรงกลาง <= 22 ซึ่งก็คือ 22

Middle: [21, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36]
Stack: [22]
Remaining scores: [22, 22, 23, 21, 24, 0, 22] 

คะแนนถัดไปคือ 22 ดังนั้นหยิบไทล์สูงสุดที่อยู่ตรงกลาง <= 22 เนื่องจากได้รับ 22 แล้วผู้เล่นจะต้องมี 21

Middle: [23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36]
Stack: [22, 21]
Remaining scores: [22, 23, 21, 24, 0, 22]

คะแนนถัดไปคือ 22 แต่ทุกหมายเลข <= 22 ได้รับแล้ว ดังนั้นผู้เล่นจะสูญเสียไทล์สูงสุดบนสแต็ค (21) ซึ่งจะถูกส่งกลับไปที่กลาง

Middle: [21, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36]
Stack: [22]
Remaining scores: [23, 21, 24, 0, 22]

คะแนนถัดไปคือ 23, 21 และ 24 ดังนั้นผู้เล่นจึงนำไพ่เหล่านี้มาจากตรงกลาง

Middle: [25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36]
Stack: [22, 23, 21, 24]
Remaining scores: [0, 22]

ผู้เล่น busts และศูนย์คะแนน ดังนั้นไทล์ที่มีหมายเลข 24 (สูงสุดบนสแต็ก) จะถูกส่งกลับไปที่ตรงกลาง

Middle: [24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36]
Stack: [22, 23, 21]
Remaining scores: [22]

คะแนนสุดท้ายคือ 22 แต่ไทล์ทั้งหมด <= 22 ถูกนำไปใช้แล้วดังนั้นผู้เล่นจะแพ้ไทล์สูงสุดบนสแต็ก (21)

Middle: [21, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36]
Final Stack and Output: [22, 23]

กรณีทดสอบ

(ด้วยไทล์สูงสุดบนสุดในรายการเอาท์พุท)

Tiles: [21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36]
Scores: [26, 30, 21]
Output: [26, 30, 21]

Tiles: [21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36]
Scores: [35, 35, 36, 36]
Output: [35, 34, 36, 33]

Tiles: [21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36]
Scores: [22, 17, 23, 19, 23]
Output: [23]

Tiles: [21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36]
Scores: []
Output: []

Tiles: [21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36]
Scores: [22, 17, 23, 19, 23, 0]
Output: []

Tiles: [21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36]
Scores: [22, 22, 22, 23, 21, 24, 0, 22]
Output: [22, 23]

Tiles: [1, 5, 9, 13, 17, 21, 26]
Scores: [6, 10, 23, 23, 23, 1, 0, 15]
Output: [5, 9, 21, 17, 13, 1]

Tiles: []
Scores: [4, 6, 1, 6]
Output: []

Sandbox


เราสามารถสมมติว่าไม่มีไทล์ที่มีค่าเป็นศูนย์อยู่ตรงกลางหรือไม่?
ศูนย์รวมแห่งอวิชชา

@EmbodimentofIgnorance มันบอกว่า "จำนวนเต็มบวก" ดังนั้นใช่
Ørjan Johansen

เนื่องจากกระเบื้องมีความเป็นเอกลักษณ์มันจะเป็นที่ยอมรับหรือไม่ที่จะพาพวกเขาไปเป็นบิตมาสก์?
Arnauld

@TRITICIMAGVS ใช่ถ้ากองกลางว่างเปล่าผู้เล่นไม่สามารถดึงไทล์จากกลางได้ดังนั้นพวกเขาจะสูญเสีย
Black Owl Kai

@Arnauld นั่นเป็นที่ยอมรับ
Black Owl Kai

คำตอบ:


3

Haskell , 119 111 104 103 ไบต์

บันทึก 1 ไบต์ขอบคุณØrjan Johansen

(#)=span.(<)
(a%(b:c))d|(g,e:h)<-b#d=(e:a)%c$g++h|g:h<-a,(i,j)<-g#d=h%c$i++g:j|1>0=a%c$d
(a%b)c=a
([]%)

ลองออนไลน์!

สมมติว่าเรียงลำดับจากมากไปน้อย

ไม่ค่อยแฟนซีเกิดขึ้นที่นี่ อาร์กิวเมนต์แรกคือกองผู้เล่นที่สองคะแนนของพวกเขาและที่สามคือกองอยู่ตรงกลาง


1
สิ่งนี้ไม่ถูกต้องเพราะใกล้sortจะถึงแล้ว กรณีทดสอบ TIO ไม่เคยกระทบสาขาดังกล่าว ฉันขอแนะนำให้ทดสอบทุกกรณีเมื่อทำซ้ำเช่นนี้
Ørjan Johansen

@ ØrjanJohansenขอบคุณ! แก้ไขแล้ว อย่างน้อยฉันก็ไม่ต้องนำเข้าอีกต่อไป!
Ad Hoc Garf Hunter

(#)=span.(<)บันทึกไบต์ด้วย
Ørjan Johansen

@ ØrjanJohansenทำการเปลี่ยนแปลง สิ่งที่ตลกคือฉันลองก่อนหน้านี้และคิดว่ามันเพิ่มไบต์
Ad Hoc Garf Hunter

3

Japt 24 ไบต์

OOF! นั่นไม่ได้ผลเช่นเดียวกับที่ฉันคิดว่ามันจะ!

รับอินพุตในลำดับย้อนกลับ

®=Va§Z)Ì?NpVjZ:VpNo)nÃN¤

ลองใช้หรือเรียกใช้กรณีทดสอบทั้งหมดใน TIO

®=Va§Z)Ì?NpVjZ:VpNo)nÃN¤     :Implicit input of N=[U=scores, V=tiles]
®                            :Map each Z in U
 =                           :  Reassign to Z
  Va                         :    0-based index of last element in V (-1 if not found)
    §Z                       :      Less than or equal to Z
      )                      :  End reassignment
       Ì                     :  Sign of difference with -1 (1 if found, 0 if not)
        ?                    :  If truthy (not zero)
         Np                  :    Push to N
           VjZ               :      Remove and return the element at index Z in V
              :              :  Else
               Vp            :    Push to V
                 No          :      Pop the last element of N
                   )         :    End Push
                    n        :    Sort V
                     Ã       :End map
                      N¤     :Slice the first 2 elements (the original inputs) off N


2

C # (Visual C # Interactive Compiler) , 159 158 154 ไบต์

เรียกได้ว่าเป็น f(tiles)(scores)

n=>m=>{var s=new Stack<int>();m.Add(0);n.ForEach(k=>{var a=m.Except(s).Where(x=>x<=k).Max();if(a<1)m.Add(s.Count<1?0:s.Pop());else s.Push(a);});return s;}

หากSystem.Voidเป็นประเภทการคืนเท่านั้นและไม่ได้เป็นเพียงตัวยึดสำหรับการสะท้อน ฉันจะสามารถแทนที่if(a<1)m.Add(s.Count<1?0:s.Pop());else s.Push(a);ด้วยvar t=a>1?m.Add(s.Count<1?0:s.Pop()):s.Push(a);การบันทึกสองไบต์

ลองออนไลน์!

//Function taking in a list and returning
//another function that takes in another list and returns a stack
n=>m=>{
//Initialize the stack
var s=new Stack<int>();
//Add a zero to the tiles, to ensure no exceptions appear due to accessing
//non-existent elements in an empty collection later
//when we try to filter it later and getting the biggest element
m.Add(0);
//Iterate through our scores
n.ForEach(k=>{
//Create a variable called a, which we will use later
var a=
//Get all the elements in the middle that haven't appeared in our stack
m.Except(s).
//And throw away all elements that are bigger than our current score
Where(x=>x<=k).
//And get the biggest element there, and that is now the value of a
//Without the m.Add(0), we would get an exception here
Max();
//Self-explanatory, if a is less than 1 aka if a equals 0
//Checks if all elements in the middle are bigger than our score 
//Except for our self added 0, of course
if(a<1)
//Add 0 to the middle if the stack is empty
//Remember, zeros don't affect the list
m.Add(s.Count<1?0:
//Else pop the stack and add that to the middle
s.Pop());
//If a isn't 0, add a to the stack
else s.Push(a);});
//Afterwards, return the stack
return s;}


2

JavaScript (Node.js) , 80 ไบต์

ตรรกะเช่นเดียวกับเวอร์ชัน ES6 แต่รับไทล์เป็น BigInt bitmask และให้คะแนนเป็นอาร์เรย์ของ BigInts

m=>s=>s.map(g=x=>!x||m>>x&1n?m^=1n<<(x?r.push(x)&&x:r.pop()||~x):g(--x),r=[])&&r

ลองออนไลน์!


JavaScript (ES6),  100 98 94  87 ไบต์

(tiles)(scores)จะเข้าเป็น กระเบื้องสามารถส่งผ่านในลำดับใดก็ได้

t=>s=>s.map(g=x=>m[x]?m[x?r.push(x)&&x:r.pop()]^=1:g(x-1),t.map(x=>m[x]=1,m=[r=[]]))&&r

ลองออนไลน์!

แสดงความคิดเห็น

t => s =>                 // t[] = tiles; s[] = scores
  s.map(g = x =>          // for each score x in s[]:
    m[x] ?                //   if m[x] is set:
      m[                  //     update the 'middle':
        x ?               //       if x is not equal to 0:
          r.push(x) && x  //         push x in the stack r[] and yield x
        :                 //       else:
          r.pop()         //         pop the last value from the stack
                          //         (may be undefined if the stack is empty)
      ] ^= 1              //     toggle the corresponding flag in m[]
    :                     //   else:
      g(x - 1),           //     try again with x - 1
    t.map(x =>            //   initialization of the 'middle': for each value x in t[]:
      m[x] = 1,           //     set m[x]
      m = [r = []]        //     the stack r[] is stored as the first entry of m[],
                          //     which ensures that g will always stop when x = 0
    )                     //   end of initialization
  ) && r                  // end of main loop; return r[]

1

ถ่าน 35 ไบต์

Fη«≔⌈Φ講κιι¿ι«≔Φθ⁻κιθ⊞υι»¿υ⊞θ⊟υ»Iυ

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

Fη«

วนรอบคะแนน

≔⌈Φ講κιι

มองหาไทล์สูงสุดที่มี

¿ι«

ถ้ามันมีอยู่แล้ว ...

≔Φθ⁻κιθ

... ลบไทล์ออกจากตรงกลาง ...

⊞υι

... และเพิ่มลงในสแต็ก

»¿υ

มิฉะนั้นหากสแต็กไม่ว่างเปล่า ...

⊞θ⊟υ

ลบไทล์ล่าสุดออกจากสแต็กและกลับไปที่กึ่งกลาง

»Iυ

พิมพ์สแต็กผลลัพธ์จากเก่าไปใหม่ล่าสุด



1

05AB1E , 27 22 ไบต์

vÐy>‹ÏDgĀià©K®së\sª])¨

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

คำอธิบาย:

v            # Loop `y` over the (implicit) input-list of scores:
 Ð           #  Triplicate the tiles list (takes it as implicit input in the first iteration)
  y>‹        #  Check for each if `y` <= the value in the tiles list
     Ï       #  Only leave the values at the truthy indices
 D           #  Duplicate the remaining tiles
  ¯Êi        #  If this list is not empty:
     à       #   Pop the list, and push its maximum
      ©      #   Store it in the register, without popping
       K     #   Remove it from the tiles list
        ®    #   Push the maximum again
         s   #   Swap the maximum and tiles-list on the stack
    ë        #  Else:
     \       #   Remove the duplicated empty tiles-list from the stack
      sª     #   Add the last tile to the tiles-list
]            # Close the if-else and loop
 )           # Wrap everything on the stack into a list
  ¨          # Remove the last item (the tiles-list)
             # (and output the result implicitly)

1

Pyth, 32 ไบต์

VE ?JeS+0f!>TNQ=-QeaYJaQ.)|Y]0;Y

ลองออนไลน์ได้ที่นี่หรือตรวจสอบทุกกรณีการทดสอบในครั้งเดียวที่นี่

จะต้องมีห้องพักสำหรับการปรับปรุงที่นี่ที่ไหนสักแห่ง - ข้อเสนอแนะใด ๆ จะได้รับการชื่นชมมาก!

VE ?JeS+0f!>TNQ=-QeaYJaQ.)|Y]0;Y   Implicit: Q=input 1 (middle), E=input 2 (scores), Y=[]
VE                            ;    For each score, as N, in the second input:
         f    Q                      Filter Q, keeping elements T where:
          !>TN                         T is not greater than N 
                                       (less than or equal is the only standard inequality without a token in Pyth, grrr)
       +0                            Prepend 0 to the filtered list
     eS                              Take the largest of the above (_e_nd of _S_orted list)
    J                                Store the above in J
   ?                                 If the above is truthy:
                   aYJ                 Append J to Y
                  e                    Take last element of Y (i.e. J)
               =-Q                     Remove that element from Q and assign the result back to Q
                                     Else:
                          |Y]0         Yield Y, or [0] if Y is empty
                        .)             Pop the last element from the above (mutates Y)
                      aQ               Append the popped value to Q
                               Y   Print Y

1

Perl 5 -apl -MList:Util=max, 97 ไบต์

$_=$".<>;for$i(@F){(($m=max grep$_<=$i,/\d+/g)&&s/ $m\b//?$s:$s=~s/ \d+$//?$_:$G).=$&}$_=$s;s/ //

TIO

อ่านคะแนนและไทล์บนบรรทัดถัดไปและพิมพ์เอาต์พุต

อย่างไร

  • -apl: -pเพื่อวนลูปมากกว่าบรรทัดและพิมพ์, -aautosplit, -lเพื่อ chomp จากอินพุตและเพิ่มอักขระบรรทัดใหม่ไปยังเอาต์พุต
  • $_=$".<> : เพื่ออ่านบรรทัดถัดไป (ไทล์) และเติมช่องว่างลงใน var เริ่มต้น $_
  • for$i(@F){... }ห่วง$iมากกว่า@Fด้านของบรรทัดปัจจุบัน (คะแนน)
  • (.. ?.. :.. ).=$&ผนวกการแข่งขันก่อนหน้านี้กับค่า l ประกอบไปด้วย
  • ($m=max grep$_<=$i,/\d+/g)&&s/ $m\b//?$sในกรณีที่พบค่าสูงสุดและลบออกจากไทล์ ( $_) l-value คือ score ( $s)
  • $s=~s/ \d+$//?$_ ไม่เช่นนั้นหากตัวเลขสุดท้ายสามารถลบออกได้จากคะแนนจะเป็นไทล์
  • :$G ในที่สุดมันก็เป็นขยะเพราะไม่สามารถเกิดขึ้นได้
  • $_=$s;s/ // เพื่อตั้งค่าคะแนนเป็นค่าเริ่มต้น var และลบช่องว่างนำหน้า
โดยการใช้ไซต์ของเรา หมายความว่าคุณได้อ่านและทำความเข้าใจนโยบายคุกกี้และนโยบายความเป็นส่วนตัวของเราแล้ว
Licensed under cc by-sa 3.0 with attribution required.