Bàn cờ bị cong vênh


20

Thử thách này là về việc xây dựng một bàn cờ trong đó kích thước hình vuông, thay vì không đổi trên bàn cờ, tuân theo một trình tự không giảm nhất định, như được mô tả dưới đây.

Bảng được định nghĩa lặp đi lặp lại. Một ban giám kích thước n×n được mở rộng kích thước (n+k)×(n+k) bằng cách mở rộng nó xuống và sang phải bằng một "lớp" của hình vuông kích thước k , nơi k là số chia lớn nhất của n không vượt n . Các hình vuông trong đường chéo luôn có cùng màu.

Cụ thể, hãy xem xét bảng với màu sắc đại diện như #+.

  1. Khởi tạo bàn cờ để

    #
    
  2. Bảng cho đến nay có kích thước 1×1 . Ước duy nhất của 11 , và nó không vượt quá 1 . Vì vậy, chúng tôi lấyk=1và mở rộng bảng bằng cách thêm một lớp hình vuông có kích thước1, với#đường chéo:

    #+
    +#
    
  3. Bảng được xây dựng cho đến nay có kích thước 2×2 . Các ước của 21,2 , và số chia tối đa không quá 21. Vì vậy, một lần nữak=1, và bảng được mở rộng thành

    #+#
    +#+
    #+#
    
  4. Kích thước là 3×3 . k=1 . Mở rộng đến

    #+#+
    +#+#
    #+#+
    +#+#
    
  5. Kích thước là 4×4 . Bây giờ k=2 , vì 2 là số chia tối đa 4 không quá 4 . Mở rộng với một lớp có độ dày2, được hình thành bởi các hình vuông có kích thước2×2, với màu sắc#theo đường chéo:

    #+#+##
    +#+###
    #+#+++
    +#+#++
    ##++##
    ##++##
    
  6. Kích thước là 6×6 . Bây giờ k=2 . Mở rộng đến kích thước 8×8 . Bây giờ k=2 . Mở rộng đến kích thước 10×10 . Bây giờ k=2 . Mở rộng đến kích thước 12×12 . Bây giờ k=3 . Mở rộng đến kích thước 15 :

    #+#+##++##++###
    +#+###++##++###
    #+#+++##++#####
    +#+#++##++##+++
    ##++##++##+++++
    ##++##++##+++++
    ++##++##++#####
    ++##++##++#####
    ##++##++##++###
    ##++##++##+++++
    ++##++##++##+++
    ++##++##++##+++
    ###+++###+++###
    ###+++###+++###
    ###+++###+++###
    

Lưu ý cách các hình vuông được thêm gần đây nhất, có kích thước 3×3 , có các cạnh trùng một phần với các hình vuông được thêm trước đó có kích thước 2×2 .

Chuỗi được hình thành bởi các giá trị của k là không giảm:

1 1 1 2 2 2 2 3 3 3 3 4 4 4 6 6 6 6 6 6 ...

và dường như không có trong OEIS. Tuy nhiên, phiên bản tích lũy của nó, là chuỗi các kích thước của bảng, là A139542 (nhờ @Arnauld đã nhận thấy).

Các thách thức

Dữ liệu vào : một số nguyên dương S biểu thị số lớp trong bảng. Nếu bạn thích, bạn cũng có thể lấy S1 thay vì S làm đầu vào ( 0 -exexed); xem bên dưới.

Đầu ra : một đại diện nghệ thuật ASCII của một bảng với các lớp S

  • Đầu ra có thể thông qua STDOUT hoặc một đối số được trả về bởi một hàm. Trong trường hợp này, nó có thể là một chuỗi với dòng mới, mảng ký tự 2D hoặc một chuỗi các chuỗi.

  • Bạn luôn có thể chọn bất kỳ hai ký tự để đại diện cho bảng.

  • Bạn luôn có thể chọn hướng phát triển. Đó là, thay vì các đại diện ở trên (phát triển xuống dưới và phải), bạn có thể tạo ra bất kỳ phiên bản phản ánh hoặc xoay nào của nó.

  • Trailing hoặc không gian hàng đầu được cho phép (nếu đầu ra thông qua STDOUT), miễn là không gian không phải là một trong hai ký tự được sử dụng cho bảng.

  • Bạn có thể tùy ý sử dụng đầu vào " 0 -exexed "; nghĩa là lấy đầu vào S1 , chỉ định một bảng có các lớp S

