計算開關數量
Round Up the Switches
這個關卡要我們先收集在第一個平台上的寶石,然後再到第二個平台上去打開相同數量的開關。
// 變數初始化
var gems = 0
var switches = 0
// 策略:如果
// 1. 還沒收到寶石,或者是
// 2. 有收到寶石但開關數量比寶石少,
// 就繼續走
while gems == 0 || (gems > 0 && switches < gems) {
walkAlongLeft {
if isOnGem {
collectGem()
gems += 1
}
if isOnClosedSwitch {
toggleSwitch()
switches += 1
}
}
}
Last updated
Was this helpful?