# Finish a symmetrical map

You are given one-quarter of a map that is symmetrical over the x- and y-axes as input. The program should print the complete map.

The map can contain the following characters: -+/\|., and they should be turned as expected. The in data is always rectangular and small.

## Example

$cat in +--- |./. |/..$ ./solution < in
+------+
|./..\.|
|/....\|
|\..../|
|.\../.|
+------+


Shortest code wins.

• What exactly does small mean for the input data? That's a bit vague to quantify.
– Joey
Feb 9 '11 at 10:05
• @Joey Let's say the input is at most 16 rows and 40 characters.
– user475
Feb 9 '11 at 10:17
• I realised that I put no time limit, but if someone needs more than a second for his solution, I'd really like to see it.
– user475
Feb 9 '11 at 10:18

# Canvas, 5 4 bytes

║Ｑ↷↷


-1 byte thanks to @dzaima.

The slashes are automatically converted when mirroring or rotating in Canvas.
Could have been 1 byte ╬ (Try it online), but unfortunately it also transforms the dots . to single quotes ' when mirroring horizontally.

Try it online.

Explanation:

         # (Take the multi-line input implicitly as canvas object)
║        # Palindromize the canvas object (without overlap)
Ｑ      # 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)


## Windows PowerShell, 99 103117126129

filter x{$_-split'/'-replace'\\','/'-join'\'}$input|%{$_+-join($_[40..0]|x)}|%{$_$s=,($_|x)+$s}
$s  Notes: • This unfortunately needs two things that PowerShell is notoriously bad at while golfing: Reversing a string (or sequence of values) and transliterating stuff in a string. I'm fairly sure that this is at least twice as long as a Perl of Ruby solution. Test: > gc in| .\map.ps1 +------+ |./..\.| |/....\| |\..../| |.\../.| +------+ > gc in2 +\/ /\/ > gc in2| .\map.ps1 +\/\/+ /\/\/\ \/\/\/ +/\/\+  History • 2011-02-09 11:10 (129) – First attempt. • 2011-02-09 11:27 (126) – OFS to save the -join and stored 99..0 in a variable. • 2011-02-09 11:31 (117) – -replace works against arrays, so I don't need three -replaces but can do a -split, -replace, -join instead. • 2011-02-09 15:03 (105) – Instead of doing the same thing twice, do it once and reverse it. And putting an assignment into parentheses causes it to spit out its value to the pipeline :-) • 2011-02-09 15:08 (103) – I don't need $a anymore since 99..0 isn't used that often by now.
• 2011-02-09 15:17   (99) – There doesn't need to be whitespace after the filter definition. Removed $x and instead collecting every line during the first run in an array and then outputting that for the second half. # Ruby - 88 87 chars t=->s{s.tr'/\\\\','\\\\/'} puts a=$<.map{|l|l.chop!+t[l.reverse]}
puts a.reverse.map &t


## Test Run

D:\tmp>ruby cg_sym_map.rb < sym_map.in.
+------+
|./..\.|
|/....\|
|\..../|
|.\../.|
+------+

• Nice, I like the puts-assignment.
– user475
Feb 9 '11 at 14:40
• Ah, there's my demise ;-) I knew it would come eventually
– Joey
Feb 9 '11 at 15:53

# APL (Dyalog Classic), 25232221 19 bytes

(⌽⍪⊖){⊃3⌽⍵∪'/\'}¨,⌽


Try it online!

# Charcoal, 5 4 bytes

Ｓ‖Ｍ⌈


-1 byte thanks to @Neil.

Charcoal automatically handles reflecting the slashes correctly.

Explanation:

Take the input as a string:

InputString()
Ｓ


Reflect mirror it both towards the right and downwards (:⌈ is a builtin for :Right, :Down):

ReflectMirror(:⌈)
‖Ｍ⌈

• @ASCII-only has since added some more multidirectionals including ⌈ which gives you right and down in a single byte.
– Neil
Jan 27 '19 at 11:52
• @Neil How do you use ⌈ in the Verbose code? :RightDown will of course not be the result we'd want. Jan 27 '19 at 12:04
• Multidirectionals just take a : prefix in Verbose mode.
– Neil
Jan 27 '19 at 12:16
• @Neil So :Right:Down, or ::RightDown, or something else? Neither of these two results will give a ⌈ in the encoded version with the -vl argument, though. What would the verbose code have to become to get Ｓ‖Ｍ⌈ when using the -vl arg? Jan 27 '19 at 16:28
• ReflectMirror(:⌈)
– Neil
Jan 27 '19 at 17:10

## Golfscript - 32 chars

n%{{.-1%{.3%2=115*^}%+}%zip}2*n*


Due to the symmetry of the problem, we repeat twice {flip horizontally, transpose (zip)}. As a bonus, you can change the value 2 to a larger number to repeat the image more.

Character transposition is done as x^=155 if x%3==2, due to the restricted character space. There's also {.5^3%(45+} at the same length.

## Perl, 80 chars

print reverse map{s@.*@($b=$&)=~y:/\\:\\/:,$&.reverse$b@e;print;y@/\\@\\/@;$_}<>  Shell Scripting!! #!/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, 26 bytes CJam is newer than this challenge, so this answer is not eligible for the green checkmark, but it was a fun exercise anyway qN/{{_W%"\/"_W%er+}%z}2*N*  Test it here. ## Explanation 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.";  The transposing at the end leads the the second flipping to be performed along the columns. At the end we transpose the map again, so we end up with the original orientation. # Powershell, 95 bytes Inspired by Joey's answer. filter x{$_;$_[40..0]|%{$_-split'/'-replace'\\','/'-join'\'}},($args|%{-join(,($_|% t*y)|x)})|x


Note: 40 because the author posts the comment Let's say the input is at most 16 rows and 40 characters.

Test script:

$f = { filter x{$_;$_[40..0]|%{$_-split'/'-replace'\\','/'-join'\'}}
,($args|%{-join(,($_|% t*y)|x)})|x

}

@(
,( ("+---",
"|./.",
"|/.."),
"+------+",
"|./..\.|",
"|/....\|",
"|\..../|",
"|.\../.|",
"+------+")
,( ("+\/",
"/\/"),
"+\/\/+",
"/\/\/\",
"\/\/\/",
"+/\/\+")
,( ("+---",
"|...",
"|..\"),
"+------+",
"|......|",
"|..\/..|",
"|../\..|",
"|......|",
"+------+")
) | % {
$m,$expected = $_$result = &$f @m "$result"-eq"$expected"$result
}


Output:

True
+------+
|./..\.|
|/....\|
|\..../|
|.\../.|
+------+
True
+\/\/+
/\/\/\
\/\/\/
+/\/\+
True
+------+
|......|
|..\/..|
|../\..|
|......|
+------+


# Ruby - 105

t=->s{s.tr '/\\\\','\\\\/'}
$<.read.split.map{|l|print l+=t[l.reverse]+" " l}.reverse.map{|l|print t[l]}  ## Golfscript - 44 chars n%{.-1%'/'/{'\\'/'/'*}%'\\'*+}%.-1%{-1%}%+n*  result $ cat in2
+-/|/\
/\|//-
$cat in2 | golfscript codegolf-761.gs +-/|/\/\|\-+ /\|//--\\|/\ \/|\\--//|\/ +-\|\/\/|/-+  ### Another script that only work for example and does not flip for '\' - 32 chars n%{.-1%'/'/'\\'*+}%.-1%{-1%}%+n*  result $ cat in
+---
|./.
|/..
$cat in | golfscript codegolf-761.gs +------+ |./..\.| |/....\| |\..../| |.\../.| +------+$

• \ needs to be flipped as well.
– Nabb
Feb 9 '11 at 12:51
• @Nabb, thanks, that made my code huge :P
– YOU
Feb 9 '11 at 13:12
• Mark: Use variables for repeated strings if it makes it shorter. Although there are a few other tricks that you can try to figure out before I post my answer later.
– Nabb
Feb 9 '11 at 13:22
• @Nabb, Thanks, I will try to figure out and let me have 30 minutes :D
– YOU
Feb 9 '11 at 13:26
• @Nabb, I still couldn't figure out, you may post yours.
– YOU
Feb 9 '11 at 13:55

c '/'='\\';c '\\'='/';c x=x;i=(c<$>) q#x=x++q(reverse x) f=((i<$>)#).map(i#)


Try it online!

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


# MS-SQL 2017, 243 bytes

input:

DECLARE @s VARCHAR(100) ='+---'+CHAR(10)+'|...'+CHAR(10)+'|..\';


compressed:

declare @t TABLE(l INT IDENTITY(1,1),s CHAR(40));INSERT INTO @t(s)SELECT value+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


declare @t TABLE(l INT IDENTITY(1,1),s CHAR(40));
INSERT INTO @t(s)
SELECT value+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


output (as text in ex.management studio):

+------+
|......|
|..\/..|
|../\..|
|......|
+------+

(6 rows affected)