Mã ngắn nhất trong byte thắng.

Các trường hợp thử nghiệm

1:

#

3:

#+#
+#+
#+#

5:

#+#+##
+#+###
#+#+++
+#+#++
##++##
##++##

6:

#+#+##++
+#+###++
#+#+++##
+#+#++##
##++##++
##++##++
++##++##
++##++##

10:

#+#+##++##++###+++
+#+###++##++###+++
#+#+++##++#####+++
+#+#++##++##+++###
##++##++##+++++###
##++##++##+++++###
++##++##++#####+++
++##++##++#####+++
##++##++##++###+++
##++##++##+++++###
++##++##++##+++###
++##++##++##+++###
###+++###+++###+++
###+++###+++###+++
###+++###+++###+++
+++###+++###+++###
+++###+++###+++###
+++###+++###+++###

15:

#+#+##++##++###+++###+++####++++####
+#+###++##++###+++###+++####++++####
#+#+++##++#####+++###+++####++++####
+#+#++##++##+++###+++#######++++####
##++##++##+++++###+++###++++####++++
##++##++##+++++###+++###++++####++++
++##++##++#####+++###+++++++####++++
++##++##++#####+++###+++++++####++++
##++##++##++###+++###+++####++++####
##++##++##+++++###+++#######++++####
++##++##++##+++###+++#######++++####
++##++##++##+++###+++#######++++####
###+++###+++###+++###+++++++####++++
###+++###+++###+++###+++++++####++++
###+++###+++###+++###+++++++####++++
+++###+++###+++###+++###++++####++++
+++###+++###+++###+++#######++++####
+++###+++###+++###+++#######++++####
###+++###+++###+++###+++####++++####
###+++###+++###+++###+++####++++####
###+++###+++###+++###+++++++####++++
+++###+++###+++###+++###++++####++++
+++###+++###+++###+++###++++####++++
+++###+++###+++###+++###++++####++++
####++++####++++####++++####++++####
####++++####++++####++++####++++####
####++++####++++####++++####++++####
####++++####++++####++++####++++####
++++####++++####++++####++++####++++
++++####++++####++++####++++####++++
++++####++++####++++####++++####++++
++++####++++####++++####++++####++++
####++++####++++####++++####++++####
####++++####++++####++++####++++####
####++++####++++####++++####++++####
####++++####++++####++++####++++####

25:

