Code Comments

Programming Forum and web based access to our favorite programming groups.
For Programmers: Free Programming Magazines | New: Database administration forum
Registration is free! Edit your profileCalendarFind other membersFrequently Asked QuestionsSearch -> 
Post New Thread











Thread
Author

HTDP problem 9.5.5
Develop the function convert. It consumes a list of digits and produces
the corresponding number. The first digit is the least significant, and
so on.

Ok I know the formula for converting 123 would be 1 x 10 expt 0 + 2 x
10 expt 1 + 3 x 10 expt 2.

But I can't conceive a programmatic solution (based on the material
taught up to that point) that does not involve passing the expt to
apply as a parameter.


Report this thread to moderator Post Follow-up to this message
Old Post
wooks
04-24-05 08:57 PM


Re: HTDP problem 9.5.5
wooks wrote:

> Develop the function convert. It consumes a list of digits and produces=

> the corresponding number. The first digit is the least significant, and=

> so on.
>=20
> Ok I know the formula for converting 123 would be 1 x 10 expt 0 + 2 x
> 10 expt 1 + 3 x 10 expt 2.
>=20
> But I can't conceive a programmatic solution (based on the material
> taught up to that point) that does not involve passing the expt to
> apply as a parameter.

1234 =3D 4 + 10*( 3 + 10*( 2 + 10*( 1 ) ) )

--=20
Jens Axel S=F8gaard


Report this thread to moderator Post Follow-up to this message
Old Post
Jens Axel Søgaard
04-24-05 08:57 PM


Re: HTDP problem 9.5.5
wooks writes:

> Develop the function convert. It consumes a list of digits and
> produces the corresponding number. The first digit is the least
> significant, and so on.
>
> Ok I know the formula for converting 123 would be 1 x 10 expt 0 + 2
> x 10 expt 1 + 3 x 10 expt 2.

A list of digits, least significant first, would be (3 2 1) or maybe
(#\3 #\2 #\1). 123 is already a number, written with most significant
digit first.

> But I can't conceive a programmatic solution (based on the material
> taught up to that point) that does not involve passing the expt to
> apply as a parameter.

This is a simple recursion. To convert (5 1 4 1 3), convert the tail
to 3141, combine with the head to get 31415. Can you see how I got
31415 from 3141 and 5? Can you see what value is needed for () to get
3 out of (3)?

I didn't check HtDP, but very little is needed here. Don't use apply.
If you have fold, work it out with that. It would be from right, with
the above base case and recursion rule as arguments.

Report this thread to moderator Post Follow-up to this message
Old Post
Jussi Piitulainen
04-24-05 08:57 PM


Sponsored Links




Last Thread Next Thread Next
Search this forum -> 
Post New Thread

Scheme archive

Show a Printable Version Send to friend Email This Page to Someone! subscribe to this thread Receive updates to this thread
Computer Consultants
Programming Jobs
Visual Basic Controls
SQL Server Programming
Webservices
Java Security
Visual Studio
C# Programming
Visual J++
Software engineering
Open source Software
Perl Programming
PHP Programming
ASP Programming
ASP .NET Programming
Visual Basic Programming
Windows Scripting Host
Java Programming
Java Help
Java Beans
VBScript
Cobol
MAC Applications
Unix Programming
Forum Jump:
All times are GMT. The time now is 07:23 PM.

 
Free MCSE Braindumps | Real Estate Topics

Programming forum archive

Copyrights CodeComments.com 2004 - 2006

Powered by vBulletin Copyright 2000-2006 Jelsoft Enterprises Limited.