태그 보관물: tiling

tiling

64 비트 ASCII 직조 길이를 지정하는

입력

두 정수 :

  • 직조를 지정하는 0에서 2 ^ 64-1 사이의 음이 아닌 정수 W.
  • 측면 길이를 지정하는 1-255 범위 의 양의 정수 S 입니다.

이것들은 당신에게 맞는 순서로 가져갈 수 있습니다.

산출

S 에 의해 S를 요청 직조 ASCII 표현 ( S의 개행는 문자열 분리 S를 선택적으로 후행 개행 문자). 직조는 직조 번호 W에 의해 다음과 같이 정의된다 :

W 를 이진수로 변환 하고 8 바이트로 나눕니다. 첫 번째 (가장 중요한) 바이트는 왼쪽 (가장 중요한 비트)에서 오른쪽으로 맨 위 행을 정의합니다. 다음 바이트는 다음 행을 정의하며 8 행에 대해서도 계속됩니다. 직조 번호는 8 x 8 정사각형을 정의하며 왼쪽 위에서 시작하여 필요한 영역에 타일을 붙여야합니다. 즉, 왼쪽 위 모서리는 덮을 영역의 왼쪽 위 모서리와 일치해야합니다.

모든 0것은 a로 표시 |되고 모든 1것은 a로 표시되어야합니다.-

입력: 0 8

출력 :

||||||||
||||||||
||||||||
||||||||
||||||||
||||||||
||||||||
||||||||

입력: 3703872701923249305 8

산출:

||--||--
|--||--|
--||--||
-||--||-
||--||--
|--||--|
--||--||
-||--||-

입력: 3732582711467756595 10

산출:

||--||--||
--||--||--
--||--||--
||--||--||
||--||--||
--||--||--
--||--||--
||--||--||
||--||--||
--||--||--

입력: 16141147355100479488 3

산출:

---
|||
---

리더 보드 스 니펫

( 마틴 템플릿 사용 )