#+#+##++##++###+++###+++####++++##########++++++######++++++######++++++++++++++########++++++++########++++++++########
+#+###++##++###+++###+++####++++##########++++++######++++++######++++++++++++++########++++++++########++++++++########
#+#+++##++#####+++###+++####++++##########++++++######++++++######++++++++++++++########++++++++########++++++++########
+#+#++##++##+++###+++#######++++##########++++++######++++++######++++++++++++++########++++++++########++++++++########
##++##++##+++++###+++###++++####++++######++++++######++++++######++++++++++++++########++++++++########++++++++########
##++##++##+++++###+++###++++####++++######++++++######++++++######++++++++++++++########++++++++########++++++++########
++##++##++#####+++###+++++++####++++++++++######++++++######++++++######++++++++########++++++++########++++++++########
++##++##++#####+++###+++++++####++++++++++######++++++######++++++######++++++++########++++++++########++++++++########
##++##++##++###+++###+++####++++####++++++######++++++######++++++##############++++++++########++++++++########++++++++
##++##++##+++++###+++#######++++####++++++######++++++######++++++##############++++++++########++++++++########++++++++
++##++##++##+++###+++#######++++####++++++######++++++######++++++##############++++++++########++++++++########++++++++
++##++##++##+++###+++#######++++####++++++######++++++######++++++##############++++++++########++++++++########++++++++
###+++###+++###+++###+++++++####++++######++++++######++++++######++++++########++++++++########++++++++########++++++++
###+++###+++###+++###+++++++####++++######++++++######++++++######++++++########++++++++########++++++++########++++++++
###+++###+++###+++###+++++++####++++######++++++######++++++######++++++########++++++++########++++++++########++++++++
+++###+++###+++###+++###++++####++++######++++++######++++++######++++++########++++++++########++++++++########++++++++
+++###+++###+++###+++#######++++##########++++++######++++++######++++++++++++++########++++++++########++++++++########
+++###+++###+++###+++#######++++##########++++++######++++++######++++++++++++++########++++++++########++++++++########
###+++###+++###+++###+++####++++####++++++######++++++######++++++######++++++++########++++++++########++++++++########
###+++###+++###+++###+++####++++####++++++######++++++######++++++######++++++++########++++++++########++++++++########
###+++###+++###+++###+++++++####++++++++++######++++++######++++++######++++++++########++++++++########++++++++########
+++###+++###+++###+++###++++####++++++++++######++++++######++++++######++++++++########++++++++########++++++++########
+++###+++###+++###+++###++++####++++++++++######++++++######++++++######++++++++########++++++++########++++++++########
+++###+++###+++###+++###++++####++++++++++######++++++######++++++######++++++++########++++++++########++++++++########
####++++####++++####++++####++++##########++++++######++++++######++++++########++++++++########++++++++########++++++++
####++++####++++####++++####++++##########++++++######++++++######++++++########++++++++########++++++++########++++++++
####++++####++++####++++####++++##########++++++######++++++######++++++########++++++++########++++++++########++++++++
####++++####++++####++++####++++##########++++++######++++++######++++++########++++++++########++++++++########++++++++
++++####++++####++++####++++####++++######++++++######++++++######++++++########++++++++########++++++++########++++++++
++++####++++####++++####++++####++++######++++++######++++++######++++++########++++++++########++++++++########++++++++
++++####++++####++++####++++####++++++++++######++++++######++++++##############++++++++########++++++++########++++++++
++++####++++####++++####++++####++++++++++######++++++######++++++##############++++++++########++++++++########++++++++
####++++####++++####++++####++++####++++++######++++++######++++++######++++++++########++++++++########++++++++########
####++++####++++####++++####++++####++++++######++++++######++++++######++++++++########++++++++########++++++++########
####++++####++++####++++####++++####++++++######++++++######++++++######++++++++########++++++++########++++++++########
####++++####++++####++++####++++####++++++######++++++######++++++######++++++++########++++++++########++++++++########
######++++++######++++++######++++++######++++++######++++++######++++++++++++++########++++++++########++++++++########
######++++++######++++++######++++++######++++++######++++++######++++++++++++++########++++++++########++++++++########
######++++++######++++++######++++++######++++++######++++++######++++++++++++++########++++++++########++++++++########
######++++++######++++++######++++++######++++++######++++++######++++++++++++++########++++++++########++++++++########
######++++++######++++++######++++++######++++++######++++++######++++++########++++++++########++++++++########++++++++
######++++++######++++++######++++++######++++++######++++++######++++++########++++++++########++++++++########++++++++
++++++######++++++######++++++######++++++######++++++######++++++##############++++++++########++++++++########++++++++
++++++######++++++######++++++######++++++######++++++######++++++##############++++++++########++++++++########++++++++
++++++######++++++######++++++######++++++######++++++######++++++##############++++++++########++++++++########++++++++
++++++######++++++######++++++######++++++######++++++######++++++##############++++++++########++++++++########++++++++
++++++######++++++######++++++######++++++######++++++######++++++##############++++++++########++++++++########++++++++
++++++######++++++######++++++######++++++######++++++######++++++##############++++++++########++++++++########++++++++
######++++++######++++++######++++++######++++++######++++++######++++++++++++++########++++++++########++++++++########
######++++++######++++++######++++++######++++++######++++++######++++++++++++++########++++++++########++++++++########
######++++++######++++++######++++++######++++++######++++++######++++++++++++++########++++++++########++++++++########
######++++++######++++++######++++++######++++++######++++++######++++++++++++++########++++++++########++++++++########
######++++++######++++++######++++++######++++++######++++++######++++++++++++++########++++++++########++++++++########
######++++++######++++++######++++++######++++++######++++++######++++++++++++++########++++++++########++++++++########
++++++######++++++######++++++######++++++######++++++######++++++######++++++++########++++++++########++++++++########
++++++######++++++######++++++######++++++######++++++######++++++######++++++++########++++++++########++++++++########
++++++######++++++######++++++######++++++######++++++######++++++##############++++++++########++++++++########++++++++
++++++######++++++######++++++######++++++######++++++######++++++##############++++++++########++++++++########++++++++
++++++######++++++######++++++######++++++######++++++######++++++##############++++++++########++++++++########++++++++
++++++######++++++######++++++######++++++######++++++######++++++##############++++++++########++++++++########++++++++
######++++++######++++++######++++++######++++++######++++++######++++++########++++++++########++++++++########++++++++
######++++++######++++++######++++++######++++++######++++++######++++++########++++++++########++++++++########++++++++
######++++++######++++++######++++++######++++++######++++++######++++++########++++++++########++++++++########++++++++
######++++++######++++++######++++++######++++++######++++++######++++++########++++++++########++++++++########++++++++
######++++++######++++++######++++++######++++++######++++++######++++++++++++++########++++++++########++++++++########
######++++++######++++++######++++++######++++++######++++++######++++++++++++++########++++++++########++++++++########
++++++######++++++######++++++######++++++######++++++######++++++######++++++++########++++++++########++++++++########
++++++######++++++######++++++######++++++######++++++######++++++######++++++++########++++++++########++++++++########
++++++######++++++######++++++######++++++######++++++######++++++######++++++++########++++++++########++++++++########
++++++######++++++######++++++######++++++######++++++######++++++######++++++++########++++++++########++++++++########
++++++######++++++######++++++######++++++######++++++######++++++######++++++++########++++++++########++++++++########
++++++######++++++######++++++######++++++######++++++######++++++######++++++++########++++++++########++++++++########
++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++
++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++
++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++
++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++
++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++
++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++
++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++
++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++
########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########
########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########
########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########
########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########
########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########
########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########
########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########
########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########
++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++
++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++
++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++
++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++
++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++
++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++
++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++
++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++
########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########
########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########
########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########
########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########
########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########
########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########
########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########
########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########
++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++
++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++
++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++
++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++
++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++
++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++
++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++
++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++
########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########
########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########
########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########
########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########
########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########
########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########
########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########
########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########++++++++########

