Finish a symmetrical map

Canvas, 5 4 bytes

║Q↷↷

First Canvas answer, so let's start with an easy one. :)

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

Windows PowerShell, 99 103 117 126 129

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.
+------+
|./..\.|
|/....\|
|\..../|
|.\../.|
+------+