Answers:
║Q↷↷
首先是Canvas的答案,所以让我们从一个简单的答案开始。:)
-1个字节感谢@dzaima。
在Canvas中镜像或旋转时,斜线会自动转换。
可以是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⌈
-1个字节感谢@Neil。
木炭会自动处理正确的斜线。
说明:
将输入作为字符串:
InputString()
S
向右和向下反射(这:⌈
是的内置功能:Right, :Down
):
ReflectMirror(:⌈)
‖M⌈
⌈
在单个字节中向右和向下的功能。
⌈
在详细代码中使用?:RightDown
当然不会是我们想要的结果。
:
在详细模式下带有前缀。
:Right:Down
,还是::RightDown
,还是其他?不过,这两个结果都不会⌈
在带有-vl
参数的编码版本中给出a 。S‖M⌈
使用-vl
arg 时,必须得到什么冗长的代码?
ReflectMirror(:⌈)
Shell脚本!!
#!/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
输入输出
./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.";
末端的移置导致第二次翻转沿列进行。最后,我们再次对地图进行转置,因此我们以原始方向结束。
受到乔伊的答案的启发。
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
+------+
|......|
|..\/..|
|../\..|
|......|
+------+
t=->s{s.tr '/\\\\','\\\\/'}
$<.read.split.map{|l|print l+=t[l.reverse]+"
"
l}.reverse.map{|l|print t[l]}
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)
输入:
DECLARE @s VARCHAR(100)='+ ---'+ CHAR(10)+'| ...'+ CHAR(10)+'| .. \';
压缩:
声明@t TABLE(l INT IDENTITY(1,1),s CHAR(40));插入@t(s)SELECT值+ TRANSLATE(REVERSE(value),'\ /','/ \')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(s) 选择值+ TRANSLATE(REVERSE(值),'\ /','/ \') 从STRING_SPLIT(@ s,char(10)); 选择 从( 从@t选择l,s 全联盟 SELECT 1e3-l,TRANSLATE(s,'\ /','/ \')FROM @t )b 按l订购
输出(如ex.management studio中的文本):
+ ------ + | ...... | | .. \ / .. | | ../ \ .. | | ...... | + ------ + (受影响的6行)