Là một ma trận số nguyên được phép làm đầu ra (ví dụ 0 và 1), hay nó phải là chuỗi / ký tự?
Nick Kennedy

@Nick Nó phải là ký tự, xin lỗi
Luis Mendo

2
Câu hỏi rất hay!
Greg Martin

@GregMartin Này, cảm ơn!
Luis Mendo

Câu trả lời:


3

Thạch , 40 31 byte

1SÆD>Ðḟ½ƊṀṭƲ³¡Äż$Ḷ:Ḃ^þ`ʋ/€ḷ""/Y

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

S1

Không có dấu vết Y, điều này trả về một danh sách các danh sách các số nguyên, nhưng điều này nằm ngoài thông số cho thử thách này.

Giải trình

Chương trình này hoạt động trong ba giai đoạn.

  1. kk
  2. k
  3. Làm việc thông qua danh sách các bàn cờ, mỗi lần thay thế phần trên cùng bên trái của bảng tiếp theo bằng bảng hiện có.

Giai đoạn 1

1                 | Start with 1
           Ʋ³¡    | Loop through the following the number of times indicated by the first argument to the program; this generates a list of values of k
 S                | - Sum
        Ɗ         | - Following three links as a monad 
  ÆD              |   - List of divisors
    >Ðḟ½          |   - Exclude those greater than the square root
         Ṁ        |   - Maximum
          ṭ       | - Concatenate this to the end of the current list of values of k 
              Äż$ | Zip the cumulative sum of the values of k with the values

Giai đoạn 2

      ʋ/€ | For each pair of k and cumulative sum, call the following as a dyad with the cumulative sum of k as the left argument and k as the right (e.g. 15, 3)
Ḷ         | - Lowered range [0, 1 ... , 13, 14]
 :        | - Integer division by k [0, 0, 0, 1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 4]
  Ḃ       | - Mod 2 [0, 0, 0, 1, 1, 1, 0, 0, 0, 1, 1, 1, 0, 0, 0]
   ^þ`    | - Outer product using xor function and same argument to both side

