PoshCode Archive  Artifact [1ca161c97e]

Artifact 1ca161c97ed5e9036d03bdd0faa8b7bc7aec5b816059424f35cb2b8e7f89771b:

  • File The-Letter-Diamond.ps1 — part of check-in [78ea938e2b] at 2018-06-10 12:56:17 on branch trunk — @CAMurphy A slightly more elegant PowerShell version for his challenge (user: Joel Bennett size: 1120)

# encoding: ascii
# api: powershell
# title: The Letter Diamond
# description: @CAMurphy A slightly more elegant PowerShell version for his challenge
# version: 0.1
# author: Joel Bennett
# license: CC0
# x-poshcode-id: 1029
# x-derived-from-id: 1032
# x-archived: 2017-04-10T19:09:45
# x-published: 2010-04-15T07:55:00
#
#
## 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]