• 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: Mon, 25 Apr 2005 00:59:07 +0100

Martin Orpen wrote on Sun, 24 Apr 2005 11:03:22 +0100:

>on 23/4/05 17:52, Nigel Garvey at email@hidden wrote:
>
>> However, this version seems to do better in AS 1.9.1, especially with
>> larger pyramids:
>
>
>                 [snip]
>
>              Thanks Nigel.

Here's the process tidied up into its own handler. If you liked, you
could add a parameter for the start number, and use {startNum} in the two
places where {1} appears now.

  on pyramid(levels)
    script o
      property wholePyramid : {{1}}
      property prevList : missing value
      property prevListRest : missing value
      property thisList : missing value
    end script

    repeat with prevLen from 1 to (levels - 1)
      set o's prevList to end of o's wholePyramid
      set o's prevListRest to rest of o's prevList
      set o's thisList to {1}
      repeat with y from 1 to (prevLen div 2)
        set end of o's thisList to ¬
          (item y of o's prevList) + (item y of o's prevListRest)
      end repeat
      set end of o's wholePyramid to return
      set end of o's wholePyramid to o's thisList & ¬
        (reverse of items 1 thru (prevLen mod 2 - 2) of o's thisList)
    end repeat
    return o's wholePyramid
  end pyramid

  pyramid(20)

>       Time to build the pyramid!
>
>What follows is one of my sketchy messes:

The result looks very pretty in a browser though.  :-)

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: 10.3.9 Broke something
  • Next by Date: Re: Creating XML
  • Previous by thread: Re: The Pyramid - a challenge...
  • Next by thread: Re: The Pyramid - a challenge...
  • Index(es):
    • Date
    • Thread