Giai đoạn 3

   /  | Reduce using the following:
ḷ""   | - Replace the top left portion of the next matrix with the current one
    Y | Finally join by newlines

Tôi nghĩ rằng người hỏi thực sự muốn #+nhân vật. Nhưng wow, vẫn ấn tượng, tôi hiểu khoảng một nửa. Và làm thế nào để bạn thậm chí lập trình trong một ngôn ngữ như vậy? Có một bảng các ký tự và ý nghĩa của chúng mà bạn vừa sao chép từ đâu?
Fabian Röling

@ FabianRöling OP tuyên bố bất kỳ hai ký tự đều được chấp nhận. Có một hướng dẫn giới thiệu tốt cho Jelly tại github.com/DennisMitchell/jelly . Nếu bạn biết Python, nguồn cũng khá dễ đọc. Ngay cả với hướng dẫn và danh sách các nguyên tử và Quicks, tôi thấy rằng nó đã mất một ít thời gian và trong một số trường hợp tham khảo nguồn để có được đầu của tôi xung quanh nó.
Nick Kennedy


4

Python 2 , 217 215 212 byte

def f(x):
 b=['1'];n=1
 for i in range(x):P=max(j*(n%j<(j<=n**.5))for j in range(1,1+n));n+=P;b=[l+P*`j/P%2^i%2`for j,l in enumerate(b)];s=len(b[0]);b+=[((v*P+`1^int(v)`*P)*s)[:s]for v in b[0][len(b):]]
 return b

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

Chỉ mục 0, sử dụng 01làm ký tự


1
@LuisMendo đã lưu 2 byte: D
Rod

3

Python 2 , 184 178 176 169 byte

def h(j,a=['1'],R=range):
 for i in R(j):L=len(a);k=max(x for x in R(1,L+1)if(x*x<=L)>L%x);a=[a[m]+k*`(i+m/k)%2`for m in R(L)]+[((`i%2`*k+`~i%2`*k)*L)[:L+k]]*k
 return a

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

Sử dụng 1, 0cho #, -; sử dụng 0-exexing.


2

JavaScript (ES7), 164 byte

Đầu vào là 0 chỉ mục. Xuất ra một ma trận với0cho #1cho +.

n=>(b=[1],g=(a,w,d=w**.5|0)=>b[n]?a:w%d?g(a,w,d-1):g(a.concat(Array(d).fill(b.push(d)&&i++)),w+d))([0],i=1).map((_,y,a)=>a.map((_,x)=>(x/b[v=a[x>y?x:y]]^y/b[v])&1))

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


2

Than , 37 byte

FN«≔⊕⌈Φ₂⊕Lυ¬﹪Lυ⊕κηFη«PL⭆⊞Oυω§#+÷⁻κμη↙

Hãy thử trực tuyến! Liên kết là phiên bản dài dòng của mã. 1 chỉ mục. Đầu ra tăng xuống và trái (xuống và phải tốn thêm một byte, nhưng có thể tăng lên cho cùng một số byte). Giải trình:

FN«

Vòng lặp S lần

≔⊕⌈Φ₂⊕Lυ¬﹪Lυ⊕κη

Tính toán kn+1. Điều này chỉ làm cho một sự khác biệt khin= =0 trong trường hợp này công thức này cho phép k= =1.

Fη«

Vòng lặp k lần, một lần cho mỗi hàng và cột mới.

PL⭆⊞Oυω§#+÷⁻κμη

Xuất ra hàng và cột, chắc chắn xen kẽ giữa các ký tự #+ký tự theo cách #luôn luôn là ký tự đầu tiên nhưng có một ranh giới ở cuối chuỗi (vì chúng ta đang vẽ từ đường chéo ra ngoài). ⊞Oυωlàm cho mỗi hàng một ký tự dài hơn mỗi lần, cũng theo dõin như chiều dài.

Di chuyển xuống và để sẵn sàng cho hàng tiếp theo.


2

05AB1E , 43 42 byte