var QUESTION_ID=54123;function answersUrl(e){return"http://api.stackexchange.com/2.2/questions/"+QUESTION_ID+"/answers?page="+e+"&pagesize=100&order=desc&sort=creation&site=codegolf&filter="+ANSWER_FILTER}function getAnswers(){jQuery.ajax({url:answersUrl(page++),method:"get",dataType:"jsonp",crossDomain:!0,success:function(e){answers.push.apply(answers,e.items),e.has_more?getAnswers():process()}})}function shouldHaveHeading(e){var a=!1,r=e.body_markdown.split("\n");try{a|=/^#/.test(e.body_markdown),a|=["-","="].indexOf(r[1][0])>-1,a&=LANGUAGE_REG.test(e.body_markdown)}catch(n){}return a}function shouldHaveScore(e){var a=!1;try{a|=SIZE_REG.test(e.body_markdown.split("\n")[0])}catch(r){}return a}function getAuthorName(e){return e.owner.display_name}function process(){answers=answers.filter(shouldHaveScore).filter(shouldHaveHeading),answers.sort(function(e,a){var r=+(e.body_markdown.split("\n")[0].match(SIZE_REG)||[1/0])[0],n=+(a.body_markdown.split("\n")[0].match(SIZE_REG)||[1/0])[0];return r-n});var e={},a=1,r=null,n=1;answers.forEach(function(s){var t=s.body_markdown.split("\n")[0],o=jQuery("#answer-template").html(),l=(t.match(NUMBER_REG)[0],(t.match(SIZE_REG)||[0])[0]),c=t.match(LANGUAGE_REG)[1],i=getAuthorName(s);l!=r&&(n=a),r=l,++a,o=o.replace("{{PLACE}}",n+".").replace("{{NAME}}",i).replace("{{LANGUAGE}}",c).replace("{{SIZE}}",l).replace("{{LINK}}",s.share_link),o=jQuery(o),jQuery("#answers").append(o),e[c]=e[c]||{lang:c,user:i,size:l,link:s.share_link}});var s=[];for(var t in e)e.hasOwnProperty(t)&&s.push(e[t]);s.sort(function(e,a){return e.lang>a.lang?1:e.lang<a.lang?-1:0});for(var o=0;o<s.length;++o){var l=jQuery("#language-template").html(),t=s[o];l=l.replace("{{LANGUAGE}}",t.lang).replace("{{NAME}}",t.user).replace("{{SIZE}}",t.size).replace("{{LINK}}",t.link),l=jQuery(l),jQuery("#languages").append(l)}}var ANSWER_FILTER="!t)IWYnsLAZle2tQ3KqrVveCRJfxcRLe",answers=[],page=1;getAnswers();var SIZE_REG=/\d+(?=[^\d&]*(?:&lt;(?:s&gt;[^&]*&lt;\/s&gt;|[^&]+&gt;)[^\d&]*)*$)/,NUMBER_REG=/\d+/,LANGUAGE_REG=/^#*\s*([^,]+)/;
body{text-align:left!important}#answer-list,#language-list{padding:10px;width:290px;float:left}table thead{font-weight:700}table td{padding:5px}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script><link rel="stylesheet" type="text/css" href="//cdn.sstatic.net/codegolf/all.css?v=83c949450c8b"><div id="answer-list"> <h2>Leaderboard</h2> <table class="answer-list"> <thead> <tr><td></td><td>Author</td><td>Language</td><td>Size</td></tr></thead> <tbody id="answers"> </tbody> </table></div><div id="language-list"> <h2>Winners by Language</h2> <table class="language-list"> <thead> <tr><td>Language</td><td>User</td><td>Score</td></tr></thead> <tbody id="languages"> </tbody> </table></div><table style="display: none"> <tbody id="answer-template"> <tr><td>{{PLACE}}</td><td>{{NAME}}</td><td>{{LANGUAGE}}</td><td>{{SIZE}}</td><td><a href="{{LINK}}">Link</a></td></tr></tbody></table><table style="display: none"> <tbody id="language-template"> <tr><td>{{LANGUAGE}}</td><td>{{NAME}}</td><td>{{SIZE}}</td><td><a href="{{LINK}}">Link</a></td></tr></tbody></table>


답변

K, 20

{y#y#'"|-"8 8#0b\:x}

.

             0b\:x    // convert to binary
         8 8#         // reshape into an 8x8 boolean matrix
     "|-"             // index into this char vector using the booleans as indices
  y#'                 // extend horizontally
y#                    // extend vertically

.

k){y#y#'"|-"8 8#0b\:x}[3703872701923249305j;10]
"||--||--||"
"|--||--||-"
"--||--||--"
"-||--||--|"
"||--||--||"
"|--||--||-"
"--||--||--"
"-||--||--|"
"||--||--||"
"|--||--||-"

k){y#y#'"|-"8 8#0b\:x}[3703872701923249305j;8]
"||--||--"
"|--||--|"
"--||--||"
"-||--||-"
"||--||--"
"|--||--|"
"--||--||"
"-||--||-"

답변

CJam, 33 31 바이트

q~:X;2b64Te["|-"f=8/{X*X<z}2*N*

여기에서 테스트하십시오.

설명

q~      e# Read and eval input.
:X;     e# Store the side length in X and discard it.
2b      e# Convert to base 2.
64Te[   e# Left-pad to length 64 with zeroes.
"|-"f=  e# Select '|' for 0 and '=' for 1.
8/      e# Split into chunks of 8 bits.
{       e# Do the following twice:
  X*    e#   Repeat lines X times (to ensure we have enough of them).
  X<    e#   Truncate them to exactly X lines.
  z     e#   Transpose the grid.
        e#   The transpose ensures that the second pass tiles the columns, and that the
        e#   grid is oriented correctly again after both passes are done.
}2*
N*      e# Join lines by newline characters.

답변

자바 110 109 107 바이트

내 코드는 소요 익명 람다 함수의 형태 long와는 int다음을 반환합니다 String.

(w,s)->{String b="";for(int j,i=s--;i-->0;b+='\n')for(j=s;j>=0;)b+=(w>>8*(i%8)+j--%8)%2<1?'|':45;return b;}

테스트 가능한 완전한 수업

import java.util.function.BiFunction;
public class AsciiWeave {   
    public static void main(String[] args){
        BiFunction<Long,Integer,String> weave = 
            (w,s)->{String b="";for(int j,i=s--;i-->0;b+='\n')for(j=s;j>=0;)b+=(w>>8*(i%8)+j--%8)%2<1?'|':45;return b;}}
        ;
        System.out.println(weave.apply(Long.valueOf(args[0]),Integer.valueOf(args[1])));
    }
}

답변

Matlab, 86 80 바이트

function f(W,S)
a='|-';x=de2bi(typecast(W,'uint8'))+1;s=8-mod(0:S-1,8);a(x(s,s))

그의 제안에 대해 Hoki에게 감사드립니다. 6 바이트를 절약 할 수있었습니다.

예:

>> W = uint64(3732582711467756595)
W =
  3732582711467756595
>> S = uint8(10)
S =
   10
>> f(W,S)
ans =
||--||--||
--||--||--
--||--||--
||--||--||
||--||--||
--||--||--
--||--||--
||--||--||
||--||--||
--||--||--

답변

줄리아, 145 바이트

f(w,s)=(A=map(i->i=="1"?"-":"|",reshape(split(lpad(bin(w),64,0),""),8,8))';for i=1:s A=hcat(A,A)end;for i=1:s println(join(A[i>8?i%8:i,1:s]))end)

두 정수를 받아들이고 stdout으로 인쇄하는 함수를 만듭니다.

언 골프 + 설명 :

function f(w,s)
    # Convert w to binary, left-padded with zeros to length 64
    b = lpad(bin(w), 64, 0)

    # Create an 8x8 array of | and -
    A = transpose(map(i -> i == "1" ? "-" : "|", reshape(split(b, ""), 8, 8)))

    # Horizontally concatenate A to itself s times
    for i = 1:s
        A = hcat(A, A)
    end

    # Print the rows of A, recycling as necessary
    for i = 1:s
        println(join(A[i > 8 ? i % 8 : i, 1:s]))
    end
end

이것은 꽤 길며 훨씬 짧아 질 수 있다고 확신합니다. 작업 중입니다.


답변

J, 28 바이트

'|-'{~]$"1]$8 8$_64{.#.inv@[

용법:

   3732582711467756595 ('|-'{~]$"1]$8 8$_64{.#.inv@[) 10
||--||--||
--||--||--
--||--||--
||--||--||
||--||--||
--||--||--
--||--||--
||--||--||
||--||--||
--||--||--

설명 (오른쪽에서 왼쪽) :

#.inv@[   binary representation vector of S
_64{.     padded with 0-s from the right to length 64
8 8$      reshaped in an 8 by 8 matrix
]$"1]$    tiled to a W by W size
'|-'{~    select | or - based on matrix element values

여기에서 온라인으로 사용해보십시오.


답변

CJam, 30 28 27 바이트

q~_2m*W%/ff{8f%8bm>"|-"=}N*

CJam 통역사 에서 온라인으로 사용해보십시오 .