简体   繁体   English

Racket - 在某些约束下创建地板功能

[英]Racket - creating a floor function under certain constraints

I'm quite stuck on trying to create a floor function with the following constraints:我一直在尝试创建具有以下约束的楼层函数:

I'm only allowed to use the following functions in section 1.5 of this page: http://docs.racket-lang.org/htdp-langs/beginner.html .我只允许使用本页第 1.5 节中的以下功能: http : //docs.racket-lang.org/htdp-langs/beginner.html

However you're not allowed to use the floor, round, ceiling and sgn function.但是,您不能使用地板、圆形、天花板和 sgn 功能。 In addition to all this, you are unable to use recursion, cond, lists or even helper functions.除此之外,您无法使用递归、cond、列表甚至辅助函数。

Note: use only beginner student documentation注意:仅使用初学者学生文档

Here is a hint to get you started:这是一个让你开始的提示:

floor(x) = 0            if 0 <=x < 1
floor(x) = 1+floor(x-1) if x>1

In Scheme notation:在方案符号中:

(define (myfloor x)
  (cond
    [(below-one? x)  0]
    [else           (add-one (myfloor (subtract-one x)))]))

All you need to do, is to figure out how to write below-one and subtract-one .您需要做的就是弄清楚如何写下below-onesubtract-one

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM