Please, merge my PowerShell examples for all chapters (#106)
* PowerShell 01_introduction_to_algorithms example * PowerShell 02_selection_sort example * PowerShell 03_recursion examples * PowerShell 04_quicksort examples * PowerShell 05_hash_tables examples * PowerShell 06_breadth-first_search example * PowerShell 07_dijkstras_algorithm example * PowerShell 08_greedy_algorithms example * Powershell 09_dynamic_programming example
This commit is contained in:
committed by
Aditya Bhargava
parent
d7de908a82
commit
06ee65d9e5
@@ -0,0 +1,32 @@
|
||||
$word_a = "fish"
|
||||
$word_b = "vista"
|
||||
|
||||
# Init the empty two-dimensional array
|
||||
$cell = @()
|
||||
for ($i = 0; $i -lt $word_a.Length; $i++)
|
||||
{
|
||||
$list = @()
|
||||
for ($j = 0; $j -lt $word_b.Length; $j++)
|
||||
{
|
||||
$list += , 0
|
||||
}
|
||||
$cell += , $list
|
||||
}
|
||||
|
||||
for ($i = 0; $i -lt $word_a.Length; $i++)
|
||||
{
|
||||
for ($j = 0; $j -lt $word_b.Length; $j++)
|
||||
{
|
||||
if ($word_a[$i] -eq $word_b[$j]) {
|
||||
# The letters match.
|
||||
$cell[$i][$j] = $cell[$i-1][$j-1] + 1
|
||||
}
|
||||
else
|
||||
{
|
||||
# The letters don't match.
|
||||
$cell[$i][$j] = 0
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
0..($cell.count-1) | ForEach-Object {Write-Host $cell[$_] -Separator `t}
|
||||
Reference in New Issue
Block a user