我在使用常见的lisp计算两个位向量之间的距离时遇到问题.
我是lisp的新手,这是我的人工智能家庭作业的最终作业问题,并且相信我遇到的问题是语法问题.
这是一个问题:
在由1和0的列表表示的相同长度的两个位向量之间写入递归函数DISTANCE.例如,
(距离'(1 0 1 1)'(0 1 0 1))
答案 - 3
如果向量长度不同,讨论必须做什么.
根据我的理解,两个位向量之间的距离只是对两个向量进行异或,然后向上计数1.
使用这个例子,我们将得到1011 ^ 0101 = 1110,它等于3.
假设这是计算距离的正确方法,那么我的问题是除了使这个递归之外还找到一种在lisp中进行异或的方法.
我如何获取两个列表并将它们放入我可以使用logxor (如此处所示)之类的格式中,然后在结果列表中计算1?
虽然尝试这样做(logxor '(1 0 1 1) '(0 1 0 1))告诉我'(1 0 1 1)不是一个整数所以它似乎logxor不适用于让我不知所措的列表.
您可以提供的任何帮助将不胜感激
谢谢!
理想情况下,可以将'或'两个数字表示为位向量,但我无法做到.请告诉我们代码中是否有错误或其他错误
line1 = BitVec('line1', 1)
line2 = BitVec('line2', 1)
s = Solver()
s.add(Or(line1, line2) == 0)
print s.check()
Run Code Online (Sandbox Code Playgroud)
给出的错误是
error: 'type error'
WARNING: invalid function application for or, sort mismatch on argument at position 1, expected Bool but given (_ BitVec 1)
WARNING: (declare-fun or (Bool Bool) Bool) applied to:
line1 of sort (_ BitVec 1)
line2 of sort (_ BitVec 1)
Run Code Online (Sandbox Code Playgroud)
从这个错误我明白,或者只能为bool变量做.我的问题是如何或为BitVectors
我正在尝试使用std::collections::BitVec,但是会生成此错误:
error[E0432]: unresolved import `std::collections::BitVec`
--> src\main.rs:6:5
|
6 | use std::collections::BitVec;
| ^^^^^^^^^^^^^^^^^^^^^^^^ no `BitVec` in `collections`
Run Code Online (Sandbox Code Playgroud)
我#![feature(collections)]在main.rs的顶部使用,我的编译器版本为rustc 1.27.0-nightly (ac3c2288f 2018-04-18)。我想念什么?错误是说BitVec并不存在std::collections,但文档说这BitVec是不稳定的功能。
我的Cargo.toml看起来像:
[package]
name = "conways_game_of_life"
version = "0.1.0"
authors = ["Gabriel Carneiro <gabriel.carneiro97@live.com>"]
# [lib]
# crate-type = ["cdylib"]
[dependencies]
wasm-bindgen = "0.2"
rand = "0.4.2"
time = "*"
Run Code Online (Sandbox Code Playgroud)
使用不稳定的功能,我应该怎么做BitVec?
假设你有一长串的字符数为1或0,有点像bitvector,但在数据库列上.您如何查询知道设置/未设置的值?假设您需要知道char 500和char 1500是否为"true".
stl的bit-vector和bitset容器有什么区别?请解释.我理解bitset是bitvector概念的实现我是对还是错?实现位向量的其他方法有哪些?
我对BitVector32行为有点困惑.看测试:
[TestClass]
public class ParallelPortDevices {
[TestMethod]
public void BitVector32Test() {
var lVector = new BitVector32(0);
Assert.IsTrue(lVector[0]);
Assert.IsFalse(lVector[1]);
}
}
Run Code Online (Sandbox Code Playgroud)
这过去了.即第一位设置为1(根据测试).但是,如果您运行ToString方法,您将获得"BitVector32 {00000000000000000000000000000000}"
我错过了什么?
提前致谢!
我正在尝试创建一个支持的位向量int[].
所以我有以下代码:
public class BitVector {
int[] vector = new int[1 << 16];
public void setBit(int nextInt) {
nextInt = nextInt & 0xFFFF;
int pos = nextInt / 32;
int offset = nextInt % 32;
vector[pos] |= (1 << offset);
}
public int findClearedBit() {
for(int i = 0; i < vector.length; i++){
for(int j = 0; j < 8; j++){
if((vector[i] & (1 << j)) == 0)
return i * 32 + j;
}
}
return -1; …Run Code Online (Sandbox Code Playgroud) 我为BitVector64创建了mysec变量.对于小于8的版本,我想使用BitVector32生成值
static BitVector64.Section mySect1;
static BitVector64.Section mySect2;
static BitVector64.Section mySect3;
if (versions) > 7)
mySect2 = BitVector64.CreateSection(14, mySect1); // V1 - 3 bits
else
mySect3 = BitVector32.CreateSection(7, mySect2);
Run Code Online (Sandbox Code Playgroud)
我现在需要什么
以下转换对我不起作用
mySect3 = BitVector32.CreateSection(7, (BitVector32.Section) mySect2);
Run Code Online (Sandbox Code Playgroud)
以下转换对我不起作用
mySect3 = BitVector32.CreateSection(7, (BitVector32.Section) mySect2) as BitVector34.Section;
Run Code Online (Sandbox Code Playgroud)
要么
mySect3 = (BitVector64.Section) BitVector32.CreateSection(7, (BitVector32.Section) mySect2) ;
Run Code Online (Sandbox Code Playgroud)