powershell 汉洛塔
来源:互联网 发布:虚拟机运行mac os x慢 编辑:程序博客网 时间:2024/04/30 12:42
#powershell 汉洛塔#可变长数组Collections.ArrayList操作#递归函数#文字排版和配色function hanoi($n){$global:num=0$global:arraya=New-Object Collections.ArrayList$global:arrayb=New-Object Collections.ArrayList$global:arrayc=New-Object Collections.ArrayList$global:arraya.addrange(1..$n)Write-Host $("初始状态:").PadLeft(13) -NoNewlineWrite-Host ($global:arraya -join ",").PadRight(9) -NoNewlineWrite-Host ($global:arrayb -join ",").PadRight(9) -NoNewlineWrite-Host ($global:arrayc -join ",").PadRight(9)function go($n,$a,$b,$c){ if($n -eq 1) { $global:num++ if($a -eq "a" -and $c -eq "b"){$s1="a";$a1="--> ";$s2="b ";$a2="";$s3="" $global:arrayb.Insert(0,$global:arraya[0]) $global:arraya.Removeat(0) } if($a -eq "a" -and $c -eq "c"){$s1="a";$a1="";$s2="---->";$a2="";$s3="c" $global:arrayc.Insert(0,$global:arraya[0]) $global:arraya.Removeat(0) } if($a -eq "b" -and $c -eq "a"){$s1="a";$a1="<-- ";$s2="b ";$a2="";$s3="" $global:arraya.Insert(0,$global:arrayb[0]) $global:arrayb.Removeat(0) } if($a -eq "b" -and $c -eq "c"){$s1=" ";$a1="";$s2="b ";$a2="-->";$s3="c" $global:arrayc.Insert(0,$global:arrayb[0]) $global:arrayb.Removeat(0) } if($a -eq "c" -and $c -eq "a"){$s1="a";$a1="";$s2="<----";$a2="";$s3="c" $global:arraya.Insert(0,$global:arrayc[0]) $global:arrayc.Removeat(0) } if($a -eq "c" -and $c -eq "b"){$s1=" ";$a1="";$s2="b ";$a2="<--";$s3="c" $global:arrayb.Insert(0,$global:arrayc[0]) $global:arrayc.Removeat(0) } Write-Host $("第$num`步:").PadLeft(15) -NoNewline Write-Host "$($s1)" -ForegroundColor 3 -NoNewline -BackgroundColor 15 Write-Host "$($a1.PadLeft(17))" -ForegroundColor 1 -NoNewline -BackgroundColor 15 Write-Host "$($s2.PadRight(12))" -ForegroundColor 9 -NoNewline -BackgroundColor 15 Write-Host "$($a2.PadLeft(6))" -ForegroundColor 1 -NoNewline -BackgroundColor 15 Write-Host "$($s3.PadLeft(12))" -ForegroundColor 12 -BackgroundColor 15 Write-Host $("当前状态:").PadLeft(13) -NoNewline Write-Host ($global:arraya -join ",").PadRight(18) -NoNewline Write-Host ($global:arrayb -join ",").PadRight(12) -NoNewline Write-Host ($global:arrayc -join ",").PadLeft(18) } else { go ($n-1) $a $c $b go 1 $a $b $c go ($n-1) $b $a $c } }go $n "a" "b" "c"}hanoi 4
0 0
- powershell 汉洛塔
- PowerShell
- PowerShell
- PowerShell
- PowerShell
- PowerShell
- PowerShell
- PowerShell
- powershell
- Powershell
- PowerShell
- Powershell
- powershell
- PowerShell
- powershell
- powershell
- powershell
- PowerShell:雙引號與單引號
- H5 缓存机制浅析 移动端 Web 加载性能优化
- FFmpeg命令及基础
- IOS加载Gif图片的N种方式 By-H罗
- dispatch_barrier_async 隐藏的坑
- 读Android群英传第五章
- powershell 汉洛塔
- 曾经的自己 现在的我
- android轮询最佳实践service+AlarmManager+Thread
- IntelliJ IDEA 常用插件收集
- cocos2dx 中 ProgressTimer的使用
- 利用 SGA 共享池,避开 parse 阶段
- Map遍历的几种方法
- 如何使用ueditor
- 将日期控件绑定指定的EditText中,自然显示给定的时间