Scheme Exercise (Structure and Interpretation book)
I've been working through the Structure and Interpretation of Computer Programs book and have hit a bit of a problem. Since I chose to use this book as part of my curriculum, my teacher doesn't actually know much of anything about Lisp or its varients, so I was hoping to get a bit of help.
The problem is:
Section 1.2 wrote:Exercise 1.11. A function f is defined by the rule that f(n) = n if n<3> 3. Write a procedure that computes f by means of a recursive process. Write a procedure that computes f by means of an iterative process.
I have no trouble writing a recursive procedure/recursive process, but I am having trouble writing it iteratively; I'm not familiar enough with Lisp to know how to model this, and I don't know how to do it iteratively with three branching sections. I'm assuming it'd require some sort of running total and a number of variables to save the state, and I was thinking about possibly trying to work from the bottom up, but I'm not real sure.
If anyone can help me with an iterative version, it'd be much appreciated; right now I'm just confused.
Let's write down some examples of this function:
f(0) = 0
f(1) = 1
f(2) = 2
f(3) = f(2) + 2*f(1) + 3*f(0)
f(4) = f(3) + 2*f(2) + 3*f(1)
f(5) = f(4) + 2*f(3) + 3*f(2)
If you compute the value of f(5) recursively you do it like this:
f(5) = f(4) + 2*f(3) + 3*f(2)
f(4) = f(3) + 2*f(2) + 3*f(1)
f(3) = f(2) + 2*f(1) + 3*f(0)
f(2) = 2
f(1) = 1
f(0) = 0
f(3) = 2 + 2*1 + 3*0
If you do this iteratively you do it the other way around:
f(0) = 0
f(1) = 1
f(2) = 2
f(3) = f(2) + 2*f(1) + 3*f(0)
f(4) = f(3) + 2*f(2) + 3*f(1)
f(5) = f(4) + 2*f(3) + 3*f(2)
The last three lines have the same structure:
f(n) = previous + 2*before-previous + 3*before-before-previous
If you want to compute f(n) you only need the 3 previous values at any time. To compute f(3) you need f(2), f(1) and f(0). Let's give these short names:
previous = a
before-previous = b
before-before-previous = c
If you want to compute f(3):
a = f(2) = 2
b = f(1) = 1
c = f(0) = 0
Now we compute f(4):
a = f(3) = ?
b = f(2) = 2
c = f(1) = 1
For b and c it's easy to define them in terms of previous values a, b and c:
b = previous-a
c = previous-b
Verify that this is correct.
a is a little tickier because we need the original formula:
a = previous-a + 2*previous-b + 3*previous-c
So this is what we have now:
a = previous-a + 2*previous-b + 3*previous-c
b = previous-a
c = previous-b
Let's rewrite that with arrow notation:
a -> a + 2*b + 3*c
b -> a
c -> b
These arrows mean that you compute them in parallel; the a in b -> a is still the previous a, and not the new a generated by a -> a + 2*b + c.
Computing f(5) with this iterative method:
a -> 2
b -> 1
c -> 0
These are the base-case values because f(n) = n if n <3> 2 + 2*1 + 3*0 = 4
b -> 2
c -> 1
(n = 4)
a -> 4 + 2*2 + 3*1 = 11
b -> 4
c -> 2
(n = 5)
a -> 11 + 2*4 + 3*2 = 25
b -> 11
c -> 4
The answer of f(5) is in a: 25.
The basic structure of the procedure looks like this:
(define (f n)
(define (iter counter a b c)
(if (= counter n)
c
(iter (+ counter 1)
; new a
; new b
; new c
(iter 0 2 1 0))
The rest is an exercise.
Don't shoot me if this isn't correct! (I didn't implement the actual procedure ;-))
Similar Messages
-
Data Structures and Algorithms in java book
Hi guys,
I want to know a good book which is good for Data Structures and Algorithms in java. I am good at Core java but a beginner for Data Structures in Java. I am a little poor in Data Structures concepts.
Following are the books I have found on the net. Could you help me the choose the best outta them.
1. Data Structures and Algorithms in Java - Mitchell Waite
2. Data Structures in Java - Sandra Anderson
3. Fundamentals of OOP and Data Structures in Java - Richard Weiner & Lewis J. Pinson
4. Object Oriented Data Structures Using Java - Nell Dale, Daniel T. Joyce, Chip Weemslieni wrote:
I good data structures book doesn't have to be language-specific.Thx DrLazlo, my speachYes.
The OP wrote:
I have access to these books and dont know which one to start with.What I meant is that you shouldn't narrow your search to insist that the book you choose have "Java" in the title. -
What is the difference between (SEPA Structured) and (SEPA Unstructured)?
Hi,
Could you please teach me about "Format Payments (SEPA Structured)"
and "Format Payments (SEPA Unstructured)"?
1.What is Format Payments (SEPA Structured)?
Is (SEPA Structured) used with which case?
2.What is Format Payments (SEPA Unstructured)?
Is (SEPA Unstructured) used with which case?
3.What is the difference between (SEPA Structured) and (SEPA Unstructured)?
The customer is checking Note.791226.1.
However, he says that he cannot understand these two differences.
Please teach me.
Thanks.From the European Payments Council website:
Remittance information: structure the unstructured
The SEPA Credit Transfer Scheme permits the end-to-end carrying of remittance data on a structured or unstructured basis appropriate to the nature of the payment (the remittance information usually contains details of the contract underlying the transaction such as an invoice number, for example). The length of the remittance information in the SCT Scheme is fixed at a standard length of 140 characters and banks are obliged to pass on the full remittance information.
The EPC supports a proposal developed by the European Association of Corporate Treasurers (EACT), which allows companies to agree on a structure for the remittance information. The EACT suggestion on how to structure the "unstructured" remittance fields allows companies exchanging a credit transfer to agree, among other, on information to be transmitted in a specific manner. Banks will carry remittance information structured in such an agreed way unaltered throughout the process chain. -
Best approach to create Package Structure and .content.xml
I am aware that we have a schem.xsd for generic package content.xml creation and neither do vault.xml and other associated xml files in the META-INF folder of the package.
I want to know if there is some recommended approach to build the package and xml files, specifically content.xml programmatically on the file system. I know that we can use package manager (API not the GUI/screen) but that comes into picture when the folder structure and xmls files are created. I am interested to know a standard procedure of acceptable procedures to build the structure. I have seen folks use JDom/SAX etc to build this and even velocity to try it out using templates but that looks largely as a workaround. Can anyone help with some inputs on this?We've been successful at using ANT as a Build tool to run XSLT 2.0 using the Saxon XSL processor. We have processed both CSV and XML files into packages. This started out pretty simply, but grew more complex than initially thought. There are a lot of subtlties that can be overlooked in the package format. Also if your filters aren't right it will happily delete a lot of data. Thankfully it appears uninstalling can recover these most times, but I'd recommend testing packages on a throw away instance.
I've posted an example Ant + XSL that goes from CSV > XML > Many XML Files > CRX Package Zip: https://github.com/odu/crx-package-xsl-example. There is also some info on some of the complexities of a package mentioned on that page that may be helpful, even if Ant / XSL isn't your route.
Can you share more about your use for building a package, what format is the source data in, etc? This example is really only useful for batch loading. -
Hide function in Login Items doesn't work for iChat and Address Book app.
There is a problem with the hide function for iChat and Address Book application in Login Items. If you go to System Preferences, click on Login Items, add the iChat and Address Book application to the Login Items, activate the hide function for iChat and Address Book application and restart your Mac iChat and Address Book application will start with opening a window. Normally this shouldn't happen if the hide function in Login Items is activated for iChat and Address Book application.
Message was edited by: Roman Patrice GegoHi,
Your link refers to changes to 10.6.3 prior release as tested by Developers.
The numbering system tells us that. (Build 10Dxxx).
Therefore it is an Update and not an Upgrade, therefore no-one is going to get charged.
If the article is the so called Release Notes then they mention nothing about correcting any issue with Login Items Hiding.
If you think an issue is being missed there is a place to report that, from this icon view list http://www.apple.com/feedback/ which includes Hardware and Software.
I personally have not tested Login Items Hiding as I tend to think there is no point in having an App open if it not on the Desktop.
As Kappy pointed out there was little progress on a similar issue with Leopard.
This could be interpreted that Apple feel that the issue does not effect enough people or that other issues are more important.
As anyone and everyone can report Issues and contribute their ideas to the OS and it's improvement via the Feedback links it would seem to be a question of enough people bringing it to Apple's Attention.
I would tend to work on Issues that stopped an App functioning first, linked with integration with the OS and any changes to the major parts of it such as a Quicktime.
Lesser issues that maybe more cosmetic in appearance would tend to fall down my list of things to do.
Presumably Apple have a grading system on such things that may not fit with either of our views.
As Apple don't reveal any details about the OS Updates or even Upgrades then anything any of us think we interpret as a pattern is just that - an interpretation.
Consequently anything we say on the subject is then likely to be seen as speculation under the Terms of Use of these Boards.
8:28 PM Sunday; May 9, 2010
Please, if posting Logs, do not post any Log info after the line "Binary Images for iChat" -
How to make a copy of an application with its schema-tables,data and all
Good day,
I am looking for the best way to make a copy of an application from one computer to another, including the schema (tables, data and all) in Apex3.2.
I can only manage to make a copy of the application without the data using the export utility
Please assist with this difficulty
Kind Regards
Thabo
Edited by: Thabo K on Jun 1, 2009 1:13 AMHello,
To copy across the data you can use the traditional EXP/IMP or the Datapump utility.
If you're used to using EXP/IMP I'd encourage you to look at Datapump, if you haven't used EXP/IMP before I'd encourage you to look at Datapump (datapump rocks) -
http://www.oracle-base.com/articles/10g/OracleDataPump10g.php
There are a few major differences between Datapump and traditional EXP/IMP (EXP/IMP creates the export file on the client side, Datapump creates it on the server side etc).
In my book "Pro Oracle Application Express" I have a section on cloning applications/data between instances, which you might find useful.
Hope this helps,
John.
Blog: http://jes.blogs.shellprompt.net
Work: http://www.apex-evangelists.com
Author of Pro Application Express: http://tinyurl.com/3gu7cd
REWARDS: Please remember to mark helpful or correct posts on the forum, not just for my answers but for everyone! -
Where to find Oracle Apps HR schema table structures?
Hi!
Can someone guide me to the link where I can find the HR schema table structures for Oracle E-Biz suite 11.5.10?
Previously, i used to get them under Top Tech Docs on the metalink.
Thanks and regards,
AparnaHi Aparna,
You can also find in http://irep.oracle.com/index.html
Regards,
Naga Suresh. Challapalli -
Need links for data structure and algorithms.
Hi.
I am just new to java but need to learn data structure and algorithms.
Do your guys got any good links or bbs to learn?
Thanx in advancehttp://www.amazon.com/exec/obidos/tg/detail/-/1571690956/ref=cm_huw_sim_1_3/104-7657019-1043968?v=glance
http://www.amazon.com/exec/obidos/tg/detail/-/0534376681/ref=cm_huw_sim_1_4/104-7657019-1043968?v=glance
http://www.amazon.com/exec/obidos/tg/detail/-/0672324539/ref=cm_huw_sim_1_2/104-7657019-1043968?v=glance
http://www.amazon.com/exec/obidos/tg/detail/-/0201775786/qid=1060946080/sr=8-1/ref=sr_8_1/104-7657019-1043968?v=glance&s=books&n=507846
$8 for the first -
Structural and Contextual Authorisations
Hello All,
WOudl appreciate if some one can provide me with some help with regards to structural and contextual authorisations. I have created structural profiles for MSS and LSO. Now if i assign both the profiles to the user then the user gets access to all employees within a pers area due to the LSO profile.
Expected is that the user sees only his reportees when he runs any MSS reports but see all employees when he runs any LSO(TEM) tcode. I believe this is possible via the contextual authorisations but it is not working.
The switches to activate structural and contextual is also on in OOAC.
Thanks,
VishwanathThank you for the reply...
LSO is used only for ESS self booking/cancelling etc. Online trainer, adminstrator, MSS lso functions are not turned on.
We have not used P_ORIGINCON yet. Autsw Incon = 0
Originally with had a structural profile which used SBESX. The root OU was determined by rh_get_manager_assignment.
After LSO implementation, managers who had this structural profile could not see the course catalog on ESS Portal. We resolved this by adding LSO related eval paths to the same structural profile. We tried, LSOCATAL, LSOCATDO, ZLSOCATDO etc. This works and they get started seeing the catalog online. But any lso related eval path has P object added to this profile (eg. LSOCATAL)makes the manager see the trainers. It P object is not used, then trainer name of a curse do not show on ess-lso.
Please let me now if you need more info.
Thanks..
PJ -
Export schema table structure only- no procedures
Hi Friends,
I try to export a schema structure with rows=n option in exp command. As log records show the procedures had exported too.
Do we have any way to export a schema tables only?
Thanks for help!
Jinuser589812 wrote:
Database is 10.2.04 I are not able to use data pump based on system configuration.Please elaborate on what you mean by "I are not able to use data pump based on system configuration"
We have more one hundred tables. that needs to be include tables option.
Do you have any simple way to export a schema tables structure without list 120 table's name in exp command?
Edited by: user589812 on Jan 4, 2012 10:19 AMI do not believe you have a choice. One method could be to get a list of all needed tables (SELECT TABLE_NAME FROM USER_TABLES) and create a par file with this list.
HTH
Srini -
How to restore iCal and Address Book from my iPod mini.
I used to back-up my iCal and Address Book to both my Nokia phone and my iPod mini twice a day. then over Christmas my laptop hard drive and my phone both broke within 2 days of each other. Ouch! My only copy of my addresses and diary are now on the iPod. I could spend days reading the data and type it into to computer manually, but there has to be a way to do it automatically. *Mustn't there?*
Similar problem here,
I have a month-old archived version of my AddressBook, but today my entire rolodex vanished when the program froze and I force quit. I have a much more recent update on my ipod and have made significant additions/editions in the past month. Can I retrieve all that data from my iPod??
Help! -
What are the logical structure and physical structure in oracle
what are the logical structure and physical structure in oracle and how can allocate a DB block size as default size is 8192?
From the Concepts Guide
http://download-east.oracle.com/docs/cd/B19306_01/server.102/b14220/toc.htm
The physical structures are:
Datafiles
Control Files
Redo Log Files
Archive Log Files
Parameter Files
Alert and Trace Log Files
Backup Files
The Logical Structures are:
Tablespaces
Oracle Data Blocks
Extents
Segments -
What is diff b/w Include Structure and Append Structure at Database Level
Hi Experts,
Could you please let me know what is the main difference between .Include Structure and .Append Structure at SE11?
Thanks in advance and for good answer will give good points.
SekharHi,
1. Append Structures
Append structures can only be assigned to a single table.
Append structures are created in the custome rnamespace ( ZZ or YY)
In case of new versions of the standard table during upgrade, the append structures are automatically appended to the new version of the standard table
Append structures can not be used with cluster and pool tables
Append structures are created in transaction SE11. Display the standard table fields and press the Append structure button.
When you press the button, SAP sugests a name for the new append structure. After you has accepted the name,
a screen will be shown where you can enter the new fields.
Remember to activate.
2. Customizing Includes
Some of the SAP standard tables contains special include statements called Customizing includes. In contrast to Append structures,
Note that customizing includes are created by SAP, but the customer supply the fields for the include.
Customizing includes begin with CI_ and is part of the customer namespace
One Customizing include can be inserted into more than one table.
You can find Customizing includes in SE11 under structures.
Try to take a look at table RKPF which uses the Customizing include CI_COBL (In an IDES system). Next try to add a field to CI_COBL, and activate it. If you go back to table RKPF you will se that your new field has been added.
Regards,
Ferry Lianto -
I already have adobe digital editions on my mac pc and download books from the library to my android e-reader. Can I use the same digital editions on my ipad air, or do I need to load a different one onto my ipad?
Try following forum:
Adobe Digital Editions -
Now that I've downloaded a book from the library, How do I get it
on to the Kobo? It's really frustrating.There's a couple of pieces of this picture I'm not getting, so let me give
you an answer that starts with the basics.
The Kobo ereader - actually any ereader - has to be recognized by ADE as an
authorized device. If you follow a certain sequence, this takes place
automagically, because everything is aligned. First, the Kobo ereader has
to be 'activated' by registering it with Kobo. That means you have to set
up an account with the Kobo store/website, and then link the ereader to the
website. When you do this, the Kobo store will embed your Kobo ID in the
Kobo ereader. Then, turn on your computer and plug in your ereader to a USB
port. Assuming that your computer is a Windows machine, the computer will
recognize the Kobo ereader as a new device - usually a hard drive. Once
Windows reports that your new hardware is ready to use, you can start up
ADE. ADE 'should' recognize that your Kobo ereader is attached, and
register it in the left hand panel of its Library view. Once this is done,
you can drag and drop books from ADE onto your ereader.
Hope this helps!
Tom (Frustrated in AZ)
=====================
Maybe you are looking for
-
How to check valuation type and batch during creating PO
Hi All, can every body help me please, I have a material which manage by batch and valuation type. When user create purchase order using that kind of material I want the system checking field batch and valuation type. If they not match then system wi
-
I have mistakenly enabled the need for a master password for firefox to autofill passwords for me.I have no clue what the master password is.Is there any way to disable or change the master password , without knowing what the master password is?
-
Update Java Sun JSDK 1.4.2_07 in server
Hello, I wonder if it is compulsory to use the version Sun JSDK 1.4.2_07 on the server xMII 11.5 or we can update the JAVA after installation of XMII 11.5 to a latest version of Java? We would have problems with support in SAP? Nilo ...
-
Hey, so i just got an HF100 and supposedly it records in 30P which is really recording 30p in a 60i wrapper. Currently my capture preset is at Prores 422(HQ) and sequence preset are Prores 422 (HQ) in 1920x108030P. Since the hf100 isn't recording in
-
<PRE>Exit Code: 6 Please see specific errors below for troubleshooting. For example, ERROR: -------------------------------------- Summary -------------------------------------- - 0 fatal error(s), 2 error(s) ----------- Payload: Microsoft Visual C+