
Re: Script Challenge - Amtrak
I'm confident that an 11 or 14 line amtrak will be useless outside of this exercise, yes. But the exercise itself is far from useless. I've already learned new insights into TWX scripting... and frankly, I'm surprised. Let me list a few of these.
I think Sing's example of recursion is incredible. His example moves down a target list, $targets, appending to it as it goes. As originally posted, it would mistakenly grid the whole universe, oops, but a brilliant solution. He said, "Just create a list of sectors to grid, then grid them." I said, "That's 2 while loops, too many lines." He said, "I think I can do it in less."
I just realized during this challenge that write, and readToArray can be used to create an array very effectively. Promethius posted an example using this technique.
I've learned that the command 'branch' can be useful for combining nested while loops, possibly. For example, if you have this while structure:
Code:
setVar $a 1
while ($a <= 10)
setVar $b 1
while ($b <= 5)
setVar $c 1
while ($c <= 2)
echo $a "." $b "." $c "*"
add $c 1
end
add $b 1
end
add $a 1
end
You can write it with this functionally equivalent code:
Code:
setVar $a 1
setVar $b 1
setVar $c 1
:loop
echo $a "." $b "." $c "*"
add $c 1
branch ($c > 2) :loop
setVar $c 1
add $b 1
branch ($b > 5) :loop
setVar $b 1
add $a 1
branch ($a > 10) :loop
So, you slackers that haven't given this a shot yet, jump on in, and learn something new.