我有兴趣与prolog一起玩和fuxing,我已经安装了swi-prolog并添加了存储库,以防万一有人对我使用的哪个命令感兴趣:
% sudo apt-add-repository ppa:swi-prolog/stable
% sudo apt-get update
% sudo apt-get install swi-prolog
Run Code Online (Sandbox Code Playgroud)
我如何开始在我的linux机器上编写prolog代码?对于我的常规编程,我使用VIM编写/编辑/调试和终端编译.我可以用vim写prolog吗?我如何编译或使用prolog解释器(我认为这就是所谓的)?
我很难设置我的代码来创建一个实时动画图,我的代码是在收集数据后绘图,而不是每次迭代都显示.我的脚本运行一个回归函数,然后存储在一个文件中,然后我访问这些文件并绘制它们,这里是我所拥有的,我需要移动或更改为实时图形?我尝试在for循环中移动绘图函数但是没有用,有什么建议吗?
fig = plt.figure()
ax1 = fig.add_subplot(1,1,1)
num = 10
for idx in range(1,num):
c,e = Regr_magic()
with open("CK_output.txt",'a') as CK:
CK.write("{0},{1}\n".format(idx,c))
with open("error_output.txt",'a') as E:
E.write("{0},{1}\n".format(idx,e))
def animate(i):
pull = open('error_output.txt','r').read()
data = pull.split('\n')
xar = []
yar = []
for each in data:
if len(each)>1:
x,y = each.split(',')
xar.append(float(x))
yar.append(float(y))
ax1.plot(xar, yar)
ani = animation.FuncAnimation(fig, animate, interval=1000)
plt.show()
Run Code Online (Sandbox Code Playgroud)
仅供参考,数据文件包含以下内容,迭代编号和Ck值或错误,因此它们看起来像这样
1,.0554
2,.0422
3,.0553
4,.0742
5,.0232
Run Code Online (Sandbox Code Playgroud) 我正在学习C语言,到目前为止对语言有了很好的理解,我最近实现了一个非常简单的单链表.我曾与Linus Torvalds一起观看过Ted演讲,他提到了良好的代码与糟糕的代码,并提供了从链接列表中删除条目的两个示例:
/*bad code*/
remove_list_entry(entry){
prev = NULL;
walk = head;
while(walk != entry){
prev = walk;
walk = walk->next;
}
if(!prev)
head = entry->next;
else
prev->next = entry->next;
/*good code*/
remove_list_entry(entry){
indirect = &head;
while ((*indirect) != entry)
indirect = &(*indirect)->next;
*indirect = entry->next;
}
Run Code Online (Sandbox Code Playgroud)
在我看来,他的良好代码示例是有效的,但我自己也不会想到这一点.在使用C编程时,我可以遵循哪些良好实践建议?或者像他在他的例子中那样操纵指针的某些方法?除了在CI编程时要避免的坏习惯和做法,希望这不是一个太宽泛的问题.
我有一个这样的数据文件:
1 13.4545
2 10.5578
3 12.5578
4 5.224
Run Code Online (Sandbox Code Playgroud)
我试图找到具有最小浮点数的行并将整行(包括整数)打印或写入另一个文件。所以我得到这个:
4 5.224
Run Code Online (Sandbox Code Playgroud)
我有这个但不起作用:
with open(file) as f:
small = map(float, line)
mini = min(small)
print mini
Run Code Online (Sandbox Code Playgroud)
也尝试使用这个:
with open(file) as f:
mylist = [[line.strip(),next(f).strip()] for line in f]
minimum = min(mylist, key = lambda x: float(x[1]))
print minimum
Run Code Online (Sandbox Code Playgroud) 我对 GNU 汇编内联非常陌生,我已经阅读了多篇文章,但仍然不完全了解发生了什么。根据我的理解:
movl %eax, %ebx\n\t将移动无论是在%eax成ebx,但不会将内容添加到对方
addl %eax, %ebx\n\t将添加%eaxwith的内容ebx并将其保存在最右边的寄存器中
addl %1, %0\n\t这就是我感到困惑的地方,我们要添加 1 和 0?为什么我们需要%0那里?
我正在编译我的c ++程序的问题,它是一个递归的正确解析器,这些是规则:
slist :: = stmt slist | stmt
stmt ::= decl | assign | print
decl ::= INT ID SC | FLOAT ID SC
print ::= PRINT expr SC
assign ::= ID EQUAL expr SC
expr ::=term PLUS expr|term MINUS expr| term
term ::= factor STAR term|factor DIV term| factor MOD term| factor
factor ::= primary STARSTAR factor | primary
primary ::= INTCONST | FLOATCONST | ID |
LPAREN expr RPAREN
Run Code Online (Sandbox Code Playgroud)
我仍然是C++的新手,所以我不确定我是否搞砸了什么,或者它是我的编译器.我在基因组/ ubuntu终端环境中使用VIM,这些是我在编译时遇到的错误,它看起来像一个丢失的包含头文件,但我100%确定我已经包含了头文件:
我的代码:
#include <iostream>
#include <string>
using …Run Code Online (Sandbox Code Playgroud)