Here's the question you clicked on:

55 members online
  • 0 replying
  • 0 viewing

chaos_168

  • 4 years ago

Some English words can be played on the keys of a piano, such as “face” or “baggage”. A piano has keys named a, b, c, d, e, f, g. Write a Scheme function can-play-word? that consumes a word (a non-empty string) and produces true or false depending on whether the word can be played on a piano or not. The only characters that can be played on a piano are lower case letters. Some English words can be played on the keys of a piano, such as “face” or “baggage”. A piano has keys named a, b, c, d, e, f, g. Write a Scheme function can-play-word? that consumes a word (a non-empty string) and produces true or false depending on whether the word can be played on a piano or not. The only characters that can be played on a piano are lower case letters. @Computer Science

  • This Question is Closed
  1. note-phobia
    • 4 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    o sweet.... we are askin the same question... feel like we should use remove-all definition but i have no clue how to operate it..

  2. chaos_168
    • 4 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    yeah... I have no idea how to do this... not that great in cs.. lol :/

  3. note-phobia
    • 4 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    ...it's only about an hour till the deadline of this assignment.... i'm dying..

  4. chaos_168
    • 4 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    Yeah... I only got the first question. LOL. I'm screwed..

  5. note-phobia
    • 4 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    ........i cant even say i got the first question cuz i didn't pass the test..... are u in cs 115..?

  6. note-phobia
    • 4 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    do i know u....?

  7. chaos_168
    • 4 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    yeah.. CS 115. In Lori Case class.... I don't think you know me.. I don't know that many people. LOL

  8. note-phobia
    • 4 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    i mean d i know u in person? nm we have different profs.... omg what to do...

  9. chaos_168
    • 4 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    No, I don't think you know me in person.. haha.. I just wrote all the design recipe stuff down hoping to get part marks.. I didn't get any of the actual functions itself...

  10. note-phobia
    • 4 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    o brilliant idea...... i'll do that immediately.... yeah muz get a 25%+ or it's too bad..

  11. note-phobia
    • 4 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    what program r u in?

  12. chaos_168
    • 4 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    haha.. yeah.. I just hope to get over 25% in the assignments to get that extra mark. LOL... and I'm in honours math.. hbu?

  13. note-phobia
    • 4 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    i already chose my program to be actsci....... and i now regret it a lot.... but i want to stay tho..

  14. chaos_168
    • 4 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    ooo actsci... a lot of people are taking that actually.. I'm actually taking MTHEL 131(intro to actuarial practice?) as my elective.. and I don't find it that interesting.. LOL

  15. note-phobia
    • 4 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    o i dont even know what that is...... my cousin 's in actsci 3rd yr and i juz wanted to get help from her so i chose the same program.. how i realize how tough it is.....><

  16. note-phobia
    • 4 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    now==

  17. chaos_168
    • 4 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    haha.. that's why you choose a program that you like and enjoy.. I have to go drop off my algebra assignment due in 30 minutes.. LOL i'll be back soon. xD work on those design recipes! xD

  18. note-phobia
    • 4 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    o m g... i didn't even do my algebra assignment......

  19. note-phobia
    • 4 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    i was workin on cs all the time..

  20. chaos_168
    • 4 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    .... are you serious? ... wow.. Dx I did algebra first cause I find it easier and much more useful than CS... I hate CS ... don't even know why I have to take it...

  21. note-phobia
    • 4 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    ...more useful....i much better in algebra than in cs so it doesn't matter if i miss one assignment.... thats why i gave it up..

  22. note-phobia
    • 4 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    yeah i don't see the point of taking cs.........i'm terrible at it...........

  23. chaos_168
    • 4 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    haha.. me too... I don't understand a thing in CS.. everything the prof says is just alien language to me.. LOL.. gonna go drop off algebra now.. i'll be back soon xD

  24. note-phobia
    • 4 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    oo~~ see u soon...... btw i cannot log in to my markus no matter which browser i use now...

  25. chaos_168
    • 4 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    o.O ur right... some authorization thing... :s

  26. note-phobia
    • 4 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    。。。 what should we do..........

  27. chaos_168
    • 4 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    I have no idea... I submitted some of mine already... It's probably cause a lot of people are using it or something.. Just keep trying I guess? :S

  28. note-phobia
    • 4 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    。。。 i emailed the ta.

  29. Narsat
    • 4 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    I'm rusty at Scheme, but you should do something like this. (define (can-play-word? word) (cond ((empty? word) #t) ((char= (car word) 'a) (can-play-word (cdr word))) ((char= (car word) 'b) (can-play-word (cdr word))) ((char= (car word) 'c) (can-play-word (cdr word))) ((char= (car word) 'd) (can-play-word (cdr word))) ((char= (car word) 'e) (can-play-word (cdr word))) ((char= (car word) 'f) (can-play-word (cdr word))) ((char= (car word) 'g) (can-play-word (cdr word))) (else #f))) As I said, it might not be exactly like this. I have no way to test it at the moment, but it should follow this general structure: Make a cond, ask if the word still has elements, if its empty, it's automatically true. If the letter you recieve is a, b, c, d, e, f or g, you call the function again and keep trying. If you recieve anything else, it's automatically false.

  30. chaos_168
    • 4 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    Hey... thanks for the reply... an error message appeared when I ran the program.. char=: this function is not defined

  31. note-phobia
    • 4 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    yeah i have no clue what does char means.... i know car is first and cdr is rest...

  32. Narsat
    • 4 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    hmm, there should be a function that does what char= is supposed to do, anything you remember that is used to compare two values? Lemme look up online char means a single character like a, b or c

  33. Narsat
    • 4 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    Oh my bad, it's supposed to be char=? not char=

  34. dmancine
    • 4 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    I wrote a helper function can-play-letter? that determines if a single letter is playable. Then for can-play-word? I said it's either that the string is empty (base case), or the first letter is playable (do a little work) and the rest of the word is playable (recursively reduce it to a smaller problem).

  35. note-phobia
    • 4 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    ;;wordlist: string -> list-of-symbols ;;Purpose: transform a string to a list ;;Examples:(define (wordlist maryh) => (cons #\m (cons #\a (cons #\r (cons #\y (cons #\h empty))))) (define (wordlist word) (string->list word)) ;;data analysis: ;; if the word contains only a,b,c,d,e,f,g then produces boolean value true ;; if the word contains letters other than a,b,c,d,e,f,g then produces boolean value false ;;wordtest: string->boolean ;;Purpose: produce boolean value of a word whether it contains only a,b,c,d,e,f,g ;;or it contains letters that are not on the piano keyboard by consuming a string ;;Examples: ;;(check-word "dad") => true ;;(check-word "play") => false (define (check-word word) (cond [(equal? (list->string(cons (first (wordlist word)) empty))"a") true] [(equal? (list->string(cons (first (wordlist word)) empty))"b") true] [(equal? (list->string(cons (first (wordlist word)) empty))"c") true] [(equal? (list->string(cons (first (wordlist word)) empty))"d") true] [(equal? (list->string(cons (first (wordlist word)) empty))"e") true] [(equal? (list->string(cons (first (wordlist word)) empty))"f") true] [(equal? (list->string(cons (first (wordlist word)) empty))"g") true] [else false])) ;;tests (check-expect (check-word "face") true) (check-expect (check-word "False") false) ;;data analysis: ;;a wordlist is a helper function that ;;help to convert a sting into a list of word ;;can-play-word?: string -> boolean ;;Purpose: produce boolean value depending on whether or not a word can be played on a piano ;;by consuming a string ;;Examples: ;;(can-play-word? "face") => true ;;(can-play-word? "Dad") => false ;;(can-play-word? "apple") => false ;; (can-play-word? "lee-chin") => false (define (can-play-word? word) (cond [(empty? (wordlist word)) true] [(check-word word) (can-play-word? (list->string (rest (wordlist word))))] [else false]))

  36. dmancine
    • 4 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    Sorry, my Scheme is ancient (R5RS, circa 1997). (define (can-play-letter? letter) (and (char>=? letter #\a) (char<=? letter #\g))) (define (can-play-word? word) (or (= (string-length word) 0) (and (can-play-letter? (string-ref word 0)) (can-play-word? (substring word 1 (string-length word))))))

  37. Not the answer you are looking for?
    Search for more explanations.

    • Attachments:

Ask your own question

Sign Up
Find more explanations on OpenStudy
Privacy Policy