Ask your own question, for FREE!
Computer Science
OpenStudy (anonymous):

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

OpenStudy (anonymous):

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..

OpenStudy (anonymous):

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

OpenStudy (anonymous):

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

OpenStudy (anonymous):

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

OpenStudy (anonymous):

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

OpenStudy (anonymous):

do i know u....?

OpenStudy (anonymous):

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

OpenStudy (anonymous):

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

OpenStudy (anonymous):

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...

OpenStudy (anonymous):

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

OpenStudy (anonymous):

what program r u in?

OpenStudy (anonymous):

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?

OpenStudy (anonymous):

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

OpenStudy (anonymous):

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

OpenStudy (anonymous):

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.....><

OpenStudy (anonymous):

now==

OpenStudy (anonymous):

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

OpenStudy (anonymous):

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

OpenStudy (anonymous):

i was workin on cs all the time..

OpenStudy (anonymous):

.... 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...

OpenStudy (anonymous):

...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..

OpenStudy (anonymous):

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

OpenStudy (anonymous):

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

OpenStudy (anonymous):

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

OpenStudy (anonymous):

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

OpenStudy (anonymous):

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

OpenStudy (anonymous):

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

OpenStudy (anonymous):

。。。 i emailed the ta.

OpenStudy (anonymous):

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.

OpenStudy (anonymous):

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

OpenStudy (anonymous):

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

OpenStudy (anonymous):

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

OpenStudy (anonymous):

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

OpenStudy (anonymous):

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).

OpenStudy (anonymous):

;;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]))

OpenStudy (anonymous):

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))))))

Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!
Latest Questions
jojomojo: what is the best paraphrase of the first stanza the olympic swimmer
37 minutes ago 0 Replies 0 Medals
oweifjwoijf: history help (only for lolitapapponettii)
1 hour ago 6 Replies 0 Medals
bruhman7624: don't do anything with this im just doing random stuff
1 hour ago 8 Replies 1 Medal
bruhman7624: who said e=mc squared?
1 hour ago 1 Reply 0 Medals
olivia14: Can someone summarize this for me?
1 hour ago 3 Replies 0 Medals
unknown66: 3x-10
2 hours ago 5 Replies 0 Medals
Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!