Re: The Pyramid - a challenge...
Re: The Pyramid - a challenge...
- Subject: Re: The Pyramid - a challenge...
- From: Nigel Garvey <email@hidden>
- Date: Sat, 23 Apr 2005 13:13:41 +0100
David C Andrews wrote on Sat, 23 Apr 2005 00:34:18 -0400:
>On Apr 22, 2005, at 3:50 PM, Martin Orpen wrote:
>
>> Trains are delayed again... So here is an ideal opportunity for
>> somebody to
>> do a "Garvey" and unleash the "script o":
>Not a "Garvey" and no "script o" but a bit simpler:
>
>set l1 to {{1}}
>repeat 5 times
> set end of l1 to nextStep(last item of l1)
>end repeat
>set t to {return}
>repeat with r in l1
> set end of t to contents of r
> set end of t to return
>end repeat
>
>on nextStep(x)
> set foo to {1}
> set n to count of x
> set {y, z} to {2, 1}
> repeat (n - 1) times
> set end of foo to (item z of x) + (item y of x)
> set {y, z} to {y + 1, z + 1}
> end repeat
> set end of foo to 1
> return foo
>end nextStep
Simpler still:
set l1 to {{1}, return}
repeat 21 times
set end of l1 to nextStep(item -2 of l1)
set end of l1 to return
end repeat
l1
on nextStep(x)
set foo to {1}
repeat with y from 2 to (count x)
set end of foo to (item (y - 1) of x) + (item y of x)
end repeat
set end of foo to 1
return foo
end nextStep
But a "Garvey" would look something like this: :-)
set l1 to {{1}, return}
repeat 20 times
set end of l1 to nextStep(item -2 of my l1)
set end of l1 to return
end repeat
set end of l1 to nextStep(item -2 of my l1)
l1
on nextStep(x)
script o
property p : x
end script
set n to (count x)
set foo to {1}
repeat with y from 2 to n div 2 + 1
set end of foo to (item (y - 1) of o's p) + (item y of o's p)
end repeat
if (n mod 2 is 0) then
set foo to foo & rest of reverse of foo
else
set foo to foo & reverse of foo
end if
return foo
end nextStep
NG
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Applescript-users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden