Permutations ind Racket

52 views
Skip to first unread message

Kira Bender

unread,
Dec 15, 2020, 8:12:25 AM12/15/20
to Racket Users
I study programming and have to do permutations in Racket without something like map , foldr, remove, remq, sort! or begin. So now i have a code but it doesn't show me every Permutation and some dopple. I can't find the issue or how to fix and program it right only using recursion. Maybe some of you know how to help me and find my logical or programming issue.  Here you can find a github link to my code.

Thank you for your help. 

With greetings Kira Bender

schle...@gmail.com

unread,
Dec 16, 2020, 12:06:14 PM12/16/20
to Racket Users
Stepping through the code with the drracket debugger and inspecting the values on the way may also be a good way to identify areas where your code doesn't work like you had expected.
Maybe write some more testcases / example applications of your function and see which inputs already work and which ones do not, thus narrowing down / getting an idea where the problem is within the code.

You already mentioned recursion, recursion can be used to solve problems that are self similar like how the Sierpiński triangle contains 3 simpler versions of itself.
Instead of thinking how you can create all permutations and then somehow create code for that. How could you create one permutation and then do that multiple times.
Maybe go through the problem yourself manually with 3 different items in physical space, pen and paper, think about what you are doing and what steps you do repeatedly.

If you have more specific questions ask them, I am sure a lot of people on this list will be interested in helping you, if you get specific.
This seems like homework with the purpose of deepening your understanding, so I can't really do much without ruining your learning experience.
I also don't want to confuse or distract you with too many different perspectives of looking at the problem, you have to find a way of looking at it that works for you.

That said I am self taught and have not a lot of teaching experience, so maybe others have better help or advice for you.

Simon

John Clements

unread,
Dec 16, 2020, 12:30:20 PM12/16/20
to Kira Bender, Racket Users
Are you using the “How To Design Programs” textbook? It’s free, online, and written by the team that developed Racket:

https://htdp.org/2020-8-1/Book/index.html

Indeed, it would not be a stretch to say that Racket and this textbook are part of the same project.

How To Design Programs (or HtDP) is focused on the idea of systematic design, and makes this concrete in the form of a “design recipe”, outlining specific steps for developing programs.

Taking a 10-second look at your code, it seems that you skipped steps 1, 2, 3, and possibly 4 of the design recipe in developing your code. Specifically: you need purpose statements, input/output specifications, and examples/test cases. These are part of systematic design.

I strongly suggest that you take a look at How To Design Programs to understand how to design functions like this methodically!

Hope this helps,

John Clements
> --
> You received this message because you are subscribed to the Google Groups "Racket Users" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to racket-users...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/racket-users/fd484f7c-77b5-492c-9780-d3c2a7cc0e0bn%40googlegroups.com.

br...@lojic.com

unread,
Dec 29, 2020, 9:50:59 AM12/29/20
to Racket Users
Kira:

You mentioned things (map, foldr, ...) that you're not permitted to use, but I don't know the full homework requirements. If your professor did not preclude the built-in permutations function, you could use that as a way of teaching your professor to communicate the requirements more clearly - they love that sort of thing ;)


Brian

Reply all
Reply to author
Forward
0 new messages