뒤틀린 체스 판


20

이 과제는 보드 전체에서 일정하지 않고 정사각형 크기가 아래에서 설명하는 것처럼 줄이지 않는 특정 순서를 따르는 체스 판을 만드는 것입니다.

보드는 반복적으로 정의됩니다. 크기의 기판 크기로 확대된다 크기의 사각형의 "층"에 의해 아래로 연장하여 오른쪽으로 , 가장 큰 약수 은 초과하지 않습니다 . 대각선의 사각형은 항상 같은 색입니다.n×n(n+k)×(n+k)kknn

구체적으로, #및로 표현 된 색상의 보드를 고려하십시오 +.

  1. 체스 판을 초기화

    #
    
  2. 지금까지 보드의 크기는 입니다. 의 유일한 제수1×111 , 그것은 초과하지 않는 1 . 따라서k=1을 취하고대각선과 함께크기가1인 사각형의 레이어를 추가하여 보드를 확장하십시오#.

    #+
    +#
    
  3. 지금까지 만들어진 보드의 크기는 2×2 입니다. 2 의 제수 는 1,2 이며 최대 제수는 √를 초과하지 않습니다21입니다. 다시케이=1이고 보드는

    #+#
    +#+
    #+#
    
  4. 크기는 × 입니다. 케이=1 입니다. 연장해서, 확장해서

    #+#+
    +#+#
    #+#+
    +#+#
    
  5. 크기는 4×4 입니다. 지금 케이=2 때문에, 2 의 최대의 제수 인 4 이하가 4 . 대각선의색상으로2×2크기의 사각형으로 형성된두께2층으로 확장하십시오.2×2#

    #+#+##
    +#+###
    #+#+++
    +#+#++
    ##++##
    ##++##
    
  6. 크기는 6×6 입니다. 이제 케이=2 입니다. 8×8 크기로 확장하십시오 . 이제 케이=2 입니다. 크기 10×10 확장하십시오 . 이제 케이=2 입니다. 12×12 크기로 확장하십시오 . 이제 케이= 입니다. 크기 15 확장 :

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

크기가 × 인 가장 최근에 추가 된 정사각형이 크기가 2×2 인 이전에 추가 된 정사각형의 측면과 부분적으로 일치하는 점에 유의하십시오 .

케이 값으로 형성된 순서 는 감소하지 않습니다.

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

OEIS에없는 것 같습니다. 그러나 기판의 크기들의 시퀀스 인 그 누적 버전이다 A139542 (덕분 @Arnauld 몰래 경우).

도전

입력 : 보드의 레이어 수를 나타내는 양의 정수 에스원하는 경우 입력 대신 S 대신 에스1 얻을 수도 있습니다 ( 0- 인덱스). 아래를 참조하십시오.에스0

출력 : 에스 레이어 가있는 보드의 ASCII 아트 표현입니다 .

  • 출력은 STDOUT 또는 함수에 의해 리턴 된 인수를 통해 이루어질 수 있습니다. 이 경우 줄 바꿈, 2D 문자 배열 또는 문자열 배열이있는 문자열 일 수 있습니다.

  • 보드를 나타내는 두 문자 를 일관되게 선택할 수 있습니다 .

  • 성장 방향 을 일관되게 선택할 수 있습니다 . 즉, 위에서 아래로 (오른쪽으로 자라는) 표현 대신 반사되거나 회전 된 버전을 만들 수 있습니다.

  • 공백 이 보드에 사용되는 두 문자 중 하나가 아닌 한 후행 또는 선행 공백 이 허용됩니다 (출력이 STDOUT을 통해 인 경우).

  • 선택적으로 " 0 -indexed "입력을 사용할 수 있습니다 . 즉, S 레이어가 있는 보드를 지정하는 입력 에스1 로 간주하십시오 .에스

바이트 단위의 최단 코드가 이깁니다.

테스트 사례

1:

#

3:

#+#
+#+
#+#

5:

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

6:

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

10:

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

15:

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

25:

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

정수 행렬이 출력으로 허용됩니까 (예 : 0과 1), 문자열 / 문자 여야합니까?
Nick Kennedy

@Nick 그것은 문자가되어야합니다, 죄송합니다
Luis Mendo

