Mais uma duvida

1 view
Skip to first unread message

Lucas Gordon

unread,
Apr 3, 2009, 4:15:17 PM4/3/09
to htdp-...@googlegroups.com
Pessoal to com uma duvida no exercise 5.1.2:
Develop  the  function check-guess. It  consumes two numbers,
t. Depending on how guess relates  to target, the function pro-
duces one of the following  three  answers:
'TooSmall, 'Perfect, or 'TooLarge.
The  function  implements  one  part of  a  two-player number guessing
game.  One  player  picks  a random number  between
0 and 99999.  The other
target, with the least  num
player's  goal is to determine this number,  called
ber of guesses. To each  guess, the first  player responds with one of the three
check-guess implements.
esponses that
check-guess and the teachpack  uess.ss implement  the  fir
The  function
player.  The  teachpack  picks  the random number, pops up a  window in
guess and the
which the second  player  can  choose  digits, and hands over  the
target to check-guess. To play the game,  set the teachpack  to guess.§§ using
Language I Set  teachpack option. Then  evaluate the expression
the
(guess-with-gui check-guess)
 
Eu entendi que eh pra envolver dentro da mesma (cond o uso de symbol e de bolean, ou seja se > guess target too large , < guess target toosmall  else perfect
 
daí gerei mais ou menos esse código:
 
;;5.1.2 develop check-guess then guess.ss
;;definir check-guess
;;Acertar errar por menos ou por mais, dar a dica com o uso do ;;symbol
(define target 911)
(define (check-guess guess)
  (cond
    [(> guess target)(symbol=? guess '????) 'TooLarge]
    [(< guess target)(symbol=? guess '????) 'TooSmall]
    [else(symbol=? guess '????) 'Perfect]))
 
;;F:\Livro programacao\0262062186\files\page_49.html

Aonde tem ???? é pq nao sei o q colocar... Eu to pensando se é pra usar mais de uma condition, mas na real eu nao acho q isso seja o certo, talvez soluciione mas o problema parece ser simples (eu consigo fazer a questão do jogo em si fácil, só nao consigo adicionar o lance do texto indicativo 'too large too small perfect')
 
Certo q vcs vao saber aguardo ae!
abraço
2009/4/1 <ebel...@gmail.com>
Um exemplo mais significativo pro pessoal sacar o que é DD

;; evens-only* : list -> list
;; removes all odd members from a list of ;; nested lists

;; vou fazer em portuga mesmo o DD
;; o nlist (nested list) pode ser:
;; vazio
;; ou o primeiro elemento é um número
;;   esse número é even?
;;   nao é even entao
;; não é um símbolo então
;;
;; qual a tradução de então???? ELSE!!!!!!!!!!!!!!!

(define (evens-only* nlist)
 (cond
  [(empty? nlist) empty]
  [(number? (first nlist))
   (cond
     [(even? (first nlist))                 (cons (first nlist)
            (evens-only* (rest nlist)))]
     [else
      (evens-only* (rest nlist))])]
  [else
   (cons     (evens-only* (first nlist))
    (evens-only* (rest nlist)))]))

(equal? (evens-only* (list 3 4 (list 2 (list 5 1 11)))) (list 4 (list 2 empty)))



--
Att,
Lucas Gordon
mobile: +55 48 8817-6134
mail: lucasg...@gmail.com

ebel...@gmail.com

unread,
Apr 3, 2009, 5:27:08 PM4/3/09
to htdp-...@googlegroups.com
Cara, o problema é que você não está seguindo o processo (design recipe) corretamente.
Eu sei que já mandei o link algumas vezes, mas lá vai de novo
http://groups.google.com/group/htdp-brasil/web/design-recibe-how-to-comentado?hl=pt-BR
Onde está o contract? o purpose? O data definition? os testes?
signature.asc
Reply all
Reply to author
Forward
0 new messages