我从朋友处获得了部分代码,我正在尝试理解它并以其他方式编写代码."gotowe"是("2011-12-22",-600.00)元素的排序列表
val wartosci = gotowe.foldLeft (List(initial_ballance)){
case ((h::t), x) => (x._2 + h)::h::t
case _ => Nil
}.reverse
Run Code Online (Sandbox Code Playgroud)
这很好,但是如何使用foldLeft?(我已经把所有额外的必要线):
val max = wartosci.max
val min = wartosci.min
val wychylenie = if(math.abs(min)>max){math.abs(min)}else{max}
def scale(x: Double) =
(x / wychylenie) * 500
def point(x: Double) =
{val z:Int = (500 - x).toInt
z}
val (points, _) = wartosci.foldLeft(("", 1)){case ((a, i), h) => (a + " " + (i * 4) + "," + point(scale(h)), i + 1)}
Run Code Online (Sandbox Code Playgroud)
当我打印点数时,我有一个值列表,并且不知道为什么不像值对
我正在使用一个名为area_code的字段,该字段在MySQL中具有int数据类型.不过,这并不让我来存储精确值像0781,0727,0788 Bcoz他们是从0开始它存储值781,727和788,即它截断从值0和保存.
请帮我..
我有自己的布局ListView和CustomCursorAdapter.每行都有自己的复选框.所以...绝对清楚的是,在滚动期间,复选框会松开它们的状态.我发现的唯一的东西是ListView中的Android保存复选框状态与光标适配器,但没有答案.还有一个问题.我的CustorArrayAdapter遇到了同样的问题.我使用SparseBooleanArray解决了这个问题,以保持复选框状态.它工作正常,但每个滚动调用onCheckedChanged.那是正常的吗?这笔交易是我的列表视图描述报警元素和启动(onCheckedChanged的)定期调用/停止报警.许多无意义的行为.
我有这种情况,我需要使用包含"."的字符串创建一个URL.
例如:
NSString *myStringWithURL = [NSString stringWithFormat:
@"http://myurl.com/setParam.php?setName=
{\"name\":\"%@\"} ", name];
// myStringWithURL will return the desired URL but it is a String.
// of course I need it as URL in order to make the request.
NSURL *targetURL = [NSURL URLWithString : myStringWithURL];
//This will return nil.
Run Code Online (Sandbox Code Playgroud)
所以问题是如何让我的URL不返回nil?
部分{"name":"My Name"}应该是JSON,但这似乎比使用NSDictionary然后使用JSON的解析器等更简单.
非常感谢你的帮助!
我正在寻找功能风格的算法(或这种算法的参数),这比命令式更快.
我喜欢功能代码,因为它具有表现力,而且比它的命令性吊坠更容易阅读.但我也知道这种表现力可能会花费运行时开销.并不总是由于尾递归等技术 - 但往往它们更慢.
虽然节目我不会去想的功能代码运行成本,因为现在的电脑速度非常快,发展的时间比运行时更为昂贵.此外,对我而言,可读性比性能更重要.然而,我的程序足够快,所以我很少需要以命令的方式解决问题.
有些算法在实践中应该以命令式方式(如排序算法)实现,否则在大多数情况下它们太慢或需要大量内存.在由于像模式匹配整个节目像写在功能语言解析器技术对比度可能多于一个的写入命令式语言的编译器,因为的可能性来优化代码快得多.
但是,是否有任何算法在功能样式上更快或者是否有可能设置这种算法的参数?
algorithm functional-programming scala imperative-programming
我正在尝试从头开始实现X.509证书生成器(我知道现有的,但我需要另一个).我无法理解的是如何计算证书的SHA-1(或任何其他)指纹.
在RFC5280说,输入签名功能是DER编码即tbsCertificate场.不幸的是,我计算的哈希值与OpenSSL产生的哈希值不同.这是一个循序渐进的例子.
openssl x509 -fingerprintsha1sum实用程序计算其哈希值现在,我在第2步和第3步得到的哈希值是不同的.有人可以给我一个暗示我可能做错了吗?
使用带有actor的接收时,使用循环而不是while(true)有什么区别.循环似乎工作得更快,但为什么,以及发动机罩下发生了什么?
使用循环而不是while(true)有什么不好吗?
更多关于背景.我正在简单的ping/pong代码中进行性能测试.我正在使用接收.
这是Ping类:
class ReceivePing(
count : Int,
pong : Actor
) extends Actor {def act() {
var pingsLeft = count - 1
pong ! Start
pong ! ReceivePing
while(true) {
receive {
case ReceivePong =>
if (pingsLeft % 10000 == 0)
Console.println("ReceivePing: pong")
if (pingsLeft > 0) {
pong ! ReceivePing
pingsLeft -= 1
} else {
Console.println("ReceivePing: stop")
pong ! Stop
exit()
}
}
}}}
Run Code Online (Sandbox Code Playgroud)
而不是while(true)它在循环中表现更好.
谢谢
每天我都在努力解决算法问题并尝试在这里问我无法回答的问题.对不起,如果我引起任何头痛.无论如何,
这里的问题从滑铁卢ACM大学程序设计竞赛.
有多少种方法可以用2x1多米诺骨牌拼贴3xn矩形?
Nirvana:闻起来像递归精神
我的解决方案资源管理器上的上下文菜单太长了,虽然我没有抱怨,这是因为我安装了很多扩展.我能找到的大多数命令......但是有一个令人讨厌的命令总是难以发现并且我一直都在使用它.
"设置为启动项目"
是否有一种方法(或扩展)允许我在上下文菜单中添加子菜单以定期使用命令,或者在解决方案窗口中添加工具栏的扩展名?
任何帮助真的很感激
有人可以提供帮助,我将hibernate搜索放入我的网络应用程序并收到以下错误:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<property name="hibernate.connection.driver_class">org.postgresql.Driver</property>
<property name="hibernate.connection.url">jdbc:postgresql://localhost/postgres</property>
<property name="hibernate.connection.username">postgres</property>
<property name="hibernate.connection.password">noor</property>
<property name="hibernate.connection.pool_size">10</property>
<property name="show_sql">true</property>
<property name="hibernate.dialect">org.hibernate.dialect.PostgreSQLDialect</property>
<property name="hibernate.hbm2ddl.auto">update</property>
<property name="current_session_context_class">thread</property>
<property name="hibernate.search.default.indexBase">
/users/application/indexes
</property>
<property name="hibernate.search.default.indexBase">
/users/application/indexes
</property>
<mapping resource="com/BiddingSystem/Models/Users.hbm.xml"/>
<mapping resource="com/BiddingSystem/Models/ForumTopic.hbm.xml"/>
<mapping resource="com/BiddingSystem/Models/ForumMessage.hbm.xml"/>
<mapping resource="com/BiddingSystem/Models/Administrator.hbm.xml"/>
<mapping resource="com/BiddingSystem/Models/PersonalUser.hbm.xml"/>
<mapping resource="com/BiddingSystem/Models/BusinessUser.hbm.xml"/>
<mapping resource="com/BiddingSystem/Models/BusinessContactNumbers.hbm.xml"/>
<mapping resource="com/BiddingSystem/Models/Attribute.hbm.xml"/>
<mapping resource="com/BiddingSystem/Models/AttributeOption.hbm.xml"/>
<mapping resource="com/BiddingSystem/Models/Category.hbm.xml"/>
<mapping resource="com/BiddingSystem/Models/Item.hbm.xml"/>
<mapping resource="com/BiddingSystem/Models/Auction.hbm.xml"/>
<mapping resource="com/BiddingSystem/Models/Picture.hbm.xml"/>
<mapping resource="com/BiddingSystem/Models/Bid.hbm.xml"/>
</session-factory>
</hibernate-configuration>
Run Code Online (Sandbox Code Playgroud)
堆栈跟踪:
org.hibernate.HibernateException: could not init listeners
at org.hibernate.event.EventListeners.initializeListeners(EventListeners.java:205)
at org.hibernate.cfg.Configuration.getInitializedEventListeners(Configuration.java:1980) …Run Code Online (Sandbox Code Playgroud)