Skip to content

Latest commit

 

History

History
48 lines (39 loc) · 1.13 KB

File metadata and controls

48 lines (39 loc) · 1.13 KB
pid 1029
author Joel Bennett
title The Letter Diamond
date 2009-04-15 00:55:58 -0700
format posh
parent 1028

The Letter Diamond

@CAMurphy A slightly more elegant PowerShell version for "his challenge":http://www.craigmurphy.com/blog/?p=1417

## Write a program which draws a diamond of the form illustrted 
## below. The letter which is to appear at the widest point of the 
## figure (E in the example) is to be specified as the input data.
##           A
##          B B
##         C   C
##        D     D
##       E       E
##        D     D
##         C   C
##          B B
##           A
Param([char]$letter = "E", [int]$padding=5)
$start = [int][char]"B"
$end = [int]$letter

$outerpadding = ($end - $start) + $padding
$innerpadding = -1

$lines = &{ 
   "$(" " * $outerpadding)A"
   foreach($char in ([string[]][char[]]($start..$end))) { 
      $innerpadding += 2; $outerpadding--
      "$(" " * $outerpadding)$char$(" " * $innerpadding)$char"
   }
}

$lines
$lines[$($lines.Length-2)..0]