Skip to content

Latest commit

 

History

History
52 lines (44 loc) · 1.25 KB

File metadata and controls

52 lines (44 loc) · 1.25 KB
pid 1028
author Joel Bennett
title The Letter Diamond
date 2009-04-15 00:39:33 -0700
format posh
parent 0

The Letter Diamond

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

Example: LetterDiamond.ps1 K

## 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")
$start = [int][char]"B"
$end = [int]$letter

$outerpadding = ($end - $start) + 5
$innerpadding = -1
Write-Host "$(" " * $outerpadding)A"
foreach($char in ([string[]][char[]]($start..$end))) { 
   $innerpadding += 2
   $outerpadding--
   Write-Host "$(" " * $outerpadding)$char$(" " * $innerpadding)$char"
}
$end--
foreach($char in ([string[]][char[]]($end..$start))) { 
   $innerpadding -= 2
   $outerpadding++
   Write-Host "$(" " * $outerpadding)$char$(" " * $innerpadding)$char"
}
Write-Host "$(" " * $outerpadding) A"