
I think perhaps « worksheet » was the right word

!

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

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

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

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?

What do you have so far?

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

So far I did

I am getting error

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.

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

How do I include racket/list in ?

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

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.

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

Ohh I just solved it

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

How do I fix it so that any order works ?

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 has joined the channel

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.

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)

@laurent.orseau Very intuitive :wink:

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

Thank You

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

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

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

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.

ok


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

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