证券交易所方计算
我正在为我的青年俱乐部编写一个程序(http://dancingrobots.org/beurs/),用于计算饮料的价格按上一轮购买的次数计算(这是一个非常有趣的派对概念)。现在我计算价格的方式是这样的:
cola = cola * (vercola / pastVerCola);
可乐的价格在哪里 vercola 是本轮购买的次数。 PastVerCola 是上一轮购买的次数。
一杯饮料不能低于 0.5 欧元,也不能高于 10 欧元。
我的两个问题是:
- 价格波动太大(主要是从最大到最小 并相反)
- 如果饮料两次 0 购买,则错误为 (0/0)
对于那些感兴趣的人,这里是完整代码: http ://pastebin.com/PsT2v2Tr
I'm writing a program (http://dancingrobots.org/beurs/) for my youth club that calculates prices of drinks by the number of times it has been bought in the last round (quite a fun party concept). Now the way I calculate the prices is like this:
cola = cola * (vercola / pastVerCola);
Where cola is the price
vercola is the times it has been bought this round.
pastVerCola is the times it has been bought last round.
A drink can't go under 0.5 euro and above 10 euro.
My two problems are:
- The prices fluctuation is too high (It mostly chances from max to min
and reversed) - If a drink is two times 0 bought, it error's (0/0)
For those intressted here is the full code: http://pastebin.com/PsT2v2Tr
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果你想减少波动,你可以使用平方根:
多次使用 sqrt 可以进一步减少波动。
另一种方法(我过去使用过的一种)是使用固定负载来抑制波动,例如,
这很有用,因为它还可以让您在每一轮中自动增加/减少价格(通过使用 40、50、60 等)。 )
您可以将这两种效果结合起来以获得您需要的波动。例如
,顺便说一句,我认为如果一轮中没有人购买特定饮料,则会导致错误。 PastVerCola 将被设置为零,从而给您带来除以零的错误。使用常量可以完全避免这种情况。
If you want to reduce the fluctuation you can use the square root :
Use sqrt multiple times to reduce it even more.
Another way (one I have used in the past) is to dampen fluctuations using a fixed load e.g.
This is useful because it also lets you have an automatic increase/decrease in price with each round (by using 40, 50, 60, etc.)
You can combine these two effects to get the fluctuation you require. e.g.
By the way, I think the error is caused if no-one buys a particular drink in a round. pastVerCola will be set to zero, giving you a divide by zero error. Using the constants avoids this situation completely.