Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.

  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint
Share this Page URL
Help

Section A.6. Chapter 6

A.6. Chapter 6

A.6.1. Exercise 1 solution

-- Calculate the first 20 Fibonacci numbers

-- Define F1 and F2

set fibList to {0, 1}

-- Now calculate the next 18 numbers

repeat 18 times
    set end of fibList to (item −1 of fibList) + (item −2 of fibList)
end repeat

-- log the result

log fibList

A.6.2. Exercise 2 solution

set USCities to {{"Boston", 574000}, {"Chicago", 2784000}, {"Dallas", 1007000}, ¬
     {"Houston", 1631000}, {"Los Angeles", 3485000}, {"Philadelphia", 1586000}, ¬
     {"San Diego", 1111000}, {"San Francisco", 724000}, {"New York", 7323000}}

-- set the mix and max to the population of the first city

set min to item 2 of item 1 of USCities
set max to min

					  


  

You are currently reading a PREVIEW of this book.

                                                                                                                    

Get instant access to over $1 million worth of books and videos.

  

Start a Free Trial


  
  • Safari Books Online
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint