x 축과 y 축에 대해 입력으로 대칭 인 맵의 1/4이 제공됩니다. 프로그램은 완전한지도를 인쇄해야합니다.
지도는 다음 문자를 포함 할 수 있으며 -+/\|.예상대로 회전해야합니다. 입력 데이터는 항상 직사각형이며 작습니다.
예
$ cat in
+---
|./.
|/..
$ ./solution < in
+------+
|./..\.|
|/....\|
|\..../|
|.\../.|
+------+
가장 짧은 코드가 승리합니다.
x 축과 y 축에 대해 입력으로 대칭 인 맵의 1/4이 제공됩니다. 프로그램은 완전한지도를 인쇄해야합니다.
지도는 다음 문자를 포함 할 수 있으며 -+/\|.예상대로 회전해야합니다. 입력 데이터는 항상 직사각형이며 작습니다.
$ cat in
+---
|./.
|/..
$ ./solution < in
+------+
|./..\.|
|/....\|
|\..../|
|.\../.|
+------+
가장 짧은 코드가 승리합니다.
답변:
║Q↷↷
첫 번째 Canvas 답변이므로 쉬운 것으로 시작합시다. :)
@dzaima 덕분에 -1 바이트 .
캔버스에서 슬래시는 미러링 또는 회전 할 때 자동으로 변환됩니다.
1 바이트 수 있었다 ╬( 온라인 체험 ),하지만 불행히도 그것은 또한 점 변환 .따옴표로를 '수평으로 미러링 할 때.
설명:
# (Take the multi-line input implicitly as canvas object)
║ # Palindromize the canvas object (without overlap)
Q # Output it with a trailing newline (without popping)
↷↷ # Rotated the canvas object that's still on the stack by 90 degrees twice
# (and output it implicitly as well at the end)
filter x{$_-split'/'-replace'\\','/'-join'\'}$input|%{$_+-join($_[40..0]|x)}|%{$_
$s=,($_|x)+$s}
$s
노트:
테스트:
> gc in| .\map.ps1
+------+
|./..\.|
|/....\|
|\..../|
|.\../.|
+------+
> gc in2
+\/
/\/
> gc in2| .\map.ps1
+\/\/+
/\/\/\
\/\/\/
+/\/\+
역사
OFS를 저장하고 변수에 -join저장 99..0합니다.-replace나는 세 가지 필요가 없습니다, 배열에 대해 작동 -replace들하지만, 작업을 수행 할 수 있습니다 -split, -replace, -join대신.$a더 이상 필요하지 않습니다 99..0.filter정의 후에 공백이 필요하지 않습니다 . $x배열에서 첫 번째 실행 중에 모든 행을 제거 하고 대신 수집 한 후 두 번째 절반에 대해 출력합니다.S‖M⌈
@Neil 덕분에 -1 바이트 .
차콜은 슬래시를 올바르게 반영하여 자동으로 처리합니다.
온라인 (자세한 내용) 또는 온라인으로 시도 (순수) 하세요
설명:
입력을 문자열로 가져옵니다.
InputString()
S
오른쪽과 아래쪽으로 거울을 반사하십시오 ( :⌈내장 :Right, :Down).
ReflectMirror(:⌈)
‖M⌈
⌈단일 바이트에서 오른쪽 아래로 제공하는 것을 포함하여 더 많은 다 방향을 추가 했습니다.
⌈Verbose 코드에서 어떻게 사용 합니까? :RightDown물론 우리가 원하는 결과는 아닙니다.
:은 Verbose 모드에서 접두사를 사용합니다.
:Right:Down, 또는 ::RightDown다른 것? 그러나이 두 결과 중 어느 것도 인수로 ⌈인코딩 된 버전을 제공하지 않습니다 -vl. arg를 S‖M⌈사용할 때 자세한 코드는 무엇을 가져야 -vl합니까?
ReflectMirror(:⌈)
쉘 스크립팅 !!
#!/bin/sh
rm temp
touch temp
file=$1
for STRING in `cat $1`
do
printf $STRING >> temp
for ((COUNT=0; COUNT<${#STRING}; COUNT++))
do
RECORD[$COUNT]=${STRING:$COUNT:1}
done
for ((REV_COUNT=${#STRING}; REV_COUNT>=0; REV_COUNT--))
do
if [ "${RECORD[$REV_COUNT]}" = "\\" ]; then
printf "/" >> temp
elif [ "${RECORD[$REV_COUNT]}" = "/" ]; then
printf "\\" >> temp
else
printf "${RECORD[$REV_COUNT]}" >> temp
fi
done
echo >> temp
done
cat temp
tac temp > temp2
for STRING in `cat temp2`
do
for ((COUNT=0; COUNT<${#STRING}; COUNT++))
do
RECORD[$COUNT]=${STRING:$COUNT:1}
if [ "${RECORD[$COUNT]}" = "\\" ]; then
printf "/"
elif [ "${RECORD[$COUNT]}" = "/" ]; then
printf "\\"
else
printf "${RECORD[$COUNT]}"
fi
done
echo
done
I / O
./solution in
+------+
|./..\.|
|/....\|
|\..../|
|.\../.|
+------+
CJam 은이 도전보다 최신 이므로이 답변은 녹색 확인 표시를 사용할 수 없지만 어쨌든 재미있는 운동이었습니다.
qN/{{_W%"\/"_W%er+}%z}2*N*
qN/{{_W%"\/"_W%er+}%z}2*N*
qN/ "Read STDIN and split on newlines.";
{ }2* "Execute this block twice.";
{ }% "Map this block onto each line.";
_W% "Duplicate and reverse.";
"\/" "Push the string '\/'.";
_W% "Duplicate and reverse.";
er "Character transliteration, swaps slashes and backslashes.";
+ "Append to first half of the line.";
z "Zip, i.e. transpose the map.";
N* "Join with newlines.";
끝에서 조옮김은 두 번째 뒤집기가 열을 따라 수행되도록한다. 마지막에 맵을 다시 조옮김으로써 원래 방향으로 끝납니다.
Joey의 답변에서 영감을 얻었습니다 .
filter x{$_;$_[40..0]|%{$_-split'/'-replace'\\','/'-join'\'}},($args|%{-join(,($_|% t*y)|x)})|x
참고 : 40작성자가 주석을 게시하기 때문 Let's say the input is at most 16 rows and 40 characters입니다.
테스트 스크립트 :
$f = {
filter x{$_;$_[40..0]|%{$_-split'/'-replace'\\','/'-join'\'}}
,($args|%{-join(,($_|% t*y)|x)})|x
}
@(
,( ("+---",
"|./.",
"|/.."),
"+------+",
"|./..\.|",
"|/....\|",
"|\..../|",
"|.\../.|",
"+------+")
,( ("+\/",
"/\/"),
"+\/\/+",
"/\/\/\",
"\/\/\/",
"+/\/\+")
,( ("+---",
"|...",
"|..\"),
"+------+",
"|......|",
"|..\/..|",
"|../\..|",
"|......|",
"+------+")
) | % {
$m,$expected = $_
$result = &$f @m
"$result"-eq"$expected"
$result
}
산출:
True
+------+
|./..\.|
|/....\|
|\..../|
|.\../.|
+------+
True
+\/\/+
/\/\/\
\/\/\/
+/\/\+
True
+------+
|......|
|..\/..|
|../\..|
|......|
+------+
n%{.-1%'/'/{'\\'/'/'*}%'\\'*+}%.-1%{-1%}%+n*
결과
$ cat in2
+-/|/\
/\|//-
$ cat in2 | golfscript codegolf-761.gs
+-/|/\/\|\-+
/\|//--\\|/\
\/|\\--//|\/
+-\|\/\/|/-+
n%{.-1%'/'/'\\'*+}%.-1%{-1%}%+n*
결과
$ cat in
+---
|./.
|/..
$ cat in | golfscript codegolf-761.gs
+------+
|./..\.|
|/....\|
|\..../|
|.\../.|
+------+
$
c '/'='\\';c '\\'='/';c x=x;i=(c<$>)
q#x=x++q(reverse x)
f=((i<$>)#).map(i#)
-- Only / and \ get converted, all other chars are passed as is
c '/'='\\';c '\\'='/';c x=x
-- "Invert" the string (that is switch all / and \ in it)
-- Just map our conversion function over the string
i = (c<$>)
-- Helper: Concatenate a list with its reversed copy (with the given function applied to the copy)
q # x = x ++ q (reverse x)
-- the resulting function:
f = ((i<$>)#) . -- produce the lower half of the image by reversing the upper half and inverting slashes in each line
map (i#) -- produce the upper half or the image (by concating each input line with its reversed, inverted version)
입력 :
선언 @s VARCHAR (100) = '+ ---'+ CHAR (10) + '| ...'+ CHAR (10) + '| .. \';
압축 :
@t TABLE (l INT IDENTITY (1,1), s CHAR (40)) 선언; @t (s)에 삽입 SELECT 값 + TRANSLATE (REVERSE (값), '\ /', '/ \') FROM STRING_SPLIT (@ s, char (10)); SELECT s FROM (SELECT l, s from @t UNION ALL SELECT 1e3-l, TRANSLATE (s, '\ /', '/ \') FROM @t) b ORDER BY l
인간이 읽을 수있는 :
@t TABLE (l INT IDENTITY (1,1), s CHAR (40)) 선언; @t에 삽입 값 선택 + 번역 (REVERSE (값), '\ /', '/ \') FROM STRING_SPLIT (@ s, char (10)); 선택 에서( @ l에서 s 선택 UNION ALL @t에서 1e3-l, 번역 (s, '\ /', '/ \') 선택 )비 내가 주문
출력 (ex. management studio에서 텍스트로) :
+ ------ + | ...... | | .. \ / .. | | ../ \ .. | | ...... | + ------ + (6 행 영향)