[英]Using python to solve for value that meets a condition
new true value that meets the condition = v满足条件的新真值 = v
previous true value = vprev前一个真值 = vprev
I am trying to look for av so that hash of str(((power(v,2))+(power(vprev, 3))) begins with ee我正在尝试寻找 av 以便 str(((power(v,2))+(power(vprev, 3))) 的 hash 以 ee 开头
I tried this我试过这个
import hashlib
values_list = []# a list where v and prev will be
solved = False
v = 1 # to start looping from 1
while not solved:
for index, v in enumerate(values_list):
vprev = values_list[(index - 1)]
results = str(v**2 + vprev**3)
results_encoded = results.encode()
results_hashed = hashlib.sha256(results_encoded).hexdigest()
if results[0:2] == "ee":
solved = True
values_list.append(v)
else: v += 1
print(values_list)
I'm expecting a list with the first true value but I have failed我期待一个具有第一个真值的列表,但我失败了
Commenting your own code:评论你自己的代码:
# ...
solved = False
v = 1 # to start looping from 1
while solved:
# This block is never executed: the `while` condition-check fails since the initial state of `solved` is `False`
print(values_list)
you'll probably want to use while not solved:
instead你可能想
while not solved:
而不是
import hashlib
values_list = []# a list where v and prev will be
solved = False
v = 1 # to start looping from 1
while not solved:
for index, value in enumerate(values_list):
vprev = values_list[(index - 1)]
results = str(v**2 + vprev**3)
results_encoded = results.encode()
results_hashed = hashlib.sha256(results_encoded).hexdigest()
if results[0:2] == "ee":
values_list.append(v)
solved = True
else: v += 1
print(values_list)
While loop is working for "true" statment.虽然循环正在为“真实”声明工作。 So you have to change your statments on code.
所以你必须改变你的代码声明。 And If you make the statment false then while loop breaks the loop.
并且如果您使语句为假,则 while 循环会中断循环。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.