ピコミノの演奏


10

Pickominoゲームでは、テーブルの中央にいくつかのタイルがあり、それぞれに異なる正の整数が付いています。プレイヤーは毎ターン、特定の方法でさいころを振って、負でない整数であるスコアを取得します。

次に、プレーヤーはスコアがまだ低いか等しい最も高い番号のタイルを取得し、中央からタイルを削除してスタックに追加します。真ん中のすべての数字がプレーヤーのスコアよりも高いためにこれが不可能な場合、プレーヤーはスタックから一番上のタイル(最後に追加されたもの)を失い、中央に戻されます。プレーヤーにタイルが残っていない場合、何も起こりません。

チャレンジ

自分と対戦するプレーヤーをシミュレートします。中央のタイルのリストと、プレーヤーが獲得したスコアのリストが表示されます。すべてのターンが評価された後、プレーヤーのタイルのリストを返します。

チャレンジルール

  • タイルを含むリストが順序付けされていて、整数が2回含まれていないと想定できます。
  • 入力の両方のリストを任意の順序で取得できます
  • 出力はスタック上のタイルの順序を維持する必要がありますが、リストを上から下にソートするか、下から上にソートするかを決定できます。

一般的なルール

  • これはなので、バイト単位の最短の回答が優先されます。
    コードゴルフ言語では、コードゴルフ言語以外の言語で回答を投稿しないようにしないでください。「あらゆる」プログラミング言語について、可能な限り短い答えを考え出すようにしてください。
  • デフォルトのI / Oルールを使用した回答には標準ルールが適用されるため、STDIN / STDOUT、関数/メソッドを適切なパラメーターで使用し、戻り値の型の完全なプログラムを使用できます。
  • デフォルトの抜け穴は禁止されています。
  • 可能であれば、コードのテスト(TIOなど)のリンクを追加してください。
  • 回答の説明を追加することをお勧めします。

(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]

プレイヤーはバストしてゼロを獲得します。したがって、番号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: []

サンドボックス


中央に値0のタイルがないと想定できますか?
無視の具現化

@EmbodimentofIgnorance「正の整数」と書かれているので、そうです。
Ørjanヨハンセン

タイルは一意なので、ビットマスクとして使用できますか?
Arnauld

@TRITICIMAGVSはい、真ん中の山が空の場合、プレーヤーは真ん中からタイルを取ることができないため、タイルを失います(タイルがある場合)
Black Owl Kai

@Arnauldそれは許容できる
Black Owl Kai

回答:


3

ハスケル119の 111 104 103バイト

ØrjanJohansenのおかげで1バイト節約

(#)=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
([]%)

オンラインでお試しください!

タイルが降順で並べ替えられていると仮定します。

ここではそれほど豪華なことはしていません。最初の引数はプレイヤーのパイル、2番目はスコア、3番目は真ん中のパイルです。


1
sortが上昇しているため、これは正しくありません。ただし、TIOテストケースがそのブランチにヒットすることはありません。このように繰り返すときは、毎回すべてのケースをテストすることを強くお勧めします。
Ørjanヨハンセン

@ØrjanJohansenありがとう!今修正されました。少なくとももうインポートする必要はありません!
アドホックガーフハンター、

でバイトを保存します(#)=span.(<)
Ørjanヨハンセン

@ØrjanJohansen変更が行われました。面白いことに、私はそれを以前に試し、バイトを追加したと思いました。
アドホックガーフハンター

3

Japt、24バイト

ウーフ!それは私が思ったほどうまくいかなかった!

入力を逆の順序で受け取ります。

®=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単にリフレクションのプレースホルダーではなく、実際には戻り値の型である場合。2バイトを節約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ビットマスクとして、スコアを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

05AB1E27 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 -apl -MList:Util=max5、97バイト

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

TIO

次の行のスコアとタイルを読み取り、出力を印刷します。

どうやって

  • -apl-p線やプリント、オーバーループに-a自動split、-l入力からムシャムシャ食べるし、出力に改行文字を追加します
  • $_=$".<> :次の行(タイル)を読み取り、デフォルトの変数の前にスペースを追加します $_
  • for$i(@F){... }ループ$iの上に@F現在の行のフィールド(スコア)
  • (.. ?.. :.. ).=$&前の一致を三項l値に追加
  • ($m=max grep$_<=$i,/\d+/g)&&s/ $m\b//?$s最大値が見つかりタイルから削除された場合($_)l値はスコア($s
  • $s=~s/ \d+$//?$_ それ以外の場合、最後の数がスコアから削除される可能性がある場合、それはタイルです
  • :$G 最後に発生することができないのでそれはゴミです
  • $_=$s;s/ // スコアをデフォルトの変数に設定し、先行スペースを削除する
弊社のサイトを使用することにより、あなたは弊社のクッキーポリシーおよびプライバシーポリシーを読み、理解したものとみなされます。
Licensed under cc by-sa 3.0 with attribution required.