Isi langkah-langkahnya (secara acak)!

8

Ini adalah Hole-9 dari The Autumn Tournament dari APL CodeGolf . Saya adalah penulis asli masalah di sana, dan dengan demikian diizinkan memposting ulang di sini.


Diberikan array Boolean sederhana (persegi panjang, tidak bergerigi) (dari satu dimensi atau lebih) mengembalikan daftar array yang berbentuk demikian di mana array pertama identik dengan input dan yang terakhir semuanya benar. Semua langkah perantara harus memiliki satu kebenaran lebih dari tetangganya di sebelah kiri (tetapi jika tidak identik). Untuk setiap langkah, bit yang diubah harus dipilih secara semu (dan Anda dapat mengambil seed jika perlu).

Contohnya

[0] memberi [[0],[1]]

[[0]] memberi [[[0]],[[1]]]

[[[1,1,1],[1,1,1],[1,1,1]],[[1,1,1],[1,1,1],[1,1,1]],[[1,1,1],[1,1,1],[1,1,1]]] memberi [[[[1,1,1],[1,1,1],[1,1,1]],[[1,1,1],[1,1,1],[1,1,1]],[[1,1,1],[1,1,1],[1,1,1]]]]

Hasil contoh-contoh berikut tentu saja dapat bervariasi karena keacakan; ini hanya contoh dari output yang valid:

[0,1,0,0] memberi [[0,1,0,0],[1,1,0,0],[1,1,0,1],[1,1,1,1]]

[[0,1,0],[0,0,1]] memberi [[[0,1,0],[0,0,1]],[[1,1,0],[0,0,1]],[[1,1,0],[0,1,1]],[[1,1,1],[0,1,1]],[[1,1,1],[1,1,1]]]

[[0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0]] memberi [[[0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0]],[[0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0],[0,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,1,1,1,1,1,1,1],[1,1,1,1,1,1,1,1]],[[1,1,1,1,1,1,1,1],[0,1,1,1,1,1,1,1],[1,1,1,0,1,1,1,1],[1,1,1,1,1,1,1,1],[1,1,1,1,1,1,1,1],[1,1,1,0,1,1,1,1],[1,1,1,1,1,1,1,1],[1,1,1,1,1,1,1,1]],[[1,1,1,1,1,1,1,1],[0,1,1,1,1,1,1,1],[1,1,1,1,1,1,1,1],[1,1,1,1,1,1,1,1],[1,1,1,1,1,1,1,1],[1,1,1,0,1,1,1,1],[1,1,1,1,1,1,1,1],[1,1,1,1,1,1,1,1]],[[1,1,1,1,1,1,1,1],[0,1,1,1,1,1,1,1],[1,1,1,1,1,1,1,1],[1,1,1,1,1,1,1,1],[1,1,1,1,1,1,1,1],[1,1,1,1,1,1,1,1],[1,1,1,1,1,1,1,1],[1,1,1,1,1,1,1,1]],[[1,1,1,1,1,1,1,1],[1,1,1,1,1,1,1,1],[1,1,1,1,1,1,1,1],[1,1,1,1,1,1,1,1],[1,1,1,1,1,1,1,1],[1,1,1,1,1,1,1,1],[1,1,1,1,1,1,1,1],[1,1,1,1,1,1,1,1]]]

Adm
sumber
1
Tantangan ini benar-benar membuat saya mulai mempertanyakan keputusan yang dibuat pengembang R / S ...
Giuseppe
Pengembang @Giuseppe R / S?
Adám
R (dan S-plus) adalah implementasi S, jadi banyak fungsi dasar R mengoperasikan cara yang ditentukan S mereka, atau dipertahankan untuk memungkinkan kompatibilitas dengan S (atau lebih buruk, S-plus). Saya tidak yakin siapa yang harus disalahkan atas beberapa perilaku tak terduga yang saya temui ketika mencoba menyelesaikan beberapa tantangan ini!
Giuseppe

Jawaban:

3

Jelly , 12 byte

F¬0TX$¦ÐĿ¬ṁ€

Cobalah online!

Bagaimana itu bekerja

F¬0TX$¦ÐĿ¬ṁ€  Main link. Argument: A (array)

