Skip to content

Instantly share code, notes, and snippets.

@JFFail
Created January 30, 2015 16:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JFFail/48e7961082636c6747d5 to your computer and use it in GitHub Desktop.
Save JFFail/48e7961082636c6747d5 to your computer and use it in GitHub Desktop.
Solution To Reddit Daily Programmer 199 - Bank Number Banners Part 2
<#
# Reddit Daily Programmer 199 Part 2
# http://www.reddit.com/r/dailyprogrammer/comments/2u0fyx/2015126_challenge_199_bank_number_banners_pt_2/
#>
#Create the strings for the inputs.
$inputTop = " _ _ _ _ _ _ _ "
$inputMid = "|_| |_| | | |_| |_ | | | |_ "
$inputBot = " | _| |_| |_| |_| | | | _|"
#Hash table of possible solutions.
$solutionHash = @{0=" _ ","| |","|_|";1=" "," |"," |";2=" _ "," _|","|_ ";3=" _ "," _|"," _|";4=" ","|_|"," |";5=" _ ","|_ "," _|";6=" _ ","|_ ","|_|";7=" _ "," |"," |";8=" _ ","|_|","|_|";9=" _ ","|_|"," _|"}
#We know there are always 9 numbers. Start to parse them.
for($i = 0; $i -lt 9; $i++)
{
#Make an empty array and string to temporarily store parsed values.
$tempArray = @()
$currentLine = ""
#Added logic since the start-end index will be different after the first number due to spaces between them.
if($i -gt 0)
{
#Start at a different location!
$index = ($i*3)+$i
}
else
{
#Start at the beginning.
$index = $i
}
#Parse the first line and write it to the array.
$currentLine = $inputTop[$index]
$currentLine += $inputTop[$index+1]
$currentLine += $inputTop[$index+2]
$tempArray += $currentLine
#Parse the second line and add it to the array.
$currentLine = $inputMid[$index]
$currentLine += $inputMid[$index+1]
$currentLine += $inputMid[$index+2]
$tempArray += $currentLine
#Parse the third line and add it to the array.
$currentLine = $inputBot[$index]
$currentLine += $inputBot[$index+1]
$currentLine += $inputBot[$index+2]
$tempArray += $currentLine
#Compare the current array to the hash table.
foreach($solution in $solutionHash.GetEnumerator())
{
#Since the value and the tempArray are different types, compare their indexes! Each will be 3 in length.
if($solution.Value[0] -eq $tempArray[0] -and $solution.Value[1] -eq $tempArray[1] -and $solution.Value[2] -eq $tempArray[2])
{
Write-Host $solution.Key -NoNewLine
}
}
}
#Final newline.
Write-Host ""
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment