# [plt-scheme] newbie's problem regarding ex-11.3.4

 From: arnuld (arnuld3 at gmail.com) Date: Thu Jan 26 04:43:17 EST 2006 Previous message: [plt-scheme] displaying errors in custom language levels Next message: [plt-scheme] newbie's problem regarding ex-11.3.4 Messages sorted by: [date] [thread] [subject] [author]

```hello,

Exercise 11.3.4.   Develop the function create-prices, which consumes a
natural number and produces a list with a corresponding number of prices
between \$.10 and \$10.00 with increments of a dime.

i think the it want to have a list in ascending order like this:

(cons 0.10 (cons 0.20 (cons 0.30.........empty)))

but i am getting exactly the opposite list. even after 3 hours of brain-work
i am not able to get the desired result. do you have any idea?

-------------------------------- start of programme
---------------------------
;; A natural number is either:
;;             1. 0, or
;;             2. (add1 n) where n is a natural number

;; create-prices : N -> list
;; to produce a list of prices of n elements with each next elemnt is a dime
more than the previuos.
;; (define (create-prices n)...)

#| TEMPLATE
(define (create-prices n)
(cond
[(zero? n)...]
[else....(create-prices (sub1 n))...]))

examples
(create-prices 0)
empty

(create-prices 3)
(cons 0.10 (cons 0.20 (cons 0.30 empty))) |#

(define (create-prices n)
(cond
[(zero? n) empty]
[else (cons (* n 0.10) (create-prices (sub1 n)))]))

;;(make-list -2 3)

;; i have created a function whch checks for values > 10 and removes them as
we only want between
;; 0.10 and 10.0

(define (remove>10 alon)
(cond
[(empty? alon) empty]
[(> (first alon) 10.0) (remove>10 (rest alon))]
[else (cons (first alon) (remove>10 (rest alon)))]))

;; tests
;;(create-prices 0)
empty

(create-prices 3)
(cons 0.10 (cons 0.20 (cons 0.30 empty)))

-------------------------------- end of programme
----------------------------------------------------------
OUTPUT:

well, this is what i get:
-------------------------------------------------------------
Welcome to DrScheme, version 209.
Language: Beginning Student.
Teachpack: /usr/lib/plt/teachpack/htdp/draw.ss.
empty
empty
(cons 0.3 (cons 0.2 (cons 0.1 empty)))
(cons 0.1 (cons 0.2 (cons 0.3 empty)))
>
-----------------------------------------------------------------

--
"the great intellectuals"
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/users/archive/attachments/20060126/d3f433f2/attachment.html>
```

 Posted on the users mailing list. Previous message: [plt-scheme] displaying errors in custom language levels Next message: [plt-scheme] newbie's problem regarding ex-11.3.4 Messages sorted by: [date] [thread] [subject] [author]