我试图暴力破解一个受3个字符密码保护的RAR存档:
import os
Alphabets = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
for a in range(0,26):
for b in range(0,26):
for c in range(0,26):
Brute = Alphabets[a] + Alphabets[b] + Alphabets[c]
os.popen4("Rar.exe x -p" + Brute + " Protected.rar")
# raw_input()
raw_input("Done !")
Run Code Online (Sandbox Code Playgroud)
代码工作正常,除了:它很慢!!
我认为让它变慢的原因是"popen4"的多重开放.因为我试图将生成的单词存储在txt文件中,程序在不到5秒的时间内完成.
任何提高性能的想法?
嘿,我正在尝试编写一个脚本,该脚本总结了"斐波那契序列"中的所有偶数项,低于4百万.
Fibonacci1 = 1
Fibonacci2 = 2
a = 2
i = 4
for i in range(1,4000000):
Fibonacci1 = Fibonacci1 + Fibonacci2
if Fibonacci1 % 2 == 0:
a = a + Fibonacci1
Fibonacci2 = Fibonacci1 + Fibonacci2
if Fibonacci2 % 2 == 0:
a = a + Fibonacci2
print a
raw_input()
Run Code Online (Sandbox Code Playgroud)
它应该不到一分钟,但它花了一整夜,它没有解决!
编辑:对不起伙计们,我误解了这个问题.我虽然这意味着我必须将所有偶数项加起来达到400万!但解决方案是将所有平均值加上400万.
工作代码(在不到一秒的时间内完成):
Fibonacci1 = 1
Fibonacci2 = 2
a = 2
while a < 4000000:
Fibonacci1 = Fibonacci1 + Fibonacci2
if Fibonacci1 % 2 == …
Run Code Online (Sandbox Code Playgroud) 我试图通过"OnMouseMove事件"使用Scanline获取图像中的当前像素.
相当于这个的东西:
Label1.Caption := IntToStr(Image1.Picture.Bitmap.Canvas.Pixels[X,Y]);
Run Code Online (Sandbox Code Playgroud)
有任何想法吗 ?
我一直在研究重新排列单词字母的算法,但是找到正确的单词需要很长时间.
var
Form1: TForm1;
DictionaryArray : array[0..2000] of string;
const Numbrs : string = '123456789';
implementation
{$R *.dfm}
function GenerateSequence(CPoint : String; L : Integer): String;
var
Increaser : array[1..8] of Integer;
i : Integer;
AnagramSequence : String;
begin
FillChar(Increaser, SizeOf(Increaser), 0);
for i := 1 to Length(CPoint) do
Increaser[9 - i] := StrToInt(CPoint[L + 1 - i]);
//==========================================//
if Increaser[8] <= L then
Increaser[8] := Increaser[8] + 1;
if Increaser[8] > L then
begin
Increaser[8] := 1;
Increaser[7] := …
Run Code Online (Sandbox Code Playgroud) 我正在尝试校验一个图像,但是给出一个结果,尝试添加值和Adler-32需要很长时间,但两者都会在很长一段时间内完成(大约2秒).
添加值:
Function Checksum_CountryFlag(Img : TPicture):Integer;
var j, k, Checksum : Integer;
begin
Checksum := 0;
For j := 0 to Img.Width do
For k := 0 to Img.Height do
If (((Img.Bitmap.Canvas.Pixels[j,k]) <> 15577344) And ((Img.Bitmap.Canvas.Pixels[j,k]) <> 15311104) And ((Img.Bitmap.Canvas.Pixels[j,k]) <> 3816255) And ((Img.Bitmap.Canvas.Pixels[j,k]) <> 10526623) And ((Img.Bitmap.Canvas.Pixels[j,k]) <> 12303034) And ((Img.Bitmap.Canvas.Pixels[j,k]) <> 9013641)) Then
begin
Checksum := Checksum + Img.Bitmap.Canvas.Pixels[j,k];
end;
Result := Abs(Checksum);
end;
Run Code Online (Sandbox Code Playgroud)
阿德勒-32:
Function Checksum_Adler32(Img : TPicture):Integer;
var i,a,b,j,k : Integer;
begin
a := 1; b …
Run Code Online (Sandbox Code Playgroud) 嘿,我试图从列表中删除一个项目(不使用set
):
list1 = []
for i in range(2,101):
for j in range(2,101):
list1.append(i ** j)
list1.sort()
for k in range(1,len(list1) - 1):
if (list1[k] == list1[k - 1]):
list1.remove(list1[k])
print "length = " + str(len(list1))
Run Code Online (Sandbox Code Playgroud)
该set
函数工作正常,但我想应用此方法.除了我得到:
IndexError: list index out of range
Run Code Online (Sandbox Code Playgroud)
在声明中:
if (list1[k] == list1[k - 1]):
Run Code Online (Sandbox Code Playgroud)
编辑添加 (感谢Ned Batchelder)工作代码是:
list1 = []
for i in range(2,101):
for j in range(2,101):
list1.append(i ** j)
list1.sort()
k = 0
while k < len(list1) - 1: …
Run Code Online (Sandbox Code Playgroud) 我试图解决问题41,但我不知道为什么我的代码停在987654319:
def IsPandigital(No):
a = sorted(str(No))
for i in range(1,10):
if a[i - 1] != str(i):
return False
return True
def IsPrime(No):
i = 2
while i < No:
if No % i == 0:
return False
i += 1
return True
i = 987654321
while i > 0:
print i
raw_input()
if IsPrime(i) == True and IsPandigital(i) == True:
print i
break
i -= 1
print i
print "EOP"
raw_input()
Run Code Online (Sandbox Code Playgroud)
PS:我知道我应该从799999999开始,因为:
GergS:每9位数和8位数的pandigital数可被3整除.
for(i=0; i<height; i++)
{
for(j=0; j<width; j++)
{
button[i][j] = new QPushButton("Empty", this);
button[i][j]->resize(40, 40);
button[i][j]->move(40*j, 40*i);
connect(button[i][j], SIGNAL(clicked()), this, SLOT(changeText(button[i][j])));
}
}
Run Code Online (Sandbox Code Playgroud)
如果我用函数(例如全屏)更改了函数changeText,它可以工作,但是当我使用我定义的插槽(changeText)时,会出现此错误,我不知道如何解决它
QObject::connect: No such slot buttons::changeText(&button[i][j])
Run Code Online (Sandbox Code Playgroud)
这是函数changeText:
void buttons::changeText(QPushButton* button)
{
button->setText("Fish");
}
Run Code Online (Sandbox Code Playgroud)
注意:在头文件中我定义了这样的插槽:
类按钮:公共 QWidget
Q_OBJECT
public slots:
void changeText(QPushButton* button);
Run Code Online (Sandbox Code Playgroud)