Preencha as etapas (aleatoriamente)!


8

Este é o Hole-9 do Torneio de Outono da APL CodeGolf . Eu sou o autor original do problema lá e, portanto, posso republicá-lo aqui.


Dada uma matriz booleana simples (retangular, sem serrilhada) (de uma ou mais dimensões), retorne uma lista de matrizes com formato assim, onde a primeira matriz é idêntica à entrada e a última é verdadeira. Todas as etapas intermediárias devem ter mais uma verdade que seu vizinho à esquerda (mas, caso contrário, devem ser idênticas). Para cada etapa, o bit alterado deve ser escolhido de forma pseudo-aleatória (e você pode coletar uma semente, se necessário).

Exemplos

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

[[0]][[[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]]]]

Os resultados dos exemplos a seguir podem, obviamente, variar devido à aleatoriedade; estes são apenas exemplos de saída válida:

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

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


1
Esses desafios realmente me fizeram começar a questionar as decisões que os desenvolvedores de R / S tomaram ...
Giuseppe

@Giuseppe R / S developers?
Adám

R (e S-plus) é uma implementação de S, portanto, muitas das funções básicas de R operam da maneira que S as especifica ou são mantidas para permitir compatibilidade com S (ou pior, S-plus). Não tenho certeza de quem culpar por alguns dos comportamentos inesperados que encontrei ao tentar resolver alguns desses desafios!
21717 Giuseppe

Respostas:


3

Jelly , 12 bytes

F¬0TX$¦ÐĿ¬ṁ€

Experimente online!

Como funciona

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.

2

Python 2 , 197 bytes

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

Experimente online!


1

Wolfram Language (Mathematica) , 61 bytes

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

Experimente online!

Explicação

Position[#,0]

Encontre todas as posições de 0s na matriz aninhada.

RandomSample@...

Embaralhe a lista de posições.

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

Dobre a função à esquerda sobre a lista aleatória de posições, usando a entrada como valor inicial e colete todas as etapas da operação de dobra no resultado.

ReplacePart[#,#2->1]

Defina o valor na posição especificada como 1.


1

R , 93 82 74 bytes

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

Experimente online!

Toma um R logical arraye retorna um listde logical arrays.

O desagradável sample(as.list(which(!a)))é evitar um caso de vantagem sample. Quando acontém exactamente um FALSEvalor no índice i, sampledevolve uma permutação aleatória de 1:i, em vez de uma amostra aleatória de tamanho 1contendo apenas o valor i, de modo que utilizado as.listpara evitar which(!a)de ser numeric.

A documentação do R sampleé um pedido de desculpas moderado sobre esse comportamento:

Se xtem comprimento 1, é numérico (no sentido de is.numeric) e x >= 1, a amostragem via amostra ocorre a partir de 1: x. Observe que esse recurso de conveniência pode levar a um comportamento indesejado quando x tem duração variável em chamadas como sample(x).


1

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

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

Experimente online!

Matriz? Qual matriz? É apenas uma longa corda.


0

Geléia , 19 bytes

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

Experimente online!

Provavelmente poderia ser mais curto

Explicação

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)

0

Python 2 , 134 132 129 bytes

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)

Experimente online!

Ao utilizar nosso site, você reconhece que leu e compreendeu nossa Política de Cookies e nossa Política de Privacidade.
Licensed under cc by-sa 3.0 with attribution required.