Điền vào các bước (ngẫu nhiên)!


8

Đây là Hole-9 từ Giải đấu mùa thu của APL CodeGolf . Tôi là tác giả ban đầu của vấn đề ở đó, và do đó được phép đăng lại ở đây.


Cho một mảng Boolean đơn giản (hình chữ nhật, không bị lởm chởm) (có một hoặc nhiều kích thước) trả về một danh sách các mảng có hình dạng như vậy trong đó mảng đầu tiên giống hệt với đầu vào và cuối cùng là hoàn toàn đúng. Tất cả các bước trung gian phải có thêm một sự thật so với hàng xóm bên trái (nhưng nếu không thì giống hệt nhau). Đối với mỗi bước, bit được thay đổi phải được chọn ngẫu nhiên giả (và bạn có thể lấy hạt nếu cần thiết).

Ví dụ

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

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

Tất nhiên, kết quả của các ví dụ sau đây có thể thay đổi do tính ngẫu nhiên; đây chỉ là ví dụ về đầu ra hợp lệ:

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

[[0,1,0],[0,0,1]] cho [[[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]] cho [[[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,0,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,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
Những thách thức này đã thực sự khiến tôi bắt đầu đặt câu hỏi về các quyết định mà các nhà phát triển R / S đã đưa ra ...
Giuseppe

@Giuseppe Nhà phát triển R / S?
Adám

R (và S-plus) là một triển khai của S, vì vậy rất nhiều hàm R cơ sở hoạt động theo cách S chỉ định chúng hoặc được duy trì để cho phép tương thích với S (hoặc tệ hơn là S-plus). Tôi không chắc ai sẽ đổ lỗi cho một số hành vi bất ngờ mà tôi gặp phải trong khi cố gắng giải quyết một số thách thức này!
Giuseppe

Câu trả lời:


3

Thạch , 12 byte

F¬0TX$¦ÐĿ¬ṁ€

Hãy thử trực tuyến!

Làm thế nào nó hoạt động

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.


1

Ngôn ngữ Wolfram (Mathicala) , 61 byte

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

Hãy thử trực tuyến!

Giải trình

Position[#,0]

Tìm tất cả các vị trí của 0s trong mảng lồng nhau.

RandomSample@...

Xáo trộn danh sách các vị trí.

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

Gấp chức năng ở bên trái qua danh sách các vị trí được xáo trộn, sử dụng đầu vào làm giá trị bắt đầu và thu thập tất cả các bước của thao tác gấp trong kết quả.

ReplacePart[#,#2->1]

Đặt giá trị tại vị trí đã cho thành 1.


1

R , 93 82 74 byte

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

Hãy thử trực tuyến!

Lấy một R logical arrayvà trả về a listcủa logical arrays.

Khó chịu sample(as.list(which(!a)))là để ngăn chặn một trường hợp cạnh trong sample. Khi achứa chính xác một FALSEgiá trị tại chỉ số i, sampletrả về một hoán vị ngẫu nhiên 1:ichứ không phải là một mẫu ngẫu nhiên kích thước 1chỉ chứa các giá trị i, vì vậy tôi sử dụng as.listđể ngăn chặn which(!a)việc bị numeric.

Tài liệu R cho samplexin lỗi nhẹ về hành vi này:

Nếu xcó độ dài 1, là số (theo nghĩa is.numeric) và x >= 1, lấy mẫu qua mẫu diễn ra từ 1: x. Lưu ý rằng tính năng tiện lợi này có thể dẫn đến hành vi không mong muốn khi x có độ dài khác nhau trong các cuộc gọi như sample(x).



0

Thạch , 19 byte

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

Hãy thử trực tuyến!

Có lẽ có thể ngắn hơn

Giải trình

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)

Khi sử dụng trang web của chúng tôi, bạn xác nhận rằng bạn đã đọc và hiểu Chính sách cookieChính sách bảo mật của chúng tôi.
Licensed under cc by-sa 3.0 with attribution required.