• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: The Pyramid - a challenge...
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: The Pyramid - a challenge...


  • Subject: Re: The Pyramid - a challenge...
  • From: Nigel Garvey <email@hidden>
  • Date: Sat, 23 Apr 2005 17:52:30 +0100

In my message of Sat, 23 Apr 2005 13:13:41 +0100, I wrote:

>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

However, this version seems to do better in AS 1.9.1, especially with
larger pyramids:

  set l1 to {{1}, return}
  repeat 200 times
    set end of my l1 to nextStep(item -2 of my l1)
    set end of my 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
      property foo : {1}
    end script
    set n to (count x)
    repeat with y from 2 to n div 2 + 1
      set end of o's foo to (item (y - 1) of o's p) + (item y of o's p)
    end repeat
    return o's foo & reverse of items 1 thru (n mod 2 - 2) of o's 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

  • Follow-Ups:
    • Re: The Pyramid - a challenge...
      • From: Martin Orpen <email@hidden>
  • Prev by Date: Re: The Pyramid - a challenge...
  • Next by Date: Creating XML
  • Previous by thread: Re: The Pyramid - a challenge...
  • Next by thread: Re: The Pyramid - a challenge...
  • Index(es):
    • Date
    • Thread