for newbies HTDP



I am providing here help on solving exercises of HTDP (have a look @
the PREFACE of the book @ htdp.org and you will never leave it).

My purpose is NOT PROVIDING solutions to exercises in the book (they
are already provided @ htdp.org) but to SHOW that our way of dwelling
our BRAINS into solving problems is LESS PRODUCTIVE than if we follow
the DESIGN-PROCESS (the core of HTDP) and I show this not only by
showing you the SOURCE-CODE of the solution i have developed BUT ALSO
by providing PRECISE EXPLANATION on WHAT different THINGS represent and
how they solved the problm and i do this using comments and little but
exact explanations (I do not TRUST too much of theory, looking at the
SOURCE-CODE and working through it is MUCH BETTER and PRODUCTIVE). If
programming only meant solving problems then it could have been easier
(it is interesting but it is a different case) but it is not as it does
not only mean solving problems but solving WHICH problems? Every BUG in
a programme has as many ways of debugging as number of people but
CHOOSING a WAY, A PROCESS to debug better than all others is the
DESIGN-PROCESS (I am sorry there is no BEST way to debug a programme as
at every new confrontation (to different PROGRAMMES & PROGRAMMERS)we
may get a new solution which can solve the problem better) . I have
many HOURS & DAYS with my head banging into problems constantly and in
the end I came to know my "CONCEPT of PROBLEM" was wrong. When i
thought in a differnet way i found the solution in a minute. this is
WHOLE MOTIVATION behind bringing this email you. SINCE i am just a
NEWBIE learning throught book HTDP i can only help you if you are
NEWBIE @htdp. This email is of NO-IMPORTANCE to a programmer.

for PROGRAMMERS only one thing can be useful which is the "CONCEPT of
DESIGN-PROCESS" (which is explained better @ htdp.org) as it is
independent of LANGUAGE. DSIGN-PROCESS is PURE-PROGRAMMING and it makes
you more productive by chnaging you from SYNTAX oriented to PROGRAMMING
oriented. I am not SURE whether it will help you or not but if it does
please send me a THANKS note so that i can know i have made a small
difference to someone's life. (actually someone helped me now i am
returning the favour as it happens in "Free-Software world", the
sharing of thoughts and ideas)

Ok now the exercis and solution using DESIGN-PROCESS:

1.) FIRST please have look at the EXERCISE STATEMENT in the book, then

2.) WRITE solution by YOURSELF, and in the end

3.) CHECK my solution and watch the difference (if any), see if you can
make out something out of TWO SOLUTIONS.

************ EXERCISE 10.1.4 **************************

;; HOW I used DESIGN-PROCESS to approach "ex: 10.1.4" of HTDP
;; <have a look @ PREFACE of the book @ htdp.org & you will never leave
it>

;;######################### COMMENTS ################################

;; this is about:
;; how I GENERLISED an EXISTING function to generate a new one.
;; also have a look at the use of AUXILIARY functions

;;###################################################################

;; DATA-DEFINITIONS
;; A list-of-euros(numbers) is either:
;; 1. an empty list, <empty>, or
;; 2. <(cons n loe)>, where n= number, loe=
list-of-euros(numbers)

;; CONTRACT, PURPOSE and HEADER:
;; convert-euro : list-of-numbers -> list-of-numbers
;; to create a list-of-dollers from list-of-euros
;; (define (convert-euro lon)...)

;; EXAMPLES
;; (convert-euro empty) "= empty"
;; (convert-euro (cons 20 (cons 10 (cons 1 empty)))) "=

;; (cons (* 1.22 20) (cons (* 1.22 10) (cons (* 1.22 1) empty)))"

;; TEMPLATE: euro-template : lon -> ???
;; (define (euro-template lon)
;; (cond
;; [(empty? (first lon))...]
;; [else...(first lon).....(euro-template (rest lon))....]))

(define (convert-euro a-lon)
(cond
[(empty? a-lon) empty]
[else (cons (euro->doller (first a-lon)) (convert-euro (rest
a-lon)))]))


(define (euro->doller euro)
(* 1.22 euro))

;; TEST
(convert-euro empty) "= empty"
(convert-euro (cons 20 (cons 10 (cons 1 empty)))) "="
(cons (* 1.22 20) (cons (* 1.22 10) (cons (* 1.22 1) empty)))

;; now I will GENERLISE this function into <convert-euro-1> which WILL
take 2 arguments.

"***************************************************************************"

(define (convert-euro-1 ex-rate a-lon)
(cond
[(empty? a-lon) empty]
[else (cons (euro->doller-1 ex-rate (first a-lon)) (convert-euro-1
ex-rate (rest a-lon)))]))

(define (euro->doller-1 ex-rate doller)
(/ doller ex-rate))

;; TEST-1
(convert-euro-1 1.22 (cons 20 (cons 10 empty))) "=" (cons (/ 20 1.22)
(cons (/ 10 1.22) empty))


;;##################### OUTPUT ########################
Welcome to DrScheme, version 209.
Language: Beginning Student.
empty
"= empty"
(cons 24.4 (cons 12.2 (cons 1.22 empty)))
"="
(cons 24.4 (cons 12.2 (cons 1.22 empty)))
"*******************************************************************************"
(cons 16.3934426229508196721311475... (cons
8.1967213114754098360655737... empty))
"="
(cons 16.3934426229508196721311475... (cons
8.1967213114754098360655737... empty))
>
;;#################### E. O. P ########################

;; EOP means "END OF PROGRAMME", it is the one i like to use instead
of traditional EOF.

.



Relevant Pages

  • for newbies and HTDP - 2
    ... you more productive by chnaging you from SYNTAX oriented to PROGRAMMING ... FIRST please have look at the EXERCISE STATEMENT in the book, ... one natural-recursion is happening WITHIN the selector ... lotp) empty] ...
    (comp.lang.scheme)
  • for newbies and HTDP - 2
    ... you more productive by chnaging you from SYNTAX oriented to PROGRAMMING ... FIRST please have look at the EXERCISE STATEMENT in the book, ... one natural-recursion is happening WITHIN the selector ... lotp) empty] ...
    (comp.lang.scheme)
  • Re: Implementing strstr
    ... exercises they contain. ... and study abilities I'd expect from first-year college students C, ... Most of it's honestly pretty obvious if you do any programming and ... I continue to push updates to the public git tree before running them ...
    (comp.lang.c)
  • Re: Help me come up with a few and simple programming challenges
    ... functional programming, and in real life actual algorithmic development is rather rare; most programming is more about data structures and communication. ... because I don't really care to do some toy programs for funny toy exercises. ... Maybe in some cases stuff like that could be applied to real-life problems, but I've never even heard of anything like that, so I don't bother. ...
    (comp.lang.scheme)
  • Re: TAOCP prerequisite
    ... Programming is like the bible in the CS/Math sense. ... note that many interesting points are covered only in the exercises. ... on the first time through a ...
    (sci.math)