Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon.

Pages: 1-

Scheme/Dr.Racket Help

Name: Anonymous 2012-10-23 20:56

Using Scheme/DrRacket for this problem:

I need help /g/...

This problem is telling me to do the following:

Create a Scheme function has-consequence? that consumes word (a string with one or more lower-case letters). It produces true if all the letters in word appear in the word “consequence", and false otherwise.



I understand that I have to use recursion and lists for this. So far all I've been able to do is convert the word that I'm supposed to use as a list by doing the following:

string->list "consequence"



However, how do I make the program convert the argument "word" into a list and then compare "consequence" with "word" to see if all characters in the "word" appear in "consequence"?

Name: Anonymous 2012-10-23 20:58

this is not g, get the fuck out

Name: Anonymous 2012-10-23 21:01

*sigh*

Name: Anonymous 2012-10-23 21:02

all $ flip elem "consequence"

Name: Anonymous 2012-10-23 21:04

What?

Name: Anonymous 2012-10-23 21:26

(define (has-consequence? word) (not (not (andmap (lambda x (member (car x) (string->list "consequence"))) (string->list word)))))

Name: Anonymous 2012-10-23 21:36

>>5
>>4 is Haskell. >>6 is the result of translating
has_consequences = all $ flip elem "consequence"
into Racket.

Name: Anonymous 2012-10-23 22:34

Alright, so you have string, which you are already able to turn into a list via string->list.

What I would do is:

1. Create a procedure to tell you if a given character is in the word consequence.

2. Within another, see if all characters satisfy said condition.

Assuming you don't know reduce, memq, or really, anything else which would have made this a fucking one-liner.



(define (is-in? char sequence)
  (and (not (null? sequence))
       (or  (equal? char (car sequence))
            (is-in? char (cdr sequence)))))

(define (combination-of? word char-list)
  (define length (string-length word))
  (define (combination-of-helper index result)
    (if (or (not result) (= index length))
        result
        (combination-of-helper (+ index 1)
                               (is-in? (string-ref word index) char-list))))
  (combination-of-helper 0 #t))

(combination-of? "c" (string->list "consequence"))

Name: Anonymous 2012-10-23 22:50

Fuck off back to /g/.

Name: Anonymous 2012-10-23 22:51

Use Symta.

Name: Anonymous 2012-10-23 22:52

>>8
Good job! You managed to turn a simple one-liner into a miserable pile of parentheses!

Name: Anonymous 2012-10-23 22:58

Why don't you try Symta?

Name: Anonymous 2012-10-23 22:59

I'm actually interested in this one-liner solution to this.

Name: Anonymous 2012-10-23 23:15

>>2,9
Question about Lisp
Back to /g/.

How new can you possibly be? It's cute that you're try to fit in and all, but fuck off back to /g/, ``please''.

Name: Anonymous 2012-10-23 23:22

>>14
Who are you quoting?

Name: Anonymous 2012-10-23 23:23

>>11
Everyone here can write a one liner for this kiddie shit, I just assumed the least amount of knowledge I could about the OP.

>>6
There was one in >>13. The double negation, essentially for type coercion, lets the program accept the empty string as a combination of the characters in "consequence". This one I wrote does not:


(define (has-consequence? word)
  (list? (andmap (lambda (c) (memq c (string->list "consequence")))
                 (string->list word))))


I guess both are valid.

Name: Anonymous 2012-10-23 23:39

>>14
OP posted this on /g/ yesterday.

Name: Anonymous 2012-10-23 23:42

>>14
Now I'm told I'm ``trying to fit in'' when I tell someone to go back to their home.

Name: Anonymous 2012-10-24 1:22

hasConsequence = and . map (`elem` "consequence")

Name: Anonymous 2012-10-24 1:28

>>17
So you were there to witness it.

Name: Anonymous 2012-10-24 1:56

>>20
yes

Name: Anonymous 2012-10-24 2:25

W^.∊'consequence'
Where W is the word.

Name: VIPPER 2012-10-24 5:24

I need help /g/...
Yep, go ask there and never come back.

Name: Anonymous 2012-10-24 10:03

>>1           `
>2012
>confusing /prog/ with /g/

I shiggy diggy

Name: Anonymous 2012-10-24 10:10

>>24
le epic meme arrows reddit/b/ro XDDDD

Name: Anonymous 2012-10-25 0:51

>>22
what language is this?

Name: Anonymous 2012-10-25 1:22

>>26
APL

Name: Anonymous 2012-10-25 2:20

>>27
Have you tried Symta?

Name: Anonymous 2012-10-25 2:37

>>28
I couldn't get asdf-install to install the packages it needs.
It looks like my kind of language.

Don't change these.
Name: Email:
Entire Thread Thread List