diff options
Diffstat (limited to 'coding-exercises/2/22.rkt')
| -rw-r--r-- | coding-exercises/2/22.rkt | 36 |
1 files changed, 18 insertions, 18 deletions
diff --git a/coding-exercises/2/22.rkt b/coding-exercises/2/22.rkt index 09ace8c..31f486a 100644 --- a/coding-exercises/2/22.rkt +++ b/coding-exercises/2/22.rkt @@ -13,24 +13,24 @@ (cons (square (car things)) answer)))) (iter items nil)) -;; (square-list (list 1 2 3 4)) +(square-list (list 1 2 3 4)) ;; This attempts the reverse the consing direction by chaning the first in the pair with the second ;; The result is that we get pairs that point to other pairs with car, which is not how a list works. -(define (square-list2 items) - (define (iter things answer) - (if (null? things) - answer - (iter (cdr things) - (cons answer (square (car things)))))) - (iter items nil)) -;;(square-list2 (list 1 2 3 4)) - -;; One thing we could try is also growing the answer list forward somehow -(define (square-list3 items) - (define (iter things answer) - (if (null? things) - answer - (iter (cdr things) (append answer (list (square (car things))))))) - (iter items (list))) -(square-list3 (list 1 2 3 4)) +;; (define (square-list2 items) +;; (define (iter things answer) +;; (if (null? things) +;; answer +;; (iter (cdr things) +;; (cons answer (square (car things)))))) +;; (iter items nil)) +;; ;;(square-list2 (list 1 2 3 4)) +;; +;; ;; One thing we could try is also growing the answer list forward somehow +;; (define (square-list3 items) +;; (define (iter things answer) +;; (if (null? things) +;; answer +;; (iter (cdr things) (append answer (list (square (car things))))))) +;; (iter items (list))) +;; (square-list3 (list 1 2 3 4)) |
