ben.knoble
2021-3-18 13:53:30

I think perhaps « worksheet » was the right word


soegaard2
2021-3-18 14:35:13

!


sschwarzer
2021-3-18 16:55:03

So you want the lists from the first argument that contain all items in the second argument?


ahnaaf20
2021-3-18 16:56:29

The second list should match with the first characters if match then give out the main list


ahnaaf20
2021-3-18 16:59:23

For example instead of ‘(#\a #\b)… if I put ‘(#\d) or ‘(#\d #\e) I should get (#\d #\e #\f) as the output


sschwarzer
2021-3-18 17:02:02

So '(#\d #\f) as second argument would give “no” result? What should be returned if there are no matches? What should be returned if multiple lists in the outer list of the first argument match?


sschwarzer
2021-3-18 17:02:39

What do you have so far?


sschwarzer
2021-3-18 17:04:08

I think it should help to (sub)divide your problem. For example, start with a predicate function that tells you whether a single list (from the first argument) matches the other list (the second argument).


ahnaaf20
2021-3-18 17:04:28

So far I did


ahnaaf20
2021-3-18 17:04:32

I am getting error


sschwarzer
2021-3-18 17:09:16

list-prefix? is defined in racket/list (see https://docs.racket-lang.org/reference/pairs.html?q=sort#%28part._.Additional_.List_.Functions_and_.Synonyms%29 ). But in itself it’s probably not enough.

Also, I recommend that you use more meaningful names than lst and arg. I found that I can think more clearly about a problem and its solution if I choose more meaningful names for the identifiers.


ahnaaf20
2021-3-18 17:10:15

I tried but can you please try to solve this for me. If you have time. I am stuck at it for so long


ahnaaf20
2021-3-18 17:11:09

How do I include racket/list in ?


sschwarzer
2021-3-18 17:17:58

@ahnaaf20 I would really recommend that you read the Racket Guide ( https://docs.racket-lang.org/guide/index.html ), at least up to and including the chapter on modules. If you don’t do this, you’ll be stuck “forever” at so many things. I really think you should make this investment. Everything will be much easier than without this investment.

If you read the text up to the module chapter and still have problems, you can still ask. (I don’t think anyone will expect that you remember everything from the first chapters.)


sschwarzer
2021-3-18 17:20:46

Also, doing exercises in the first two chapters of SICP ( https://sarabander.github.io/sicp/html/index.xhtml ) helped me get a better intuition for recursion.


ahnaaf20
2021-3-18 17:22:14

Yeah I am reading these. But It’s been 2 days I am stuck. So that’s why I am asking for help


ahnaaf20
2021-3-18 17:24:28

Ohh I just solved it


ahnaaf20
2021-3-18 17:28:40

I am having a problem if the order doesn’t match


ahnaaf20
2021-3-18 17:30:06

How do I fix it so that any order works ?


sschwarzer
2021-3-18 17:52:23

list-prefix? doesn’t do what you want (see it’s documentation). I suggest you first write a function that checks for a match between two lists (i. e. if all items from the second list are contained in the first list).


joshuahoeflich2021
2021-3-18 17:56:44

@joshuahoeflich2021 has joined the channel


sschwarzer
2021-3-18 17:59:31

By the way, what’s the supposed semantics for duplicated entries in one list or the other or in both? For example, is '(#\a #\b #\c) vs. '(#\a #\a) a match or not? This would also affect your solution.


laurent.orseau
2021-3-18 18:19:18

Here’s an elegant solution for random order, written like a true mathematician (with at most 2 characters per variable): #lang racket (require math/number-theory) (define (finder ll l) (define (->number l) (apply * (map (λ (c) (nth-prime (- (char->integer c) (char->integer #\a) -1))) (remove-duplicates l)))) (define n1 (->number l)) (filter (λ (l2) (divides? n1 (->number l2))) ll)) (finder '((#\a #\b #\c) (#\a #\c #\d) (#\d #\e #\f)) '(#\a #\b)) ; -> '((#\a #\b #\c)) (although don’t attempt to hand this to your teacher)


sschwarzer
2021-3-18 18:24:39

@laurent.orseau Very intuitive :wink:


laurent.orseau
2021-3-18 18:27:59

To make it even more natural I wanted to use the zeta function, but I wouldn’t get exact integers :/


ahnaaf20
2021-3-18 18:30:04

Thank You


laurent.orseau
2021-3-18 18:30:49

@ahnaaf20 Don’t thank me, that’s not a proper solution.


ahnaaf20
2021-3-18 18:31:45

But you still helped me that’s why I am thanking you


juanesgonzalez746
2021-3-18 19:45:12

I need to do this workshop and I have no idea how to do it


samth
2021-3-18 20:24:54

You’ve asked this homework question in a lot of channels several times. Try to just ask it once in one place. Also, you are more likely to get help if you describe what you’ve done and where you’re stuck.


juanesgonzalez746
2021-3-18 20:38:27

ok



camoy
2021-3-19 04:42:44

a silly macro for our ruby friends… kinda funny you can do this without extending the reader #lang racket (require (for-syntax racket/string syntax/parse)) (begin-for-syntax (define app (syntax-local-value #'#%app))) (define-syntax (#%app stx) (syntax-parse stx [(_ ps:id b ...+) #:when (eq? (syntax-property stx 'paren-shape) #\{) #:with (p ...) (map (λ (p) (datum->syntax stx (string->symbol p))) (string-split (symbol->string (syntax->datum #'ps)) #px",\\s*")) #'(λ (p ...) b ...)] [_ (app stx)])) (map { \|x, y\| (+ x y) } '(1 2 3) '(4 5 6))


sorawee
2021-3-19 05:00:02

Self-promotion:

#lang racket (require mixfix (for-syntax syntax/parse racket/string)) (define-mixfix-rule (ps:id b ...+) #:when (eq? (syntax-property this-syntax 'paren-shape) #\{) #:with (p ...) (map (λ (p) (datum->syntax this-syntax (string->symbol p))) (string-split (symbol->string (syntax->datum #'ps)) #px",\\s*")) (λ (p ...) b ...)) (map { \|x, y\| (+ x y) } '(1 2 3) '(4 5 6))