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ematica:
layouts = Graph /@ {Labeled[DirectedEdge[#, #2], #3] & @@@ {{0, 1, ">"}, ... };
path[layout_, a_, b_] :=
StringJoin[
PropertyValue[{layouts[[layout + 1]], #}, EdgeLabels] & /@
DirectedEdge @@@
Partition[FindShortestPath[layouts[[layout + 1]], a, b], 2, 1]]
safetyCheck[layout_, target_] = "";
safetyCheck[0, 1] = safetyCheck[0, 11] = "v<>^";
safetyCheck[0, 2] = "v^";
safetyCheck[0, 3] = safetyCheck[0, 13] = "<>";
safetyCheck[0, 4] = "<<>>";
safetyCheck[0, 5] = "v^";
safetyCheck[0, 6] = "<v^>";
safetyCheck[0, 7] = "><";
safetyCheck[0, 8] = safetyCheck[0, 18] = "<>";
safetyCheck[0, 9] = "v^";
safetyCheck[1, 2] = "v^";
safetyCheck[1, 3] = safetyCheck[1, 13] = safetyCheck[1, 23] = "<<>>";
safetyCheck[1, 4] = "<v<>^>";
safetyCheck[1, 5] = "v^";
safetyCheck[1, 6] = "<v^>";
safetyCheck[1, 7] = "<v^>";
safetyCheck[1, 8] = "v^";
safetyCheck[1, 9] = safetyCheck[1, 19] = "<v^>";
safetyCheck[2, 3] = safetyCheck[2, 13] = "<>";
safetyCheck[2, 4] = "<<>>";
safetyCheck[2, 5] = safetyCheck[2, 15] = "v<>^";
safetyCheck[2, 6] = safetyCheck[2, 16] = "<<<<>>>>";
safetyCheck[2, 7] = "><";
safetyCheck[2, 8] = safetyCheck[2, 18] = "<>";
safetyCheck[2, 9] = safetyCheck[2, 19] = safetyCheck[2, 29] = "<>";
safetyCheck[3, 4] = "<>";
safetyCheck[3, 5] = "v^";
safetyCheck[3, 6] = ">><<";
safetyCheck[3, 7] = safetyCheck[3, 17] = "<<>>";
safetyCheck[3, 8] = safetyCheck[3, 18] = "v><^";
safetyCheck[3, 9] = safetyCheck[3, 19] = safetyCheck[3, 29] = "vvv^^^";
safetyCheck[4, 5] = safetyCheck[4, 15] = "<>";
safetyCheck[4, 6] = safetyCheck[4, 16] = "<<>>";
safetyCheck[4, 7] = ">v^<";
safetyCheck[4, 8] = "v^";
safetyCheck[4, 9] = safetyCheck[4, 19] = safetyCheck[4, 29] = "<>";
safetyCheck[5, 6] = "<>";
safetyCheck[5, 7] = "><";
safetyCheck[5, 8] = "<>";
safetyCheck[5, 9] = safetyCheck[5, 19] = "<<>>";
safetyCheck[6, 7] = "><";
safetyCheck[6, 8] = safetyCheck[6, 18] = "<>";
safetyCheck[6, 9] = "v^";
safetyCheck[7, 8] = safetyCheck[7, 18] = "v><^";
safetyCheck[7, 9] = safetyCheck[7, 19] = safetyCheck[7, 29] = "<>";
safetyCheck[8, 9] = safetyCheck[8, 19] = safetyCheck[8, 29] = "<>";
minions = {};
For[i = 0, i < 10, ++i,
collector = "c";
For[j = i, j < 90, j += 10,
collector = collector <> path[i, j, j + 10] <> "c"
];
AppendTo[minions, collector];
For[newI = i + 1, newI < 10, ++newI,
For[k = 0, k < 10, ++k,
AppendTo[minions,
path[i, j, 10 k + newI] <> "c" <> path[newI, 10 k + newI, newI] <>
safetyCheck[i, 10 k + newI]]
]
]
];
StringRiffle[minions, "\n"]
Na verdade, eu escrevi todas essas safetyCheck
linhas à mão. Mas a primeira linha desse código do Mathematica tem, na verdade, cerca de 28.000 caracteres e foi gerada pelo seguinte código CJam:
'{o
q~]{-1:W;
2b200Te[W%2/{W):W;~\{
"{"W+","W)++",\">\"}"+
"{"W)+","W++",\"<\"}"+
@
}*{
"{"W+","WA+++",\"v\"}"+
"{"WA++","W++",\"^\"}"+
}*}%", "*"Labeled[DirectedEdge[#,#2],#3]&@@@{ }"S/\*
]o',oNoNo}/'}
(O que leva como entrada os 10 layouts codificados no intérprete. Você pode executar o código online. )
Cepção de geração de código!
Explicação
Para começar, dê uma olhada neste script CJam para ver como são os labirintos.
Minha solução é baseada em uma observação importante: enquanto coletarmos itens em uma única coluna, não mudaremos entre layouts, independentemente de as células estarem preenchidas ou não. Em particular, enquanto movermos a coluna mais à esquerda, permaneceremos no layout 0
. Enquanto avançarmos na próxima coluna, permaneceremos no layout 1
.
O mais complicado é como garantir que mudamos entre layouts, porque não sabemos quais células da coluna 1
possuem itens (se houver!).
Então, aqui está o algoritmo (começando na célula 0
no layout 0
):
- Colete todos os itens ao longo da coluna atual, terminando na linha inferior. Esse lacaio nunca vai morrer.
Agora, para cada célula à direita da coluna atual (experimentando-as na ordem principal da coluna), tente mover para lá no layout atual, selecione um item e mova para a linha superior dessa nova coluna usando o novo layout.
Se a célula tentada contiver um item, o layout será alterado e alcançaremos com êxito a nova coluna e layout. Como a nova posição (segura) está na linha superior, mas todas as tentativas de encontrar a próxima coluna incluem 10 movimentos líquidos para cima, todas as outras tentativas falharão, para que possamos ignorá-las.
Se a célula tentada não contiver um item, na maioria dos casos, o lacaio morrerá durante a tentativa de alcançar a linha superior usando o layout errado, descartando essa tentativa. No entanto, esse nem sempre é o caso. Por exemplo, a célula tentada já pode estar na linha superior, portanto, nenhuma movimentação foi feita no novo layout. Da mesma forma, em alguns casos, o caminho da célula tentada para a linha superior é curto o suficiente para ser válido nos dois layouts. Eu coletei todos os casos em que esse é um problema manualmente e determinei um conjunto de movimentos que são válidos apenas no novo layout (mas que movem o lacaio de volta para a célula de destino, portanto, ele é efetivamente um no-op no novo layout). Depois de cada tentativa em que isso pode ser um problema, eu executo esse conjunto de movimentos para matar qualquer lacaio que não
Agora, passamos para o topo da próxima coluna, que contém pelo menos um item. Volte para a etapa 1.
Você pode perceber que a estrutura da solução é a seguinte:
Line with 10 "c"s
90 lines with 1 "c"
Line with 10 "c"s
80 lines with 1 "c"
Line with 10 "c"s
70 lines with 1 "c"
Line with 10 "c"s
60 lines with 1 "c"
...
Line with 10 "c"s
10 lines with 1 "c"
Line with 10 "c"s
Quanto ao código do Mathematica, as safetyCheck
seqüências de caracteres são aqueles movimentos escolhidos a dedo que garantem que alcançamos o novo layout. O primeiro parâmetro para a pesquisa é o layout do qual estamos iniciando e o segundo é a célula que tentamos. Qualquer combinação que não seja mencionada explicitamente fornece apenas uma verificação de segurança vazia (porque nenhuma é necessária).
Além disso, estou simplesmente configurando os 10 labirintos como Graph
objetos, onde existem duas arestas direcionadas entre quaisquer células adjacentes (e conectadas), onde cada aresta é anotada com o movimento necessário para atravessá-la. Com isso, posso simplesmente encontrar os caminhos usando FindShortestPath
e depois extrair os rótulos de borda correspondentes comPropertyValue[..., EdgeLabels]
.
O restante do código apenas usa isso para implementar o algoritmo acima de maneira bastante direta.
Os dados reais do gráfico são armazenados layouts
e foram gerados com o script CJam, que decodifica os números conforme descrito na publicação policial e os transforma em uma lista do Mathematica, que pode ser facilmente transformada em um gráfico.