racket - Scheme filter with a function as a predicate -
I'm sorry if I'm opening a lot of scheme questions, but for some time it's been annoying me.
So I have a function (called pair-scoreer) which takes a list of pair of stars in the form of parameters and according to how close the score is (2 points for the same character, -1 For example, for the example
(pair-scorer '("AAA" "BBB") ("CCC" "CCC") ("AAA" return '(- 3 6 3) I also have the maximum function that will take the maximum number in this list of numbers
like
(max-list '(-3,63))> 6 Now here's the problem I added to the string To create a list, there is a need to create a filter, that is, i.e. ("aaa" "bbb") ("ccc" "ccc") ("AAA" "AAB") and only pair Or couples) who generate maximum value when run through scoring function Areas are. How do I apply this filter? I hope I was quite clear.
I think you have a score function that is a single pair Try it out: (argmax score '("aaa" "bbb") (" ccc "" ccc "(" AAA "" AAB "))) The trick here was used, which receives a function applied to each element in the list and Finds that element for which the function returns a maximum value.
Keep in mind that argmax will return the same element, even if there are many with the same maximum value, if it is a problem then you have to type your function, but the existing processes In context and it is easy to use: will return a list with the above elements which is the highest score. If there is only one, then the list will contain an element.
Comments
Post a Comment