2
잘 쓰여진 질문!
Greg Martin

@GregMartin 안녕하세요, 감사합니다!
Luis Mendo

답변:


3

젤리 , 40 31 바이트

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

온라인으로 사용해보십시오!

에스1

후행 Y이 없으면 정수 목록의 목록을 반환하지만이 문제는 사양에 맞지 않습니다.

설명

이 프로그램은 3 단계로 진행됩니다.

  1. 케이케이
  2. 타일 ​​크기 각각에 대한 바둑판을 생성하십시오.케이
  3. 다음 보드의 왼쪽 상단을 기존 보드로 교체 할 때마다 바둑판 목록을 확인하십시오.

스테이지 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

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

3 단계

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

나는 asker가 실제로 #and +문자를 원한다고 생각합니다 . 그러나 와우, 여전히 인상적입니다. 나는 그것의 절반 정도를 이해했습니다. 그리고 그런 언어로 어떻게 프로그래밍합니까? 방금 복사 한 문자표와 그 의미가 있습니까?
Fabian Röling

@ FabianRöling OP는 두 문자가 허용된다고 말합니다. github.com/DennisMitchell/jelly 에 Jelly를위한 좋은 입문서가 있습니다. 파이썬을 안다면 소스도 읽을 수 있습니다. 튜토리얼과 원자 및 Quicks 목록을 사용하더라도 시간이 조금 걸리고 경우에 따라 소스를 참조하기도합니다.
Nick Kennedy


4

파이썬 (2) , 217 (215) 212 바이트

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

온라인으로 사용해보십시오!

0 색인, 사용 01문자


1
@LuisMendo는 2 바이트를 절약했습니다 : D
Rod


2

자바 스크립트 (ES7), 164 바이트

입력은 0 인덱스입니다. 로 행렬을 출력합니다.0대한 #1에 대한 +.

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))

온라인으로 사용해보십시오!


2

, 37 바이트

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

온라인으로 사용해보십시오! 링크는 자세한 버전의 코드입니다. 1- 색인. 출력은 아래로 증가하고 왼쪽으로 증가합니다 (아래로 및 오른쪽으로 추가 바이트가 필요하지만 동일한 바이트 수로 증가 할 수 있음). 설명:

FN«

고리 에스 타임스.

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

계산하다 케이+1. 이것은 때만 차이를 만듭니다=0 이 경우이 공식은 케이=1.

Fη«

고리 케이 새 행과 열마다 한 번씩

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

행과 열을 출력하여 항상 첫 번째 문자이지만 문자열 끝에 경계가 있는 방식으로 #and +문자 사이를 번갈아 가며 확인하십시오 #(대각선에서 바깥쪽으로 그리기 때문에). ⊞Oυω매번 각 행을 한 문자 씩 길게 만듭니다. 길이로.

다음 행을 위해 왼쪽 아래로 이동하십시오.


2

05AB1E , 43 42 바이트

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

@NickKennedy 의 Jelly 답변 에서 영감을 얻었 으며 마지막 부분 ζεðKζðδK€θ@Emigna 의 05AB1E 답변의 포트입니다 .

0대신 #1대신에 행렬을 반환합니다 +.

온라인으로 시도 하거나 첫 번째를 출력하여 온라인으로 시도하십시오[2,]결과 ( J,바닥 글 및 --no-lazy플래그는 결과 행렬을 예쁘게 인쇄합니다).

설명:

$                # 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

하스켈, 149146 바이트

(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

인덱스가 0이고 문자열 목록을 반환하며 위쪽과 왼쪽으로 커집니다.

온라인으로 사용해보십시오!

(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

펄 (6) , 156 (144) 155 154 바이트

nimi에서보고 한 버그를 수정하려면 +11

{$!=-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}...*)[$_]}

대략 Chas Brown의 Python 솔루션을 기반으로 합니다 . S를 인덱스없이 취합니다. 출력 01.

온라인으로 사용해보십시오!


결정된. 이제 모서리가 동일한 색상을 공유해야합니다.
bb94
당사 사이트를 사용함과 동시에 당사의 쿠키 정책개인정보 보호정책을 읽고 이해하였음을 인정하는 것으로 간주합니다.
Licensed under cc by-sa 3.0 with attribution required.