F             Flatten A.
 ¬            Negate all Booleans in the result.
       DĿ     Repeatedly call the link to the left until the results are no longer
              unique. Yield the array of all unique results.
      ¦         Sparse application:
   TX$            Pseudo-randomly select an index of a 1.
  0               Replace the element at that index with 0.
         ¬    Once again negate all Booleans.
          ṁ€  Shape each flat array in the result like A.
Dennis
sumber
2

Python 2 , 197 byte

import random,copy
A=[input()]
while"0"in`A[-1]`:
 A+=copy.deepcopy(A[-1]),
 while~0:
	j="A[-1]"
	while[]<eval(j):j+="[%s]"%random.randint(0,~-len(eval(j)))
	if eval(j)<1:exec"%s=1"%j;break
print A

Cobalah online!

Jonathan Frech
sumber
1

Bahasa Wolfram (Mathematica) , 61 byte

FoldList[ReplacePart[#,#2->1]&,#,RandomSample@Position[#,0]]&

Cobalah online!

Penjelasan

Position[#,0]

Temukan semua posisi 0s dalam array bersarang.

RandomSample@...

Kocok daftar posisi.

FoldList[...&,#,...]

Lipat fungsi di sebelah kiri di atas daftar posisi yang dikocok, menggunakan input sebagai nilai awal, dan kumpulkan semua langkah operasi lipatan di hasilnya.

ReplacePart[#,#2->1]

Tetapkan nilai pada posisi yang diberikan ke 1.

Martin Ender
sumber
1

R , 93 82 74 byte

function(a)Reduce(function(x,y){x[y]=T;x},sample(as.list(which(!a))),a,,T)

Cobalah online!

Mengambil R logical arraydan mengembalikan listdari logical arrays.

Jahat sample(as.list(which(!a)))adalah untuk mencegah kasus tepi di sample. Ketika aberisi tepat satu FALSEnilai pada indeks i, samplemengembalikan permutasi acak 1:idaripada sampel ukuran acak 1yang hanya berisi nilai i, jadi saya digunakan as.listuntuk mencegah which(!a)dari menjadi numeric.

Dokumentasi R untuk samplesedikit meminta maaf tentang perilaku ini:

Jika xmemiliki panjang 1, adalah numerik (dalam arti is.numeric) dan x >= 1, pengambilan sampel melalui sampel dilakukan mulai 1: x. Perhatikan bahwa fitur kenyamanan ini dapat menyebabkan perilaku yang tidak diinginkan ketika x memiliki panjang panggilan yang bervariasi seperti sample(x).

Giuseppe
sumber
1

Perl 5 , 78 + 1 ( -p) = 79 byte

while(@a=/0/g){$o.="$_,";for$i(0..rand@a){/0/g}substr$_,-1+pos,1,1}$_="[$o$_]"

Cobalah online!

Himpunan? Array apa? Itu hanya string panjang.

Xcali
sumber
0

Jelly , 19 byte

F¬TṬ€$$o€$ṁ€µX$ÐĿṖṖ

Cobalah online!

Mungkin bisa lebih pendek

Penjelasan

F¬TṬ€$$o€$ṁ€µX$ÐĿṖṖ  Main Link
               ÐĿ    While results are unique:
F                    Flatten the array
     $$              3 links will form a monad
 ¬                   Logical NOT on each element
  T                  Find indices of 1s (0s in the original)
    €                For each 0 in the original
   Ṭ                 Make an array of all 0s containing one 1 there
         $           2 links will form a monad
        €            For each of the mask arrays
       o             Vectorizing logical OR it with the original (flat) array
           €         For each of these subarrays
          ṁ          Reshape it to the original array's shape
            µ        Start a new monadic chain, using the list of possible next steps as the argument
              $      2 links will form a monad
             X       Pick a random element
                 ṖṖ  Remove the last two elements (0 and '' which are selected by X when the list is empty)
HyperNeutrino
sumber
0

Python 2 , 134 132 129 byte

from random import*
a=input()
print a;l=list(`a`)
while'0'in l:l[choice([i for i,c in enumerate(l)if'0'==c])]='1';print''.join(l)

Cobalah online!

TFeld
sumber