$G©ÐX‚ˆÑʒ®>t‹}àDU+}¯εÝ`θ÷ɨDδ^}RζεðKζðδK€θ

Lấy cảm hứng từ @NickKennedy 'Jelly câu trả lời s , và phần đuôi ζεðKζðδK€θlà một cổng từ @Emigna ' s 05AB1E trả lời ở đây .

Trả về một ma trận 0thay vì #1thay vì +.

Dùng thử trực tuyến hoặc thử trực tuyến bằng cách xuất đầu tiên[2,n]kết quả ( J,ở chân trang và --no-lazycờ sẽ in đẹp ma trận kết quả).

Giải trình:

$                # Push 1 and the input
 G               # Loop the input - 1 amount of times:
  ©              #  Store the top of the stack in variable `r` (without popping)
   Ð             #  And triplicate the top as well
    X           #  Pair it with variable `X` (which is 1 by default)
      ˆ          #  And pop and store this pair in the global array
    Ñ            #  Get the divisors of the integer we triplicated
     ʒ         #  Get the highest divisor which is truthy for:
                #   Where the divisor integer is smaller than
      ®>t        #   the square root of `r+1`
            DU   #  Store a copy of this largest filtered divisor as new variable `X`
              +  #  And add it to the triplicated integer
               # After the loop: push the global array
   ε             # Map each pair to:
    Ý θ          #  Convert the first value in the pair to a list in the range [0,n]
     `           #  and push both this list and the second value to the stack
       ÷         # Integer-divide each value in the list by the second value
        É        # Check for each value if it's even (1 if even; 0 if odd)
         ¨       # Remove the last item
          Dδ     # Loop double vectorized over this list:
            ^    #  And XOR the values with each other
   }R            # After the map: reverse the list of digit-matrices
     ζ           # Zip/transpose; swapping rows and columns, with a space as filler
      ε          # map each matrix to:
       ðK        #  Remove all spaces from the current matrix
         ζ       #  Zip/transpose with a space as filler again
          ðδK    #  Deep remove all spaces
             €θ  #  Then only leave the last values of each row
                 # (after which the resulting matrix of 0s and 1s is output implicitly)

1

Haskell, 149 146 byte

(iterate g["#"]!!)
g b|let e=(<$[1..d]);l=length b;d=last[i|i<-[1..l],i*i<=l,mod l i<1];m="+#"++m=(e$take(l+d)$e=<<'#':m)++zipWith(++)(e=<<e<$>m)b

Đây là 0 được lập chỉ mục, trả về một danh sách các chuỗi và phát triển lên và xuống.

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

(iterate g["#"]!!)                    -- start with ["#"], repeatedly add a layer
                                      -- (via function 'g'), collect all results in
                                      -- a list and index it with the input number

g b | let                             -- add a single layer to chessboard 'b'

 l=length b                           -- let 'l' be the size of 'b'
 d=last[i|i<-[1..l],i*i<=l,mod l i<1] -- let 'd' be the size of the new layer
 e=(<$[1..d])                         -- let 'e' be a functions that makes 'd'
                                      --   copies of it's argument
 m="#+"++m                            -- let 'm' be an infinite string of "+#+#+..."

 =                                    -- return
              zipWith(++)             --   concatenate pairwise
                         (e=<<e<$>m)  --   a list of squares made by expanding each
                                      --   char in 'm' to size 'd'-by-'d'
                                    b --   and 'b' (zipWith truncates the infinite
                                      --   list of squares to the length of 'b')
                                      --
           ++                         --   and prepend
                                      --
(e$take(l+d)$e=<<'#':m)               --   the top layer, i.e. a list of 'd' strings
                                      --   each with the pattern 'd' times '#'
                                      --   followed by 'd' times '+', etc., each
                                      --   shortened to the correct size of 'l'+'g'

1

Perl 6 , 156 144 155 154 byte

+11 để sửa lỗi được báo cáo bởi nimi.

{$!=-1;join "
",(1,{my \k=max grep $_%%*,1.. .sqrt;++$!;flat .kv.map(->\i,\l {l~($!+i/k)%2+|0 x k}),substr(($!%2 x k~1-$!%2 x k)x$_,0,$_+k)xx k}...*)[$_]}

Dựa vào giải pháp Python của Chas Brown . Mất S không có chỉ số. Đầu ra 01.

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


Đã sửa. Bây giờ các góc nên chia sẻ cùng màu.
bb94
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.