我想取一系列用户输入的整数,然后对输入求和.例如,如果用户输入:
1 <return>
2 <return>
3 <return>
<return>
Run Code Online (Sandbox Code Playgroud)
6
Run Code Online (Sandbox Code Playgroud)
到目前为止,这是我的代码:
(defun stuff ()
(format t "Enter a number: ")
(let ((n (read)))
(+ n)))
Run Code Online (Sandbox Code Playgroud) 这比标题所暗示的要复杂得多,但我无法将其浓缩为一句话.
我正在使用Clisp,目前有一个列表列表.外部列表是任意长的,而内部列表是4个整数长.这是我可能拥有的一个例子.
((2 1 1 0) (1 1 0 0) (1 0 0 1) (1 1 0 0) (1 0 1 0) (1 0 0 0))
Run Code Online (Sandbox Code Playgroud)
现在每个内部列表由2个部分组成,第一个项目是"乘数".最后3项只是列表中的值.因此在某种意义上,(10 1 1 0)与(5 1 1 0)(5 1 1 0)相同.
我需要一个可以压缩此列表的函数,这样就没有2个列表包含相同的最后3个项目.但是每个唯一的最后3个项目只有一个列表,第一个空格中的值是这个列表的"多少".如果这是有道理的......
所以这
((2 1 1 0) (1 1 0 0) (1 0 0 1) (1 1 0 0) (1 0 1 0) (1 0 0 0))
; ^ ^
Run Code Online (Sandbox Code Playgroud)
会成为这个
((2 1 1 0) (2 1 0 0) (1 0 0 1) (1 0 …Run Code Online (Sandbox Code Playgroud) 我有n清单,例如:
L_1 = [a_11, a_12, ...]
L_2 = [a_21, a_22, ...]
...
L_n = [a_n1, a_n2, ...]
Run Code Online (Sandbox Code Playgroud)
其中i次列表具有k_i的元素。现在,我想生成所有n-elements列表,其中ith元素来自L_i,我的意思是:
[a_11, a_21, ..., a_n1]
[a_11, a_21, ..., a_n2]
...
[a_11, a_22, ..., a_n1]
[a_11, a_22, ..., a_n2]
...
[a_12, a_21, ..., a_n1]
[a_12, a_21, ..., a_n2]
...
[a_12, a_22, ..., a_n1]
[a_12, a_22, ..., a_n2]
...
Run Code Online (Sandbox Code Playgroud)
列表总数应等于k_1*k_2*...k_n。您能描述这种算法的伪代码还是使用Java代码?当列表数量被硬编码时,我可以使用嵌套的for循环来完成此操作,但是当n在运行时可自定义时,我将被完全阻止。
我必须对奇数位置上的奇数元素求和.这不起作用.谁能告诉我我的错误在哪里?谢谢
(defun sum (list)
(cond
((null list) 0)
((= (mod 2 (car list)) 0) (sum (cddr list)))
(T (+ (car list) (sum (cddr list))))))
Run Code Online (Sandbox Code Playgroud) 我正在使用一个函数d来生成随机数,我将其收集在列表中,然后对它们求平均值:
(/ (apply #'+ (list (d 6) (d 6) (d 6) (d 6) (d 6) (d 6))) 6.0)
Run Code Online (Sandbox Code Playgroud)
我想运行函数(d n) i次数,将返回的值一起添加,然后除以i.dotimes不返回值.我将如何在Common Lisp中执行此操作?
我有以下查询,我试图使用一个图形中的元素的id来检索另一个图形中的某些值.但是这不起作用:
select * from <mygraph2#> where {
?s ?p ?id in {select ?id from <mygraph1#> where { ?id ?t "MyService" }
}
Run Code Online (Sandbox Code Playgroud) 有没有办法将count的结果绑定到变量?我尝试过以下(不起作用):
SELECT ?totalSubject WHERE {
?s ?p ?o
BIND(COUNT(?s) AS ?totalSubject)
}
Run Code Online (Sandbox Code Playgroud) 我不明白以下SPARQL查询生成的输出:
select distinct ?Concept
where {
<http://dbpedia.org/resource/Blink-182> a ?Concept
}
LIMIT 100
Run Code Online (Sandbox Code Playgroud)
有人可以解释一下"概念"在DBPedia中的含义,以及此查询结果的含义是什么?它与rdf:type有什么联系吗?
我尝试常见的lisp hunchentoot-test.
当我上传带有非拉丁符号的utf-8文本文件时,上传文件的长度增加了.在完成文件中,插入了每个非拉丁符号的附加字节.我不明白为什么.最近的实验是刚刚在digitalocean上启动ubuntu系统.安装emacs,clisp和slime.在swank执行:
(ql:quickload"hunchentoot")
(ql:quickload"hunchentoot-test")
(hunchentoot:start(make-instance'hunchentoot:easy-acceptor:port 4242))
在127.0.0.1:4242/hunchentoot/test/upload.html上查看问题就足够了
我一直在尝试将线性列表转换为集合,但无济于事。每次运行此命令时,都会出现一些奇怪的编译错误,例如“格式错误的lambda”,它指出了我使用append的方式。这是我的代码:
(defun mem(e l)
(cond
((null l) nil)
((equal e (car l)) t)
((listp (car l)) (mem e (car l)))
(t(mem e (cdr l)))
)
)
(defun st(l k)
(cond
((null l) nil)
(( mem '(car l) 'k) (st (cdr l) k))
((listp (car l)) (st (car l) k))
( t (st (cdr l) (append((car l) k)) ))
(t(mem e (cdr l)))
)
)
Run Code Online (Sandbox Code Playgroud)
编辑:坦率地说,我只想从列表中删除重复项
common-lisp ×6
sparql ×3
lisp ×2
dbpedia ×1
hunchentoot ×1
java ×1
list ×1
math ×1
permutation ×1
pseudocode ×1
rdf ×1
set ×1