Urgent Urgent I am stuck with this problem 
Author Message
 Urgent Urgent I am stuck with this problem

Quote:

> Hi every one I am a newcomer in Scheme.  Please some one help me how to
> solve the following problem from the Boot "SCHEMATICS OF COMPUTATION"
> By vincent s manis & J little. page #105
> Problem
> Wate a procedure (nth-digit n x) that takes a nonnegative integer n and
> a positive integer x, and returns the nth from the left of x counting
> from 0 e.g
> (nth-digit 0 10) =>  1.0
> (nth-digit 3 1234) => 4.0

> Thanks
> QQ

> I have been able to write the procedure when done from right.  But
> having problem is from left.

Warning.  It's probably not what you're instructor had in mind.

(define (nth-digit d n)
  (-
    (char->integer
      (list-ref
         (string->list (number->string n))
         d))  
    48))

(define (testit)
  (if (equal? '(1 4) (map nth-digit '(0 3) '(10 1234)))
     'bingo
     'bust))

==>(testit)
bingo

Cheers,
John



Sat, 11 Jan 2003 03:00:00 GMT  
 Urgent Urgent I am stuck with this problem
Hi every one I am a newcomer in Scheme.  Please some one help me how to
solve the following problem from the Boot "SCHEMATICS OF COMPUTATION"
By vincent s manis & J little. page #105
Problem
Wate a procedure (nth-digit n x) that takes a nonnegative integer n and
a positive integer x, and returns the nth from the left of x counting
from 0 e.g
(nth-digit 0 10) =>  1.0
(nth-digit 3 1234) => 4.0

Thanks
QQ

I have been able to write the procedure when done from right.  But
having problem is from left.

Sent via Deja.com http://www.deja.com/
Before you buy.



Sun, 12 Jan 2003 03:00:00 GMT  
 Urgent Urgent I am stuck with this problem
Thanks Alot Jhon you saved me as I was stuck with this problem and was
unable to go on for further problems.  That is a big drawback that
unless I dont' know a problem I don't go a head.  Plus it seemed great
way of looking at a problem and making it more simple.

Thanks very much

QQ



Quote:

> > Hi every one I am a newcomer in Scheme.  Please some one help me
how to
> > solve the following problem from the Boot "SCHEMATICS OF
COMPUTATION"
> > By vincent s manis & J little. page #105
> > Problem
> > Wate a procedure (nth-digit n x) that takes a nonnegative integer n
and
> > a positive integer x, and returns the nth from the left of x
counting
> > from 0 e.g
> > (nth-digit 0 10) =>  1.0
> > (nth-digit 3 1234) => 4.0

> > Thanks
> > QQ

> > I have been able to write the procedure when done from right.  But
> > having problem is from left.

> Warning.  It's probably not what you're instructor had in mind.

> (define (nth-digit d n)
>   (-
>     (char->integer
>       (list-ref
>          (string->list (number->string n))
>          d))
>     48))

> (define (testit)
>   (if (equal? '(1 4) (map nth-digit '(0 3) '(10 1234)))
>      'bingo
>      'bust))

> ==>(testit)
> bingo

> Cheers,
> John

Sent via Deja.com http://www.deja.com/
Before you buy.


Sun, 12 Jan 2003 03:00:00 GMT  
 Urgent Urgent I am stuck with this problem

Quote:

>Thanks Alot Jhon you saved me as I was stuck with this problem and was
>unable to go on for further problems.  That is a big drawback that
>unless I dont' know a problem I don't go a head.  Plus it seemed great
>way of looking at a problem and making it more simple.

>Thanks very much

>QQ

Let me suggest that you read this line again:

Quote:



...
>> Warning.  It's probably not what you're instructor had in mind.

This is certainly not what your instructor had in mind, and has the
following among its drawbacks:

1) It relies upon the arbitrary ordering and offset of the digit
characters imposed by character->integer. (I guarantee this will
break for some scheme implementations.)
2) It ignores the nice structure inherent in the numbers themselves.
This solution is like trying to fix your car by taking fif{*filter*} pictures
of it, inside and out, and then giving them to an expert mechanic.
Why not just take the car itself to the garage?

I think Joe Marshall (sp?) gave you some excellent hints, and I would
suggest you look to those rather than going the number->string->number
route. Scheme is not perl.

Hope this helps,

john clements



Sun, 12 Jan 2003 03:00:00 GMT  
 Urgent Urgent I am stuck with this problem

...

Quote:

>Hope this helps,

>john clements

p.s.: I also think it's not such a great problem to
begin with.

p.p.s: You say you solved the problem when counting
from the right; can you see a way to turn the part of
the problem you solved into the whole solution?



Sun, 12 Jan 2003 03:00:00 GMT  
 
 [ 5 post ] 

 Relevant Pages 

1. URGENT URGENT URGENT

2. URGENT-help needed-URGENT

3. Super URGENT Request - Easy answer I am sure

4. Urgent!!Oracle9i:using ODBC, I am noy able to link to my database tables using Access

5. I am New but assignment is urgent!

6. An Urgent problem regarding app. conversion

7. Urgent EIP problem

8. tpsbt.cpp line 2172 error -- urgent problem

9. urgent Edit-In-Place problem, C55EE-H, ABC

10. Urgent !!! ABC Query problem

11. C4B Number Rounding Problem - URGENT

12. C4BPatch - Upgrade problem - Urgent!!!!!!!!!!!! - Attention: Technical Support

 

 
Powered by phpBB® Forum Software