我试图找出一个公式来计算一组任意任务的紧急程度,根据"截止日期"之前的天数和任务已完成的完成百分比.
到目前为止,我有一个'函数',它给出了代表:
U = ((dd * 25) - (100 - cp))
Where:
dd = Day difference from deadline to current date (in an integer value)
cp = current completion % (in an integer value - in increments of 5 currently)
Run Code Online (Sandbox Code Playgroud)
这给了我一个线性函数,函数中的25表示每天25%的任务进度.
所以在任何给定日期:
Where U <0 task is urgent
Where U =0 task is on schedule
Where U >0 task is ahead of schedule
(The actual display on if a task is on schedule (within a range) would be handled separately) …Run Code Online (Sandbox Code Playgroud) 考虑以下伪代码(语言不可知):
int f(reference int y) {
y++;
return 2;
}
int v = 1;
v += f(v);
Run Code Online (Sandbox Code Playgroud)
当评估时功能f发生变化y(即v)时v += f(v),v"冻结" 的原始值是否变为v"丢失"?
v += f(v); // Compute the address of v (l-value)
// Evaluate v (1)
// Execute f(v), which returns 2
// Store 1 + 2
printf(v); // 3
Run Code Online (Sandbox Code Playgroud) language-agnostic programming-languages pseudocode operators compound-assignment
我的问题不是特定于语言的……我可能会用C#或Python来实现,除非语言的特定功能可以帮助我获得所需的信息。
有没有人知道的某种算法可以帮助我确定数字列表是否包含重复模式?
假设我有几个数字清单...
[12, 4, 5, 7, 1, 2]
[1, 2, 3, 1, 2, 3, 1, 2, 3]
[1, 1, 1, 1, 1, 1]
[ 1, 2, 4, 12, 13, 1, 2, 4, 12, 13]
Run Code Online (Sandbox Code Playgroud)
我需要检测每个列表中是否有重复的模式...例如,列表1返回false,但是列表2、3和4返回true。
我在想也许要对列表中出现的每个值进行计数,如果val 1 == val 2 == val n ...那就可以了。还有更好的主意吗?
我正在尝试为背包算法设计一个伪代码,其中可以多次选择单个项目。经典算法是
OPT(i, w) = max(OPT(i-1, w) or vi + OPT(i-1, w-wi))
Run Code Online (Sandbox Code Playgroud)
为了满足要求,我修改为
k=1;
max = maximum(OPT(i-1, w))
while(OPT(i-1, w - k*wi) > 0) {
maximum = max(maximum, k*vi + OPT(i-1, w - k*wi))
k++
}
OPT(i, w) = maximum
Run Code Online (Sandbox Code Playgroud)
这似乎是一个合适的解决方案吗?或者还有更好的解决方案吗?如果需要任何其他信息,请告诉我。其余保持不变,vi表示第i个元素的值,wi表示第i个元素的权重。
我有 2 个数字范围:
$startTime到$endTime$offerStartTime到$offerEndTime上述每个变量都是整数。
我想看看 的范围是否offerStartTime落在和 的offerEndTime范围内。startTimeendTime
例如,如果startTime和endTime范围为:10 到 20,则以下示例范围将返回true:
offerStartTime: 5, offerEndTime: 11offerStartTime: 5, offerEndTime: 100offerStartTime: 10, offerEndTime: 15offerStartTime: 10, offerEndTime: 100offerStartTime: 12, offerEndTime: 15offerStartTime: 19, offerEndTime: 100将返回以下内容false:
offerStartTime: 1, offerEndTime: 3offerStartTime: 90, offerEndTime: 100offerStartTime: 1, offerEndTime: 10offerStartTime: 20, offerEndTime: 100我怎样才能做到这一点?理想情况下希望用 PHP 提供答案,但伪代码就可以了。
关于图上的BFS遍历只是一个简单而愚蠢的问题
我在许多站点上发现了BFS的伪代码几乎是这样的:
BFS (Graph, root):
create empty set S
create empty queue Q
add root to S //mark as visited here
Q.enqueue(root)
while Q is not empty:
current = Q.dequeue()
if current is the goal:
return current
for each node n that is adjacent to current:
if n is not in S:
add n to S //mark as visited here
Q.enqueue(n)
Run Code Online (Sandbox Code Playgroud)
我只是发现在给定节点出队列后将其标记为已访问,而不是在对一个给定节点进行标记时,将其标记为访问的节点稍微简单些,因为在后一种方法中,我们将需要编写一个额外的步骤。我知道这不是一件大事,但我想将一个节点标记为在一个地方而不是两个地方访问更有意义。更简洁,更容易记住甚至学习。
修改后的版本将如下所示:
BFS (Graph, root):
create empty set S
create empty queue Q
Q.enqueue(root)
while Q is not empty: …Run Code Online (Sandbox Code Playgroud) 我正在尝试在以下部分中实现该功能:Per-commitment Secret Requirements。
generate_from_seed(seed, I):
P = seed
for B in 47 down to 0:
if B set in I:
flip(B) in P
P = SHA256(P)
return P
Run Code Online (Sandbox Code Playgroud)
其中“flip(B)”替换值 P 中的第 B 个最低有效位。
根据这个定义,如果我们有seed=0x0101010101010101010101010101010101010101010101010101010101010101和I=1,我希望结果是
>>> from hashlib import sha256
>>> from binascii import hexlify
>>> hexlify(sha256(int(("00000001"*31)+"00000000",2).to_bytes(length=32,byteorder="big")).digest())
b'79356295f56e69998b9140cb77c63d3d80c93874259793a38d1dbd8678809ca9'
Run Code Online (Sandbox Code Playgroud)
因为flip函数执行一次,将第 0 个 LSB(最右边的位)设置为 0。
相反,结果是(测试向量):
>>> hexlify(sha256(int("00000000"+("00000001"*31),2).to_bytes(length=32,byteorder="big")).digest())
b'915c75942a26bb3a433a8ce2cb0427c29ec6c1775cfc78328b57f6ba7bfeaa9c'
Run Code Online (Sandbox Code Playgroud)
查看一个实现,很明显人们正在使用:
output[lp / 8] ^= (1 << (lp % 8));
Run Code Online (Sandbox Code Playgroud)
这在我看来是错误的,因为它正在改变字节的 LSB,如果 …
pseudocode endianness bitwise-operators bitcoin lightning-network
我正在编写一个程序,以将元组列表作为输入,并根据它们是否可以以某种方式排列来返回一些内容。通常我在编码之前就知道如何解决问题,但在这种情况下,我很难想出一个好的方法来解决这个问题。
这个想法是输入一个这样的列表.. [(5, 2), (3, 5), (3, 3), (1, 3)] 并验证是否可以以某种方式排列,以便最后number 匹配下一个元组的开头。所以在这种情况下是可能的,比如:[(1, 3), (3, 3), (3, 5), (5, 2)]。于是验证为真。元组也可以颠倒。
我想遍历列表并将有效的元组对组合在一起,但是如果它们没有以正确的方式分组以与其余的对一起工作怎么办?也可能太费时间了。
有任何想法吗?
谢谢!
你会如何编写伪代码来绘制一个8×8的方块棋盘,其中没有一个方块必须是满的?(都可以是空的)
我不太了解伪代码概念.
我正在攻读计算机科学的最终学士学位项目,现在我已经走到了尽头.这是我被困在的东西:
我试图用任何8种(8种)简单颜色对任何颜色(rgb代码)进行分类.简而言之,我需要找到可以放置任何颜色的8个间隔,并将其视为基本颜色(红色,蓝色,绿色,黑色,黄色,紫色,灰色,棕色).
例如:
(18,218,23)被归类为"绿色"
(81,,214,85)也是"绿色"
但是
(15,52,16)需要为"黑色"
(110,117,110)需要为"灰色"
所以有256 x 256 x 256种可能的颜色,我需要将它们分成8种(间隔)基本颜色.
我在等一些建议.
干杯!
要清楚(正如我在评论中看到的)我正在寻找一组特定的8种颜色(红色,黑色,绿色,棕色,蓝色,紫色,灰色,黄色).对不起上面的橙色!
pseudocode ×10
algorithm ×3
python ×2
bitcoin ×1
colors ×1
endianness ×1
graph-theory ×1
javascript ×1
math ×1
mysql ×1
numbers ×1
operators ×1
php ×1
range ×1
rgb ×1
sorting ×1
statistics ×1
tuples ×1