如何在DrRacket中进行电源设置?

编程入门 行业动态 更新时间:2024-10-28 00:17:44
本文介绍了如何在DrRacket中进行电源设置?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在使用带有DrRacket列表缩写的开始语言,并且想递归地创建一个Powerset,但无法弄清楚该怎么做.我目前有这么多

I'm using the beginning language with list abbreviations for DrRacket and want to make a powerset recursively but cannot figure out how to do it. I currently have this much

(define (powerset aL) (cond [(empty? aL) (list)]

任何帮助都会很好.

推荐答案

What's in a powerset? A set's subsets! An empty set is any set's subset, so powerset of empty set's not empty. Its (only) element it is an empty set:

(define (powerset aL) (cond [(empty? aL) (list empty)] [else

As for non-empty sets, there is a choice, for each set's element, whether to be or not to be included in subset which is a member of a powerset. We thus include both choices when combining first element with smaller powerset, that, which we get recursively applying the same procedure to the rest of input:

(combine (first aL) (powerset (rest aL)))])) (define (combine a r) ; `r` for Recursive Result (cond [(empty? r) empty] ; nothing to combine `a` with [else (cons (cons a (first r)) ; Both add `a` and (cons (first r) ; don't add, to first subset in `r` (combine ; and do the same a ; with (rest r))))])) ; the rest of `r`

"There are no answers, only choices". Rather, the choices made, are what the answer's made of.

更多推荐

如何在DrRacket中进行电源设置?

本文发布于:2023-11-09 13:48:11,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1572518.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:电源   如何在   DrRacket

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!