I would personally just use arrays for this. Each index of the array can represent the number:

# For simplicity, I only created 0,1,2,3 indices.
# Each index number matches the graphical number it stores.
$Numbers = @("  #####   "," ##   ##  ","##     ## ","##     ## ","##     ## "," ##   ##  ","  #####   "),
           @("####   ","  ##   ","  ##   ","  ##   ","  ##   ","  ##   ","###### "),
           @(" #######  ","##     ## ","       ## "," #######  ","##        ","##        ","######### "),
           @(" #######  ","##     ## ","       ## "," #######  ","       ## ","##     ## "," #######  ")

$IDNumbers = '20012'
$IDNumbers.ToCharArray() | Foreach-Object { $Numbers["$_"] }

# Output
 #######
##     ##
       ##
 #######
##
##
#########
  #####
 ##   ##
##     ##
##     ##
##     ##
 ##   ##
  #####
  #####
 ##   ##
##     ##
##     ##
##     ##
 ##   ##
  #####
####
  ##
  ##
  ##
  ##
  ##
######
 #######
##     ##
       ##
 #######
##
##
#########

Explanation:

$Numbers is an array where its indexes each contain an array that represents a numerical graphic. So $Numbers['0'] contains array elements that make up the 0 graphic, $Numbers['1'] contains array elements that make up the 1 graphic, etc. Now you only need to retrieve the index of $Numbers that contains your target graphic.

If visual representation within the shell matters to you, you can still maintain that:

$Numbers = @(
"  #####   ",
" ##   ##  ",
"##     ## ",
"##     ## ",
"##     ## ",
" ##   ##  ",
"  #####   "
),
@(
"####   ",
"  ##   ",
"  ##   ",
"  ##   ",
"  ##   ",
"  ##   ",
"###### "
),
@(
" #######  ",
"##     ## ",
"       ## ",
" #######  ",
"##        ",
"##        ",
"######### "
),
@(
" #######  ",
"##     ## ",
"       ## ",
" #######  ",
"       ## ",
"##     ## ",
" #######  "
)

You can build on this approach for horizontal display:

$Numbers = @("  #####   "," ##   ##  ","##     ## ","##     ## ","##     ## "," ##   ##  ","  #####   "),
           @("####   ","  ##   ","  ##   ","  ##   ","  ##   ","  ##   ","###### "),
           @(" #######  ","##     ## ","       ## "," #######  ","##        ","##        ","######### "),
           @(" #######  ","##     ## ","       ## "," #######  ","       ## ","##     ## "," #######  ")

$IDNumbers = '20012'
for ($i = 0; $i -lt 7; $i++) {
    ($IDNumbers.ToCharArray() | Foreach-Object { $Numbers["$_"][$i] }) -join "`t"
}

You can simply just change the joining characters (tab here) to any one or group of characters. Since each graphic has 7 parts, you can loop through each part (indices 0-6). Since we created each part as an element of the array, you have an array of nested arrays. So graphic 0 part 1 would be $Numbers['0'][0], graphic 3 part 4 would be $Numbers['3'][3].


Edit: Working with Letters and Numbers

You can use a hash table instead of an array to hold your graphics. Then you can access each graphic array by the hash table key.

$hash = [ordered]@{}
$hash['A'] = @('      ####      ','     ##  ##     ','    ##    ##    ','   ##########   ','  ##        ##  ',' ##          ## ','##            ##')
$hash['0'] = @("  #####   "," ##   ##  ","##     ## ","##     ## ","##     ## "," ##   ##  ","  #####   ")
$hash['1'] = @("####   ","  ##   ","  ##   ","  ##   ","  ##   ","  ##   ","###### ")
$hash['2'] = @(" #######  ","##     ## ","       ## "," #######  ","##        ","##        ","######### ")
$hash['3'] = @(" #######  ","##     ## ","       ## "," #######  ","       ## ","##     ## "," #######  ")

$IDNumbers = 'A23012'
for ($i = 0; $i -lt 7; $i++) {
    ($IDNumbers.ToCharArray() | Foreach-Object { $hash["$_"][$i] }) -join "`t"
}

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top